Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

editoast: make budget nullable in project and study #6861

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
UPDATE study SET budget = COALESCE(budget, 0);
ALTER TABLE study ALTER COLUMN budget SET NOT NULL;

UPDATE project SET budget = COALESCE(budget, 0);
ALTER TABLE project ALTER COLUMN budget SET NOT NULL;
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TABLE study ALTER COLUMN budget DROP NOT NULL;
ALTER TABLE project ALTER COLUMN budget DROP NOT NULL;
6 changes: 4 additions & 2 deletions editoast/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4475,6 +4475,7 @@ components:
properties:
budget:
format: int32
nullable: true
type: integer
creation_date:
format: date-time
Expand Down Expand Up @@ -4505,7 +4506,6 @@ components:
- objectives
- description
- funders
- budget
- creation_date
- last_modification
- tags
Expand All @@ -4515,6 +4515,7 @@ components:
properties:
budget:
format: int32
nullable: true
type: integer
description:
maxLength: 1024
Expand Down Expand Up @@ -5967,6 +5968,7 @@ components:
type: string
budget:
format: int32
nullable: true
type: integer
business_code:
type: string
Expand Down Expand Up @@ -6010,7 +6012,6 @@ components:
- service_code
- creation_date
- last_modification
- budget
- tags
- state
- study_type
Expand All @@ -6025,6 +6026,7 @@ components:
type: string
budget:
format: int32
nullable: true
type: integer
business_code:
type: string
Expand Down
4 changes: 2 additions & 2 deletions editoast/src/fixtures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ pub mod tests {
.service_code("BBB".into())
.creation_date(Utc::now().naive_utc())
.last_modification(Utc::now().naive_utc())
.budget(0)
.budget(Some(0))
.tags(Tags::default())
.state("some_state".into())
.study_type("some_type".into())
Expand All @@ -313,7 +313,7 @@ pub mod tests {
.objectives("".to_owned())
.description("".to_owned())
.funders("".to_owned())
.budget(0)
.budget(Some(0))
.creation_date(Utc::now().naive_utc())
.last_modification(Utc::now().naive_utc())
.tags(Tags::default());
Expand Down
4 changes: 2 additions & 2 deletions editoast/src/modelsv2/projects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub struct Project {
pub objectives: String,
pub description: String,
pub funders: String,
pub budget: i32,
pub budget: Option<i32>,
pub creation_date: NaiveDateTime,
pub last_modification: NaiveDateTime,
#[model(remote = "Vec<Option<String>>")]
Expand Down Expand Up @@ -239,7 +239,7 @@ pub mod test {
// Patch a project
let mut project = project_fixture.model.clone();
project.name = "update_name".into();
project.budget = 1000;
project.budget = Some(1000);
project.save(conn).await.unwrap();
let project = Project::retrieve(conn, project.id).await.unwrap().unwrap();
assert_eq!(project.name, String::from("update_name"));
Expand Down
2 changes: 1 addition & 1 deletion editoast/src/modelsv2/study.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub struct Study {
pub start_date: Option<NaiveDate>,
pub expected_end_date: Option<NaiveDate>,
pub actual_end_date: Option<NaiveDate>,
pub budget: i32,
pub budget: Option<i32>,
#[model(remote = "Vec<Option<String>>")]
pub tags: Tags,
pub state: String,
Expand Down
4 changes: 2 additions & 2 deletions editoast/src/tables.rs
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ diesel::table! {
description -> Varchar,
#[max_length = 255]
funders -> Varchar,
budget -> Int4,
budget -> Nullable<Int4>,
creation_date -> Timestamptz,
last_modification -> Timestamptz,
tags -> Array<Nullable<Text>>,
Expand Down Expand Up @@ -612,7 +612,7 @@ diesel::table! {
start_date -> Nullable<Date>,
expected_end_date -> Nullable<Date>,
actual_end_date -> Nullable<Date>,
budget -> Int4,
budget -> Nullable<Int4>,
tags -> Array<Nullable<Text>>,
#[max_length = 16]
state -> Varchar,
Expand Down
5 changes: 2 additions & 3 deletions editoast/src/views/projects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,7 @@ struct ProjectCreateForm {
#[serde(default)]
#[schema(max_length = 1024)]
pub funders: String,
#[serde(default)]
pub budget: i32,
pub budget: Option<i32>,
/// The id of the image document
pub image: Option<i64>,
#[serde(default)]
Expand Down Expand Up @@ -269,7 +268,7 @@ impl From<ProjectPatchForm> for Changeset<Project> {
.flat_description(project.description)
.flat_objectives(project.objectives)
.flat_funders(project.funders)
.flat_budget(project.budget)
.flat_budget(Some(project.budget))
.flat_image(Some(project.image))
.flat_tags(project.tags)
}
Expand Down
5 changes: 2 additions & 3 deletions editoast/src/views/study.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,7 @@ struct StudyCreateForm {
pub business_code: String,
#[serde(default)]
pub service_code: String,
#[serde(default)]
pub budget: i32,
pub budget: Option<i32>,
#[serde(default)]
pub tags: Tags,
pub state: String,
Expand Down Expand Up @@ -328,7 +327,7 @@ impl StudyPatchForm {
.flat_start_date(Some(self.start_date))
.flat_expected_end_date(Some(self.expected_end_date))
.flat_actual_end_date(Some(self.actual_end_date))
.flat_budget(self.budget)
.flat_budget(Some(self.budget))
.flat_tags(self.tags)
.flat_state(self.state)
.flat_study_type(self.study_type);
Expand Down
6 changes: 3 additions & 3 deletions front/src/applications/operationalStudies/views/Project.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -240,20 +240,20 @@ export default function Project() {
</div>
</div>
</div>
{(project.funders || (project.budget !== undefined && project.budget !== 0)) && (
{(project.funders || (project.budget !== 0 && project.budget !== null)) && (
<div className="project-details-financials">
<div className="project-details-financials-infos">
<h3>{t('fundedBy')}</h3>
{project.funders && <div>{project.funders}</div>}
</div>
{project.budget !== undefined && project.budget !== 0 && (
{project.budget ? (
<div className="project-details-financials-amount">
<span className="project-details-financials-amount-text">
{t('totalBudget')}
</span>
{budgetFormat(project.budget)}
</div>
)}
) : null}
</div>
)}
<div className="project-details-tags">
Expand Down
20 changes: 7 additions & 13 deletions front/src/applications/operationalStudies/views/Study.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import OptionsSNCF from 'common/BootstrapSNCF/OptionsSNCF';
import { Loader, Spinner } from 'common/Loaders';
import ScenarioCard from 'modules/scenario/components/ScenarioCard';
import ScenarioCardEmpty from 'modules/scenario/components/ScenarioCardEmpty';
import AddOrEditStudyModal, { type StudyForm } from 'modules/study/components/AddOrEditStudyModal';
import AddOrEditStudyModal from 'modules/study/components/AddOrEditStudyModal';
import { budgetFormat } from 'utils/numbers';

type SortOptions =
Expand Down Expand Up @@ -221,15 +221,7 @@ export default function Study() {
type="button"
onClick={() =>
openModal(
<AddOrEditStudyModal
editionMode
study={
{
...study,
budget: study.budget !== 0 ? study.budget : undefined,
} as StudyForm
}
/>,
<AddOrEditStudyModal editionMode study={study} />,
'xl',
'no-close-modal'
)
Expand Down Expand Up @@ -268,7 +260,9 @@ export default function Study() {
)}
</div>

{(study.service_code || study.business_code || study.budget !== 0) && (
{(study.service_code ||
study.business_code ||
(study.budget !== 0 && study.budget !== null)) && (
<div className="study-details-financials">
<div className="study-details-financials-infos">
{study.service_code && (
Expand All @@ -284,12 +278,12 @@ export default function Study() {
</div>
)}
</div>
{study.budget !== 0 && (
{study.budget ? (
<div className="study-details-financials-amount">
<span className="study-details-financials-amount-text">{t('budget')}</span>
{budgetFormat(study.budget)}
</div>
)}
) : null}
</div>
)}

Expand Down
8 changes: 4 additions & 4 deletions front/src/common/api/osrdEditoastApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1926,7 +1926,7 @@ export type ElectrificationsOnPathResponse = {
};
export type Tags = string[];
export type Project = {
budget: number;
budget?: number | null;
creation_date: string;
description: string;
funders: string;
Expand Down Expand Up @@ -1958,7 +1958,7 @@ export type Ordering =
| 'LastModifiedDesc'
| 'LastModifiedAsc';
export type ProjectCreateForm = {
budget?: number;
budget?: number | null;
description?: string;
funders?: string;
/** The id of the image document */
Expand All @@ -1979,7 +1979,7 @@ export type ProjectPatchForm = {
};
export type Study = {
actual_end_date?: string | null;
budget: number;
budget?: number | null;
business_code: string;
creation_date: string;
description: string;
Expand Down Expand Up @@ -2013,7 +2013,7 @@ export type StudyResponse = Study & {
};
export type StudyCreateForm = {
actual_end_date?: string | null;
budget?: number;
budget?: number | null;
business_code?: string;
description?: string;
expected_end_date?: string | null;
Expand Down
13 changes: 7 additions & 6 deletions front/src/modules/project/components/AddOrEditProjectModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import useModalFocusTrap from 'utils/hooks/useModalFocusTrap';
import useOutsideClick from 'utils/hooks/useOutsideClick';

const emptyProject: ProjectCreateForm = {
budget: undefined,
budget: null,
description: '',
funders: '',
image: null,
Expand Down Expand Up @@ -384,12 +384,13 @@ export default function AddOrEditProjectModal({
{t('projectBudget')}
</div>
}
value={currentProject.budget !== undefined ? currentProject.budget : ''}
value={
currentProject.budget !== undefined && currentProject.budget !== null
? currentProject.budget
: ''
}
onChange={(e) =>
handleProjectInputChange(
'budget',
e.target.value !== '' ? +e.target.value : undefined
)
handleProjectInputChange('budget', e.target.value !== '' ? +e.target.value : null)
}
textRight
/>
Expand Down
13 changes: 7 additions & 6 deletions front/src/modules/study/components/AddOrEditStudyModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ type StudyParams = {

const emptyStudy: StudyForm = {
actual_end_date: null,
budget: undefined,
budget: null,
business_code: '',
description: '',
expected_end_date: null,
Expand Down Expand Up @@ -405,12 +405,13 @@ export default function AddOrEditStudyModal({ editionMode, study }: Props) {
{t('studyBudget')}
</div>
}
value={currentStudy.budget !== undefined ? currentStudy.budget : ''}
value={
currentStudy.budget !== undefined && currentStudy.budget !== null
? currentStudy.budget
: ''
}
onChange={(e) =>
handleStudyInputChange(
'budget',
e.target.value !== '' ? +e.target.value : undefined
)
handleStudyInputChange('budget', e.target.value !== '' ? +e.target.value : null)
}
textRight
/>
Expand Down
6 changes: 3 additions & 3 deletions front/src/modules/study/components/StudyCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export default function StudyCard({ setFilterChips, study }: StudyCardProps) {
)}
<div className="study-card-description">{study.description}</div>

{(study.budget > 0 || study.service_code || study.business_code) && (
{(study.budget !== 0 || study.service_code || study.business_code) && (
<div className="study-card-financials">
<div className="study-card-financials-infos">
{study.service_code && (
Expand All @@ -71,12 +71,12 @@ export default function StudyCard({ setFilterChips, study }: StudyCardProps) {
</div>
)}
</div>
{study.budget > 0 && (
{study.budget ? (
<div className="study-card-financials-amount">
<span className="study-card-financials-amount-text">{t('budget')}</span>
{budgetFormat(study.budget)}
</div>
)}
) : null}
</div>
)}

Expand Down
Loading