49 lines
1.2 KiB
Python
49 lines
1.2 KiB
Python
|
import uuid
|
||
|
|
||
|
from datetime import date, datetime
|
||
|
from decimal import Decimal
|
||
|
|
||
|
from pydantic import BaseModel, validator
|
||
|
|
||
|
from . import to_camel
|
||
|
|
||
|
|
||
|
class MeItem(BaseModel):
|
||
|
id_: uuid.UUID
|
||
|
name: str
|
||
|
price: Decimal
|
||
|
average: Decimal
|
||
|
sale_category: str
|
||
|
menu_category: str
|
||
|
quantity: Decimal
|
||
|
sales: Decimal
|
||
|
quantity_percent: Decimal
|
||
|
sales_percent: Decimal
|
||
|
|
||
|
class Config:
|
||
|
anystr_strip_whitespace = True
|
||
|
alias_generator = to_camel
|
||
|
|
||
|
|
||
|
class MeReport(BaseModel):
|
||
|
start_date: date
|
||
|
finish_date: date
|
||
|
amounts: list[MeItem]
|
||
|
|
||
|
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()
|