Skip to content

Commit a6be30c

Browse files
committed
editoast: make budget nullable in project and study
1 parent a24e487 commit a6be30c

File tree

15 files changed

+41
-39
lines changed

15 files changed

+41
-39
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
UPDATE study SET budget = COALESCE(budget, 0);
2+
ALTER TABLE study ALTER COLUMN budget SET NOT NULL;
3+
4+
UPDATE project SET budget = COALESCE(budget, 0);
5+
ALTER TABLE project ALTER COLUMN budget SET NOT NULL;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
ALTER TABLE study ALTER COLUMN budget DROP NOT NULL;
2+
ALTER TABLE project ALTER COLUMN budget DROP NOT NULL;

editoast/openapi.yaml

+4-2
Original file line numberDiff line numberDiff line change
@@ -4475,6 +4475,7 @@ components:
44754475
properties:
44764476
budget:
44774477
format: int32
4478+
nullable: true
44784479
type: integer
44794480
creation_date:
44804481
format: date-time
@@ -4505,7 +4506,6 @@ components:
45054506
- objectives
45064507
- description
45074508
- funders
4508-
- budget
45094509
- creation_date
45104510
- last_modification
45114511
- tags
@@ -4515,6 +4515,7 @@ components:
45154515
properties:
45164516
budget:
45174517
format: int32
4518+
nullable: true
45184519
type: integer
45194520
description:
45204521
maxLength: 1024
@@ -5967,6 +5968,7 @@ components:
59675968
type: string
59685969
budget:
59695970
format: int32
5971+
nullable: true
59705972
type: integer
59715973
business_code:
59725974
type: string
@@ -6010,7 +6012,6 @@ components:
60106012
- service_code
60116013
- creation_date
60126014
- last_modification
6013-
- budget
60146015
- tags
60156016
- state
60166017
- study_type
@@ -6025,6 +6026,7 @@ components:
60256026
type: string
60266027
budget:
60276028
format: int32
6029+
nullable: true
60286030
type: integer
60296031
business_code:
60306032
type: string

editoast/src/fixtures.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ pub mod tests {
295295
.service_code("BBB".into())
296296
.creation_date(Utc::now().naive_utc())
297297
.last_modification(Utc::now().naive_utc())
298-
.budget(0)
298+
.budget(Some(0))
299299
.tags(Tags::default())
300300
.state("some_state".into())
301301
.study_type("some_type".into())
@@ -313,7 +313,7 @@ pub mod tests {
313313
.objectives("".to_owned())
314314
.description("".to_owned())
315315
.funders("".to_owned())
316-
.budget(0)
316+
.budget(Some(0))
317317
.creation_date(Utc::now().naive_utc())
318318
.last_modification(Utc::now().naive_utc())
319319
.tags(Tags::default());

editoast/src/modelsv2/projects.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ pub struct Project {
2828
pub objectives: String,
2929
pub description: String,
3030
pub funders: String,
31-
pub budget: i32,
31+
pub budget: Option<i32>,
3232
pub creation_date: NaiveDateTime,
3333
pub last_modification: NaiveDateTime,
3434
#[model(remote = "Vec<Option<String>>")]
@@ -239,7 +239,7 @@ pub mod test {
239239
// Patch a project
240240
let mut project = project_fixture.model.clone();
241241
project.name = "update_name".into();
242-
project.budget = 1000;
242+
project.budget = Some(1000);
243243
project.save(conn).await.unwrap();
244244
let project = Project::retrieve(conn, project.id).await.unwrap().unwrap();
245245
assert_eq!(project.name, String::from("update_name"));

editoast/src/modelsv2/study.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ pub struct Study {
3131
pub start_date: Option<NaiveDate>,
3232
pub expected_end_date: Option<NaiveDate>,
3333
pub actual_end_date: Option<NaiveDate>,
34-
pub budget: i32,
34+
pub budget: Option<i32>,
3535
#[model(remote = "Vec<Option<String>>")]
3636
pub tags: Tags,
3737
pub state: String,

editoast/src/tables.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ diesel::table! {
402402
description -> Varchar,
403403
#[max_length = 255]
404404
funders -> Varchar,
405-
budget -> Int4,
405+
budget -> Nullable<Int4>,
406406
creation_date -> Timestamptz,
407407
last_modification -> Timestamptz,
408408
tags -> Array<Nullable<Text>>,
@@ -612,7 +612,7 @@ diesel::table! {
612612
start_date -> Nullable<Date>,
613613
expected_end_date -> Nullable<Date>,
614614
actual_end_date -> Nullable<Date>,
615-
budget -> Int4,
615+
budget -> Nullable<Int4>,
616616
tags -> Array<Nullable<Text>>,
617617
#[max_length = 16]
618618
state -> Varchar,

editoast/src/views/projects.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,7 @@ struct ProjectCreateForm {
7676
#[serde(default)]
7777
#[schema(max_length = 1024)]
7878
pub funders: String,
79-
#[serde(default)]
80-
pub budget: i32,
79+
pub budget: Option<i32>,
8180
/// The id of the image document
8281
pub image: Option<i64>,
8382
#[serde(default)]
@@ -269,7 +268,7 @@ impl From<ProjectPatchForm> for Changeset<Project> {
269268
.flat_description(project.description)
270269
.flat_objectives(project.objectives)
271270
.flat_funders(project.funders)
272-
.flat_budget(project.budget)
271+
.flat_budget(Some(project.budget))
273272
.flat_image(Some(project.image))
274273
.flat_tags(project.tags)
275274
}

editoast/src/views/study.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,7 @@ struct StudyCreateForm {
7474
pub business_code: String,
7575
#[serde(default)]
7676
pub service_code: String,
77-
#[serde(default)]
78-
pub budget: i32,
77+
pub budget: Option<i32>,
7978
#[serde(default)]
8079
pub tags: Tags,
8180
pub state: String,
@@ -328,7 +327,7 @@ impl StudyPatchForm {
328327
.flat_start_date(Some(self.start_date))
329328
.flat_expected_end_date(Some(self.expected_end_date))
330329
.flat_actual_end_date(Some(self.actual_end_date))
331-
.flat_budget(self.budget)
330+
.flat_budget(Some(self.budget))
332331
.flat_tags(self.tags)
333332
.flat_state(self.state)
334333
.flat_study_type(self.study_type);

front/src/applications/operationalStudies/views/Project.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -240,20 +240,20 @@ export default function Project() {
240240
</div>
241241
</div>
242242
</div>
243-
{(project.funders || (project.budget !== undefined && project.budget !== 0)) && (
243+
{(project.funders || project.budget !== 0) && (
244244
<div className="project-details-financials">
245245
<div className="project-details-financials-infos">
246246
<h3>{t('fundedBy')}</h3>
247247
{project.funders && <div>{project.funders}</div>}
248248
</div>
249-
{project.budget !== undefined && project.budget !== 0 && (
249+
{project.budget ? (
250250
<div className="project-details-financials-amount">
251251
<span className="project-details-financials-amount-text">
252252
{t('totalBudget')}
253253
</span>
254254
{budgetFormat(project.budget)}
255255
</div>
256-
)}
256+
) : null}
257257
</div>
258258
)}
259259
<div className="project-details-tags">

front/src/applications/operationalStudies/views/Study.tsx

+3-8
Original file line numberDiff line numberDiff line change
@@ -223,12 +223,7 @@ export default function Study() {
223223
openModal(
224224
<AddOrEditStudyModal
225225
editionMode
226-
study={
227-
{
228-
...study,
229-
budget: study.budget !== 0 ? study.budget : undefined,
230-
} as StudyForm
231-
}
226+
study={study}
232227
/>,
233228
'xl',
234229
'no-close-modal'
@@ -284,12 +279,12 @@ export default function Study() {
284279
</div>
285280
)}
286281
</div>
287-
{study.budget !== 0 && (
282+
{study.budget ? (
288283
<div className="study-details-financials-amount">
289284
<span className="study-details-financials-amount-text">{t('budget')}</span>
290285
{budgetFormat(study.budget)}
291286
</div>
292-
)}
287+
) : null}
293288
</div>
294289
)}
295290

front/src/common/api/osrdEditoastApi.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1926,7 +1926,7 @@ export type ElectrificationsOnPathResponse = {
19261926
};
19271927
export type Tags = string[];
19281928
export type Project = {
1929-
budget: number;
1929+
budget?: number | null;
19301930
creation_date: string;
19311931
description: string;
19321932
funders: string;
@@ -1958,7 +1958,7 @@ export type Ordering =
19581958
| 'LastModifiedDesc'
19591959
| 'LastModifiedAsc';
19601960
export type ProjectCreateForm = {
1961-
budget?: number;
1961+
budget?: number | null;
19621962
description?: string;
19631963
funders?: string;
19641964
/** The id of the image document */
@@ -1979,7 +1979,7 @@ export type ProjectPatchForm = {
19791979
};
19801980
export type Study = {
19811981
actual_end_date?: string | null;
1982-
budget: number;
1982+
budget?: number | null;
19831983
business_code: string;
19841984
creation_date: string;
19851985
description: string;
@@ -2013,7 +2013,7 @@ export type StudyResponse = Study & {
20132013
};
20142014
export type StudyCreateForm = {
20152015
actual_end_date?: string | null;
2016-
budget?: number;
2016+
budget?: number | null;
20172017
business_code?: string;
20182018
description?: string;
20192019
expected_end_date?: string | null;

front/src/modules/project/components/AddOrEditProjectModal.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import useModalFocusTrap from 'utils/hooks/useModalFocusTrap';
3434
import useOutsideClick from 'utils/hooks/useOutsideClick';
3535

3636
const emptyProject: ProjectCreateForm = {
37-
budget: undefined,
37+
budget: null,
3838
description: '',
3939
funders: '',
4040
image: null,
@@ -384,11 +384,11 @@ export default function AddOrEditProjectModal({
384384
{t('projectBudget')}
385385
</div>
386386
}
387-
value={currentProject.budget !== undefined ? currentProject.budget : ''}
387+
value={currentProject.budget !== undefined && currentProject.budget !== null ? currentProject.budget : ''}
388388
onChange={(e) =>
389389
handleProjectInputChange(
390390
'budget',
391-
e.target.value !== '' ? +e.target.value : undefined
391+
e.target.value !== '' ? +e.target.value : null
392392
)
393393
}
394394
textRight

front/src/modules/study/components/AddOrEditStudyModal.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ type StudyParams = {
4545

4646
const emptyStudy: StudyForm = {
4747
actual_end_date: null,
48-
budget: undefined,
48+
budget: null,
4949
business_code: '',
5050
description: '',
5151
expected_end_date: null,
@@ -405,11 +405,11 @@ export default function AddOrEditStudyModal({ editionMode, study }: Props) {
405405
{t('studyBudget')}
406406
</div>
407407
}
408-
value={currentStudy.budget !== undefined ? currentStudy.budget : ''}
408+
value={currentStudy.budget !== undefined && currentStudy.budget !== null ? currentStudy.budget : ''}
409409
onChange={(e) =>
410410
handleStudyInputChange(
411411
'budget',
412-
e.target.value !== '' ? +e.target.value : undefined
412+
e.target.value !== '' ? +e.target.value : null
413413
)
414414
}
415415
textRight

front/src/modules/study/components/StudyCard.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export default function StudyCard({ setFilterChips, study }: StudyCardProps) {
5555
)}
5656
<div className="study-card-description">{study.description}</div>
5757

58-
{(study.budget > 0 || study.service_code || study.business_code) && (
58+
{(study.budget !== 0 || study.service_code || study.business_code) && (
5959
<div className="study-card-financials">
6060
<div className="study-card-financials-infos">
6161
{study.service_code && (
@@ -71,12 +71,12 @@ export default function StudyCard({ setFilterChips, study }: StudyCardProps) {
7171
</div>
7272
)}
7373
</div>
74-
{study.budget > 0 && (
74+
{study.budget ? (
7575
<div className="study-card-financials-amount">
7676
<span className="study-card-financials-amount-text">{t('budget')}</span>
7777
{budgetFormat(study.budget)}
7878
</div>
79-
)}
79+
) : null}
8080
</div>
8181
)}
8282

0 commit comments

Comments
 (0)