Fix: Closing stock on update was not working as it was not able to encode/parse creation date and last edit date

This commit is contained in:
2021-11-02 11:57:06 +05:30
parent b69a38d8e9
commit b6ef6f79e5
2 changed files with 22 additions and 6 deletions

View File

@ -40,10 +40,26 @@ class ClosingStock(BaseModel):
class Config:
anystr_strip_whitespace = True
alias_generator = to_camel
json_encoders = {date: lambda v: v.strftime("%d-%b-%Y")}
json_encoders = {date: lambda v: v.strftime("%d-%b-%Y"), datetime: lambda v: v.strftime("%d-%b-%Y %H:%M")}
@validator("date_", pre=True)
def parse_date(cls, value):
if isinstance(value, date):
return value
return datetime.strptime(value, "%d-%b-%Y").date()
@validator("creation_date", pre=True)
def parse_creation_date(cls, value):
if value is None:
return None
if isinstance(value, datetime):
return value
return datetime.strptime(value, "%d-%b-%Y %H:%M")
@validator("last_edit_date", pre=True)
def parse_last_edit_date(cls, value):
if value is None:
return None
if isinstance(value, datetime):
return value
return datetime.strptime(value, "%d-%b-%Y %H:%M")