barker/barker/barker/schemas/master.py

91 lines
2.7 KiB
Python

import uuid
from typing import Optional
from datetime import date, datetime
from decimal import Decimal
from pydantic import BaseModel, Field, validator
from barker.schemas import to_camel
from barker.schemas.tax import TaxLink, TaxIn, Tax # noqa: F401
from barker.schemas.sale_category import SaleCategoryLink, SaleCategoryIn, SaleCategory # noqa: F401
from barker.schemas.customer import CustomerIn, Customer # noqa: F401
from barker.schemas.guest_book import GuestBookIn, GuestBook # noqa: F401
from barker.schemas.menu_category import MenuCategoryLink, MenuCategoryIn, MenuCategory # noqa: F401
from barker.schemas.product import ProductLink, ProductIn, Product # noqa: F401
from barker.schemas.modifier_category import ModifierCategoryLink, ModifierCategoryIn, ModifierCategory # noqa: F401
from barker.schemas.modifier import ModifierLink, ModifierIn, Modifier # noqa: F401
from barker.schemas.printer import PrinterLink, PrinterIn, Printer # noqa: F401
from barker.schemas.section import SectionLink, SectionIn, Section # noqa: F401
from barker.schemas.device import DeviceLink, DeviceIn, Device # noqa: F401
from barker.schemas.section_printer import SectionPrinter # noqa: F401
from barker.schemas.table import TableLink, TableIn, Table # noqa: F401
class AccountBase(BaseModel):
name: str = Field(..., min_length=1)
is_starred: bool
is_active: bool
class Config:
fields = {"id_": "id"}
anystr_strip_whitespace = True
alias_generator = to_camel
class AccountIn(AccountBase):
type: int
is_reconcilable: bool
class Account(AccountIn):
id_: uuid.UUID
code: int
is_fixture: bool
class EmployeeIn(AccountBase):
designation: str
salary: int = Field(ge=0)
points: Decimal = Field(ge=0, lt=1000, multiple_of=0.01)
joining_date: date
leaving_date: Optional[date]
@validator("joining_date", pre=True)
def parse_joining_date(cls, value):
return datetime.strptime(value, "%d-%b-%Y").date()
@validator("leaving_date", pre=True)
def parse_leaving_date(cls, value):
if value is None or value == "":
return None
else:
return datetime.strptime(value, "%d-%b-%Y").date()
@validator("leaving_date")
def leaving_date_more_than_joining_date(cls, v, values, **kwargs):
if values["is_active"]:
return None
if v < values["joining_date"]:
raise ValueError("Leaving Date cannot be less than Joining Date")
return v
class Employee(EmployeeIn):
id_: uuid.UUID
code: int
is_fixture: bool
class DbSetting(BaseModel):
id_: uuid.UUID
name: str
data: bytes
class AccountType(BaseModel):
id_: int
name: str
class Config:
fields = {"id_": "id"}