41 lines
1.0 KiB
Python
41 lines
1.0 KiB
Python
from datetime import date, datetime
|
|
from decimal import Decimal
|
|
|
|
from pydantic import BaseModel, validator
|
|
|
|
from . import to_camel
|
|
|
|
|
|
class TaxReportItem(BaseModel):
|
|
name: str
|
|
tax_rate: Decimal
|
|
sale_amount: Decimal
|
|
amount: Decimal
|
|
|
|
class Config:
|
|
anystr_strip_whitespace = True
|
|
alias_generator = to_camel
|
|
|
|
|
|
class TaxReport(BaseModel):
|
|
start_date: date
|
|
finish_date: date
|
|
amounts: list[TaxReportItem]
|
|
|
|
class Config:
|
|
anystr_strip_whitespace = True
|
|
alias_generator = to_camel
|
|
json_encoders = {datetime: lambda v: v.strftime("%d-%b-%Y %H:%M"), date: lambda v: v.strftime("%d-%b-%Y")}
|
|
|
|
@validator("start_date", pre=True)
|
|
def parse_start_date(cls, value):
|
|
if isinstance(value, date):
|
|
return value
|
|
return datetime.strptime(value, "%d-%b-%Y").date()
|
|
|
|
@validator("finish_date", pre=True)
|
|
def parse_finish_date(cls, value):
|
|
if isinstance(value, date):
|
|
return value
|
|
return datetime.strptime(value, "%d-%b-%Y").date()
|