Skip to content

Commit

Permalink
chore: fix date output (#437)
Browse files Browse the repository at this point in the history
Co-authored-by: Victor Shia <[email protected]>
  • Loading branch information
vshia and vshia authored Sep 23, 2024
1 parent c1862d4 commit b9a1679
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 3 deletions.
5 changes: 2 additions & 3 deletions python/src/functions/generate_treasury_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -438,8 +438,7 @@ def insert_project_row(
sheet is Optional only for tests
"""
row_schema = row.model_json_schema()["properties"]
row_dict = dict(row)

row_dict = row.dict()
row_with_output_cols = {}
for prop in row_dict.keys():
prop_meta = row_schema.get(prop)
Expand All @@ -448,7 +447,7 @@ def insert_project_row(
if prop_meta[f"treasury_report_col_{project_use_code}"]:
row_with_output_cols[
prop_meta[f"treasury_report_col_{project_use_code}"]
] = row_dict[prop]
] = row_dict[prop] if row_dict[prop] else ""

for col in row_with_output_cols.keys():
if sheet:
Expand Down
15 changes: 15 additions & 0 deletions python/src/schemas/schema_V2024_04_01.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
condecimal,
conint,
constr,
field_serializer,
field_validator,
)

Expand Down Expand Up @@ -350,6 +351,20 @@ def parse_mm_dd_yyyy_dates(cls, v):
raise ValueError(f"Date {v} is not in 'mm/dd/yyyy' format.")
return v

@field_serializer(
"Projected_Con_Start_Date__c",
"Projected_Con_Completion__c",
"Projected_Init_of_Operations__c",
"Actual_Con_Start_Date__c",
"Actual_Con_Completion__c",
"Actual_operations_date__c",
)
def serialize_mm_dd_yyyy_dates(self, value: datetime) -> str:
if value:
return value.strftime("%m/%d/%Y")
else:
return ""

@field_validator(
"Project_Name__c",
"Identification_Number__c",
Expand Down
16 changes: 16 additions & 0 deletions python/src/schemas/schema_V2024_05_24.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
condecimal,
conint,
constr,
field_serializer,
field_validator,
)

Expand Down Expand Up @@ -242,6 +243,7 @@ class BaseProjectRow(BaseModel):
Current_Period_Obligation__c: condecimal(max_digits=12, decimal_places=2) = Field(
...,
serialization_alias="Current Period Obligation",

json_schema_extra={
"column": "L",
"treasury_report_col_1A": "K",
Expand Down Expand Up @@ -609,6 +611,20 @@ def parse_mm_dd_yyyy_dates(cls, v):
raise ValueError(f"Date {v} is not in 'mm/dd/yyyy' format.")
return v

@field_serializer(
"Projected_Con_Start_Date__c",
"Projected_Con_Completion__c",
"Projected_Init_of_Operations__c",
"Actual_Con_Start_Date__c",
"Actual_Con_Completion__c",
"Actual_operations_date__c",
)
def serialize_mm_dd_yyyy_dates(self, value: datetime) -> str:
if value:
return value.strftime("%m/%d/%Y")
else:
return ""

@field_validator(
"Project_Name__c",
"Identification_Number__c",
Expand Down

0 comments on commit b9a1679

Please sign in to comment.