barker/barker/barker/schemas/voucher.py

59 lines
1.4 KiB
Python

import uuid
from typing import Optional, List
from decimal import Decimal
from pydantic import BaseModel, Field
from barker.schemas import to_camel
from barker.schemas.customer import CustomerLink
from barker.schemas.modifier import ModifierLink
from barker.schemas.product import ProductLink
from barker.schemas.table import TableLink
from barker.schemas.tax import TaxLink
class Inventory(BaseModel):
id_: Optional[uuid.UUID]
product: ProductLink
quantity: Decimal = Field(ge=0, multiple_of=0.01)
price: Optional[Decimal]
tax: Optional[TaxLink]
tax_rate: Optional[Decimal]
discount: Decimal = Field(ge=0, multiple_of=0.00001, le=1)
is_happy_hour: bool
modifiers: Optional[List[ModifierLink]]
amount: Optional[Decimal]
class Config:
alias_generator = to_camel
class Kot(BaseModel):
id_: Optional[uuid.UUID]
inventories: List[Inventory]
class Config:
anystr_strip_whitespace = True
alias_generator = to_camel
class VoucherIn(BaseModel):
pax: int
table: TableLink
customer: Optional[CustomerLink]
kots: List[Kot]
class Config:
fields = {"id_": "id"}
anystr_strip_whitespace = True
alias_generator = to_camel
class Voucher(VoucherIn):
id_: uuid.UUID
class Config:
fields = {"id_": "id"}
anystr_strip_whitespace = True
alias_generator = to_camel