57 lines
1.1 KiB
Python
57 lines
1.1 KiB
Python
import uuid
|
|
|
|
from decimal import Decimal
|
|
|
|
from pydantic import BaseModel, Field
|
|
|
|
from . import to_camel
|
|
|
|
|
|
class CustomerDiscount(BaseModel):
|
|
id_: uuid.UUID
|
|
name: str
|
|
discount: Decimal = Field(ge=0, multiple_of=0.0001, default=0, le=1)
|
|
limit: Decimal = Field(ge=0, multiple_of=0.0001, default=0, le=1)
|
|
|
|
class Config:
|
|
alias_generator = to_camel
|
|
|
|
|
|
class CustomerIn(BaseModel):
|
|
name: str = Field(..., min_length=1)
|
|
# phone: str = Field(..., min_length=1)
|
|
phone: str
|
|
address: str | None
|
|
print_in_bill: bool
|
|
|
|
discounts: list[CustomerDiscount]
|
|
|
|
class Config:
|
|
anystr_strip_whitespace = True
|
|
alias_generator = to_camel
|
|
|
|
|
|
class Customer(CustomerIn):
|
|
id_: uuid.UUID
|
|
|
|
class Config:
|
|
fields = {"id_": "id"}
|
|
anystr_strip_whitespace = True
|
|
alias_generator = to_camel
|
|
|
|
|
|
class CustomerLink(BaseModel):
|
|
id_: uuid.UUID = Field(...)
|
|
name: str | None
|
|
|
|
class Config:
|
|
fields = {"id_": "id"}
|
|
|
|
|
|
class CustomerBlank(CustomerIn):
|
|
name: str
|
|
|
|
class Config:
|
|
anystr_strip_whitespace = True
|
|
alias_generator = to_camel
|