Chore: fixed a lot of mypy errors.
This commit is contained in:
1 parent
0e9d9c5934
commit
31b4ee1ebf
72 files changed
+432
-347
No files matched your search
@@ -30,7 +30,7 @@ class Bill:
|
||||
voucher: Mapped["Voucher"] = relationship(back_populates="bills")
|
||||
regime: Mapped["Regime"] = relationship(back_populates="bills")
|
||||
|
||||
def __init__(self, regime_id, is_valid, bill_number):
|
||||
def __init__(self, regime_id: int, is_valid: bool, bill_number: int):
|
||||
self.regime_id = regime_id
|
||||
self.is_valid = is_valid
|
||||
self.bill_number = bill_number
|
||||
@@ -26,17 +26,14 @@ class Customer:
|
||||
|
||||
discounts: Mapped[list["CustomerDiscount"]] = relationship(back_populates="customer")
|
||||
|
||||
@property
|
||||
def __name__(self):
|
||||
return self.name
|
||||
|
||||
def __init__(self, name=None, phone=None, address=None, print_in_bill=None, id_=None):
|
||||
def __init__(self, name: str, phone: str, address: str | None, print_in_bill: bool, id_: uuid.UUID | None = None):
|
||||
self.name = name
|
||||
self.phone = phone
|
||||
self.address = address
|
||||
self.print_in_bill = print_in_bill
|
||||
self.id = id_
|
||||
if id_ is not None:
|
||||
self.id = id_
|
||||
|
||||
@classmethod
|
||||
def cash(cls):
|
||||
def cash(cls) -> uuid.UUID:
|
||||
return uuid.UUID("2c716f4b-0736-429a-ad51-610d7c47cb5e")
|
||||
@@ -28,12 +28,21 @@ class CustomerDiscount:
|
||||
customer: Mapped["Customer"] = relationship(back_populates="discounts")
|
||||
sale_category: Mapped["SaleCategory"] = relationship("SaleCategory")
|
||||
|
||||
def __init__(self, sale_category_id=None, discount=None, id_=None, customer_id=None, customer=None):
|
||||
def __init__(
|
||||
self,
|
||||
sale_category_id: uuid.UUID,
|
||||
discount: Decimal,
|
||||
id_: uuid.UUID | None = None,
|
||||
customer_id: uuid.UUID | None = None,
|
||||
customer: "Customer | None" = None,
|
||||
):
|
||||
self.sale_category_id = sale_category_id
|
||||
self.discount = discount
|
||||
self.id = id_
|
||||
if id_ is not None:
|
||||
self.id = id_
|
||||
self.date = datetime.now(UTC).replace(tzinfo=None)
|
||||
if customer is None:
|
||||
self.customer_id = customer_id
|
||||
if customer_id is not None:
|
||||
self.customer_id = customer_id
|
||||
else:
|
||||
self.customer = customer
|
||||
@@ -14,7 +14,8 @@ class DbSetting:
|
||||
name: Mapped[str] = mapped_column(Text, unique=True, nullable=False)
|
||||
data = mapped_column(JSON, nullable=False)
|
||||
|
||||
def __init__(self, id_=None, name=None, data=None):
|
||||
self.id = id_
|
||||
def __init__(self, id_: uuid.UUID | None, name: str, data: JSON):
|
||||
if id_ is not None:
|
||||
self.id = id_
|
||||
self.name = name
|
||||
self.data = data
|
||||
@@ -31,15 +31,23 @@ class Device:
|
||||
order_by=desc(LoginHistory.date), back_populates="device"
|
||||
)
|
||||
|
||||
def __init__(self, name=None, enabled=None, section_id=None, creation_date=None, id_=None):
|
||||
def __init__(
|
||||
self,
|
||||
name: str,
|
||||
enabled: bool,
|
||||
section_id: uuid.UUID,
|
||||
creation_date: datetime | None = None,
|
||||
id_: uuid.UUID | None = None,
|
||||
):
|
||||
self.name = name
|
||||
self.enabled = enabled
|
||||
self.section_id = section_id
|
||||
self.creation_date = datetime.now(UTC).replace(tzinfo=None) if creation_date is None else creation_date
|
||||
self.id = id_
|
||||
if id_ is not None:
|
||||
self.id = id_
|
||||
|
||||
@classmethod
|
||||
def create(cls, db: Session):
|
||||
def create(cls, db: Session) -> "Device":
|
||||
main_section = uuid.UUID("3f13f6e7-dc76-4fca-8fdb-b2bbf29b35df")
|
||||
name = "".join(random.choices(string.ascii_lowercase + string.digits, k=6))
|
||||
device = Device(name, False, main_section)
|
||||
|
||||
@@ -22,27 +22,24 @@ class FoodTable:
|
||||
seats: Mapped[int] = mapped_column(Integer, nullable=False)
|
||||
section_id: Mapped[uuid.UUID] = mapped_column(Uuid, ForeignKey("sections.id"), nullable=False)
|
||||
is_active: Mapped[bool] = mapped_column(Boolean, nullable=False)
|
||||
sort_order: Mapped[bool] = mapped_column(Integer, nullable=False)
|
||||
sort_order: Mapped[int] = mapped_column(Integer, nullable=False)
|
||||
|
||||
section: Mapped["Section"] = relationship("Section", foreign_keys=section_id)
|
||||
status: Mapped[Optional["Overview"]] = relationship(back_populates="food_table", uselist=False)
|
||||
|
||||
@property
|
||||
def __name__(self):
|
||||
return self.name
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
name=None,
|
||||
seats=None,
|
||||
section_id=None,
|
||||
is_active=None,
|
||||
sort_order=0,
|
||||
id_=None,
|
||||
name: str,
|
||||
seats: int,
|
||||
section_id: uuid.UUID,
|
||||
is_active: bool,
|
||||
sort_order: int = 0,
|
||||
id_: uuid.UUID | None = None,
|
||||
):
|
||||
self.name = name
|
||||
self.seats = seats
|
||||
self.section_id = section_id
|
||||
self.is_active = is_active
|
||||
self.sort_order = sort_order
|
||||
self.id = id_
|
||||
if id_ is not None:
|
||||
self.id = id_
|
||||
@@ -43,14 +43,14 @@ class GuestBook:
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
customer_id=None,
|
||||
pax=None,
|
||||
booking_date=None,
|
||||
arrival_date=None,
|
||||
notes=None,
|
||||
type_=None,
|
||||
customer=None,
|
||||
id_=None,
|
||||
pax: int,
|
||||
booking_date: datetime | None,
|
||||
arrival_date: datetime | None,
|
||||
notes: str | None,
|
||||
type_: GuestBookType,
|
||||
customer_id: uuid.UUID | None = None,
|
||||
customer: "Customer | None " = None,
|
||||
id_: uuid.UUID | None = None,
|
||||
):
|
||||
if customer_id is not None:
|
||||
self.customer_id = customer_id
|
||||
@@ -63,8 +63,9 @@ class GuestBook:
|
||||
self.last_edit_date = datetime.now(UTC).replace(tzinfo=None)
|
||||
self.notes = notes
|
||||
self.type_ = type_
|
||||
if customer is None:
|
||||
if customer is None and customer_id is not None:
|
||||
self.customer_id = customer_id
|
||||
else:
|
||||
if customer is not None:
|
||||
self.customer = customer
|
||||
self.id = id_
|
||||
if id_ is not None:
|
||||
self.id = id_
|
||||
@@ -53,17 +53,17 @@ class Inventory:
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
kot_id=None,
|
||||
product_id=None,
|
||||
quantity=None,
|
||||
price=None,
|
||||
discount=None,
|
||||
is_hh=None,
|
||||
tax_id=None,
|
||||
tax_rate=None,
|
||||
sort_order=None,
|
||||
product=None,
|
||||
tax=None,
|
||||
kot_id: uuid.UUID,
|
||||
product_id: uuid.UUID | None,
|
||||
quantity: Decimal,
|
||||
price: Decimal,
|
||||
discount: Decimal,
|
||||
is_hh: bool,
|
||||
tax_id: uuid.UUID | None,
|
||||
tax_rate: Decimal,
|
||||
sort_order: int,
|
||||
product: "Product | None" = None,
|
||||
tax: "Tax | None" = None,
|
||||
):
|
||||
self.kot_id = kot_id
|
||||
if product_id is not None:
|
||||
|
||||
@@ -43,14 +43,15 @@ class Kot:
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
voucher_id=None,
|
||||
code=None,
|
||||
food_table_id=None,
|
||||
date=None,
|
||||
user_id=None,
|
||||
id_=None,
|
||||
voucher_id: uuid.UUID,
|
||||
code: int,
|
||||
food_table_id: uuid.UUID,
|
||||
date: datetime,
|
||||
user_id: uuid.UUID,
|
||||
id_: uuid.UUID | None = None,
|
||||
):
|
||||
self.id = id_
|
||||
if id_ is not None:
|
||||
self.id = id_
|
||||
self.voucher_id = voucher_id
|
||||
self.code = code
|
||||
self.food_table_id = food_table_id
|
||||
|
||||
@@ -30,8 +30,15 @@ class LoginHistory:
|
||||
device: Mapped["Device"] = relationship(back_populates="login_history")
|
||||
user: Mapped["User"] = relationship(back_populates="login_history")
|
||||
|
||||
def __init__(self, user_id=None, device_id=None, date=None, id_=None):
|
||||
def __init__(
|
||||
self,
|
||||
user_id: uuid.UUID,
|
||||
device_id: uuid.UUID,
|
||||
date: datetime | None = None,
|
||||
id_: uuid.UUID | None = None,
|
||||
):
|
||||
self.user_id = user_id
|
||||
self.device_id = device_id
|
||||
self.date = datetime.now(UTC).replace(tzinfo=None) if date is None else date
|
||||
self.id = id_
|
||||
if id_ is not None:
|
||||
self.id = id_
|
||||
@@ -25,9 +25,12 @@ class MenuCategory:
|
||||
|
||||
products: Mapped[list["ProductVersion"]] = relationship(back_populates="menu_category")
|
||||
|
||||
def __init__(self, name, is_active, sort_order, is_fixture=False, id_=None):
|
||||
def __init__(
|
||||
self, name: str, is_active: bool, sort_order: int, is_fixture: bool = False, id_: uuid.UUID | None = None
|
||||
):
|
||||
self.name = name
|
||||
self.is_active = is_active
|
||||
self.sort_order = sort_order
|
||||
self.is_fixture = is_fixture
|
||||
self.id = id_
|
||||
if id_ is not None:
|
||||
self.id = id_
|
||||
@@ -32,14 +32,15 @@ class Modifier:
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
name=None,
|
||||
show_in_bill=None,
|
||||
price=None,
|
||||
modifier_category_id=None,
|
||||
is_active=True,
|
||||
id_=None,
|
||||
name: str,
|
||||
show_in_bill: bool,
|
||||
price: Decimal,
|
||||
modifier_category_id: uuid.UUID,
|
||||
is_active: bool = True,
|
||||
id_: uuid.UUID | None = None,
|
||||
):
|
||||
self.id = id_
|
||||
if id_ is not None:
|
||||
self.id = id_
|
||||
self.name = name
|
||||
self.show_in_bill = show_in_bill
|
||||
self.price = price
|
||||
|
||||
@@ -26,21 +26,22 @@ class ModifierCategory:
|
||||
sort_order: Mapped[int] = mapped_column(Integer, nullable=False)
|
||||
|
||||
products: Mapped[list["Product"]] = relationship(
|
||||
secondary=ModifierCategoryProduct.__table__, # type: ignore[attr-defined]
|
||||
secondary=ModifierCategoryProduct.__table__,
|
||||
back_populates="modifier_categories",
|
||||
)
|
||||
modifiers: Mapped[list["Modifier"]] = relationship(back_populates="modifier_category")
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
name=None,
|
||||
minimum=None,
|
||||
maximum=None,
|
||||
is_active=True,
|
||||
sort_order=0,
|
||||
id_=None,
|
||||
name: str,
|
||||
minimum: int,
|
||||
maximum: int | None = None,
|
||||
is_active: bool = True,
|
||||
sort_order: int = 0,
|
||||
id_: uuid.UUID | None = None,
|
||||
):
|
||||
self.id = id_
|
||||
if id_ is not None:
|
||||
self.id = id_
|
||||
self.name = name
|
||||
self.minimum = minimum
|
||||
self.maximum = maximum
|
||||
|
||||
@@ -33,16 +33,26 @@ class Overview:
|
||||
nullable=False,
|
||||
unique=True,
|
||||
)
|
||||
guest_book_id: Mapped[uuid.UUID] = mapped_column(Uuid, ForeignKey("guest_book.id"), unique=True, nullable=True)
|
||||
guest_book_id: Mapped[uuid.UUID | None] = mapped_column(
|
||||
Uuid, ForeignKey("guest_book.id"), unique=True, nullable=True
|
||||
)
|
||||
status: Mapped[OverviewStatus] = mapped_column(Enum(OverviewStatus), nullable=False)
|
||||
|
||||
voucher: Mapped[Voucher] = relationship(back_populates="status")
|
||||
food_table: Mapped[FoodTable] = relationship(back_populates="status")
|
||||
guest: Mapped[GuestBook] = relationship(back_populates="status")
|
||||
|
||||
def __init__(self, voucher_id, food_table_id, guest_book_id, status, id_=None):
|
||||
def __init__(
|
||||
self,
|
||||
voucher_id: uuid.UUID,
|
||||
food_table_id: uuid.UUID,
|
||||
guest_book_id: uuid.UUID | None,
|
||||
status: OverviewStatus,
|
||||
id_: uuid.UUID | None = None,
|
||||
):
|
||||
self.voucher_id = voucher_id
|
||||
self.food_table_id = food_table_id
|
||||
self.guest_book_id = guest_book_id
|
||||
self.status = status
|
||||
self.id = id_
|
||||
if id_ is not None:
|
||||
self.id = id_
|
||||
@@ -22,9 +22,10 @@ class Permission:
|
||||
|
||||
roles: Mapped[list["Role"]] = relationship(
|
||||
secondary=RolePermission.__table__,
|
||||
back_populates="permissions", # type: ignore[attr-defined]
|
||||
back_populates="permissions",
|
||||
)
|
||||
|
||||
def __init__(self, name=None, id_=None):
|
||||
def __init__(self, name: str, id_: uuid.UUID | None = None):
|
||||
self.name = name
|
||||
self.id = id_
|
||||
if id_ is not None:
|
||||
self.id = id_
|
||||
@@ -15,8 +15,9 @@ class Printer:
|
||||
address: Mapped[str] = mapped_column(Text, nullable=False)
|
||||
cut_code: Mapped[str] = mapped_column(Text, nullable=False)
|
||||
|
||||
def __init__(self, name=None, address=None, cut_code=None, id_=None):
|
||||
self.id = id_
|
||||
def __init__(self, name: str, address: str, cut_code: str, id_: uuid.UUID | None = None):
|
||||
if id_ is not None:
|
||||
self.id = id_
|
||||
self.name = name
|
||||
self.address = address
|
||||
self.cut_code = cut_code
|
||||
@@ -23,11 +23,11 @@ class Product:
|
||||
inventories: Mapped[list["Inventory"]] = relationship(back_populates="product")
|
||||
modifier_categories: Mapped[list["ModifierCategory"]] = relationship(
|
||||
"ModifierCategory",
|
||||
secondary=ModifierCategoryProduct.__table__, # type: ignore[attr-defined]
|
||||
secondary=ModifierCategoryProduct.__table__,
|
||||
order_by="ModifierCategory.sort_order",
|
||||
back_populates="products",
|
||||
)
|
||||
|
||||
def __init__(self, id_=None, version_id=None):
|
||||
self.id = id_
|
||||
self.version_id = version_id
|
||||
def __init__(self, id_: uuid.UUID | None = None):
|
||||
if id_ is not None:
|
||||
self.id = id_
|
||||
@@ -75,19 +75,19 @@ class ProductVersion:
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
product_id=None,
|
||||
name=None,
|
||||
units=None,
|
||||
menu_category_id=None,
|
||||
sale_category_id=None,
|
||||
price=None,
|
||||
has_happy_hour=None,
|
||||
is_not_available=None,
|
||||
quantity=None,
|
||||
valid_from=None,
|
||||
valid_till=None,
|
||||
sort_order=0,
|
||||
id_=None,
|
||||
product_id: uuid.UUID,
|
||||
name: str,
|
||||
units: str,
|
||||
menu_category_id: uuid.UUID,
|
||||
sale_category_id: uuid.UUID,
|
||||
price: Decimal,
|
||||
has_happy_hour: bool,
|
||||
is_not_available: bool,
|
||||
quantity: Decimal,
|
||||
valid_from: date | None,
|
||||
valid_till: date | None,
|
||||
sort_order: int = 0,
|
||||
id_: uuid.UUID | None = None,
|
||||
):
|
||||
self.product_id = product_id
|
||||
self.name = name
|
||||
@@ -101,21 +101,13 @@ class ProductVersion:
|
||||
self.valid_from = valid_from
|
||||
self.valid_till = valid_till
|
||||
self.sort_order = sort_order
|
||||
self.id = id_
|
||||
if id_ is not None:
|
||||
self.id = id_
|
||||
|
||||
@hybrid_property
|
||||
def full_name(self):
|
||||
def full_name(self) -> str:
|
||||
return f"{self.name} ({self.units})" if self.units else self.name
|
||||
|
||||
@full_name.inplace.expression
|
||||
def _full_name_expression(cls):
|
||||
return cls.name + case((cls.units != "", " (" + cls.units + ")"), else_="")
|
||||
|
||||
def can_delete(self, advanced_delete):
|
||||
if self.is_fixture:
|
||||
return False, f"{self.name} is a fixture and cannot be edited or deleted."
|
||||
if self.is_active:
|
||||
return False, "Product is active"
|
||||
# if len(self.inventories) > 0 and not advanced_delete:
|
||||
# return False, "Product has entries"
|
||||
return True, ""
|
||||
@@ -24,30 +24,29 @@ class Regime:
|
||||
taxes: Mapped[list["Tax"]] = relationship(back_populates="regime")
|
||||
bills: Mapped[list["Bill"]] = relationship(back_populates="regime")
|
||||
|
||||
def __init__(self, id=None, name=None, header=None, prefix=None, is_fixture=False, id_=None):
|
||||
def __init__(self, id: int, name: str, header: str, prefix: str, is_fixture: bool = False):
|
||||
self.id = id
|
||||
self.name = name
|
||||
self.header = header
|
||||
self.prefix = prefix
|
||||
self.is_fixture = is_fixture
|
||||
self.id = id_
|
||||
|
||||
@classmethod
|
||||
def KOT(cls):
|
||||
def KOT(cls) -> int:
|
||||
return 0
|
||||
|
||||
@classmethod
|
||||
def REGULAR_BILL(cls):
|
||||
def REGULAR_BILL(cls) -> int:
|
||||
return 1
|
||||
|
||||
@classmethod
|
||||
def NO_CHARGE(cls):
|
||||
def NO_CHARGE(cls) -> int:
|
||||
return 2
|
||||
|
||||
@classmethod
|
||||
def STAFF(cls):
|
||||
def STAFF(cls) -> int:
|
||||
return 4
|
||||
|
||||
@classmethod
|
||||
def VOID(cls):
|
||||
def VOID(cls) -> int:
|
||||
return 8
|
||||
@@ -31,8 +31,9 @@ class Reprint:
|
||||
user: Mapped["User"] = relationship(backref="reprints")
|
||||
voucher: Mapped["Voucher"] = relationship(back_populates="reprints")
|
||||
|
||||
def __init__(self, voucher_id=None, user_id=None, id_=None):
|
||||
self.id = id_
|
||||
def __init__(self, voucher_id: uuid.UUID, user_id: uuid.UUID, id_: uuid.UUID | None = None):
|
||||
if id_ is not None:
|
||||
self.id = id_
|
||||
self.date = datetime.now(UTC).replace(tzinfo=None)
|
||||
self.voucher_id = voucher_id
|
||||
self.user_id = user_id
|
||||
@@ -22,10 +22,11 @@ class Role:
|
||||
|
||||
permissions: Mapped[list["Permission"]] = relationship(
|
||||
"Permission",
|
||||
secondary=RolePermission.__table__, # type: ignore[attr-defined]
|
||||
secondary=RolePermission.__table__,
|
||||
back_populates="roles",
|
||||
)
|
||||
|
||||
def __init__(self, name=None, id_=None):
|
||||
def __init__(self, name: str, id_: uuid.UUID | None = None):
|
||||
self.name = name
|
||||
self.id = id_
|
||||
if id_ is not None:
|
||||
self.id = id_
|
||||
@@ -26,12 +26,13 @@ class SaleCategory:
|
||||
tax: Mapped["Tax"] = relationship(back_populates="sale_categories")
|
||||
products: Mapped[list["ProductVersion"]] = relationship(back_populates="sale_category")
|
||||
|
||||
def __init__(self, name, discount_limit=None, tax_id=False, id_=None):
|
||||
def __init__(self, name: str, discount_limit: Decimal, tax_id: uuid.UUID, id_: uuid.UUID | None = None):
|
||||
self.name = name
|
||||
self.discount_limit = discount_limit if discount_limit is not None else 1
|
||||
self.discount_limit = discount_limit
|
||||
self.tax_id = tax_id
|
||||
self.id = id_
|
||||
if id_ is not None:
|
||||
self.id = id_
|
||||
|
||||
@classmethod
|
||||
def cash_charges(cls):
|
||||
def cash_charges(cls) -> uuid.UUID:
|
||||
return uuid.UUID("f3d6441a-7018-4454-9704-6b99db9333c7")
|
||||
@@ -22,11 +22,12 @@ class Section:
|
||||
|
||||
devices: Mapped[list["Device"]] = relationship(back_populates="section")
|
||||
|
||||
def __init__(self, name=None, is_fixture=None, id_=None):
|
||||
self.id = id_
|
||||
def __init__(self, name: str, is_fixture: bool = False, id_: uuid.UUID | None = None):
|
||||
if id_ is not None:
|
||||
self.id = id_
|
||||
self.name = name
|
||||
self.is_fixture = is_fixture
|
||||
|
||||
@classmethod
|
||||
def main(cls):
|
||||
def main(cls) -> uuid.UUID:
|
||||
return uuid.UUID("3f13f6e7-dc76-4fca-8fdb-b2bbf29b35df")
|
||||
@@ -20,7 +20,7 @@ class SectionPrinter:
|
||||
__table_args__ = (UniqueConstraint("sale_category_id", "section_id"),)
|
||||
|
||||
id: Mapped[uuid.UUID] = mapped_column(Uuid, primary_key=True, server_default=text("gen_random_uuid()"))
|
||||
sale_category_id: Mapped[uuid.UUID] = mapped_column(Uuid, ForeignKey("sale_categories.id"), nullable=True)
|
||||
sale_category_id: Mapped[uuid.UUID | None] = mapped_column(Uuid, ForeignKey("sale_categories.id"), nullable=True)
|
||||
section_id: Mapped[uuid.UUID] = mapped_column(Uuid, ForeignKey("sections.id"), nullable=False)
|
||||
printer_id: Mapped[uuid.UUID] = mapped_column(Uuid, ForeignKey("printers.id"), nullable=False)
|
||||
copies: Mapped[int] = mapped_column(Integer, nullable=False)
|
||||
@@ -31,13 +31,14 @@ class SectionPrinter:
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
sale_category_id=None,
|
||||
section_id=None,
|
||||
printer_id=None,
|
||||
copies=None,
|
||||
id_=None,
|
||||
sale_category_id: uuid.UUID | None,
|
||||
section_id: uuid.UUID,
|
||||
printer_id: uuid.UUID,
|
||||
copies: int,
|
||||
id_: uuid.UUID | None = None,
|
||||
):
|
||||
self.id = id_
|
||||
if id_ is not None:
|
||||
self.id = id_
|
||||
self.sale_category_id = sale_category_id
|
||||
self.section_id = section_id
|
||||
self.printer_id = printer_id
|
||||
|
||||
@@ -18,7 +18,15 @@ class SettleOption:
|
||||
has_reason: Mapped[bool] = mapped_column(Boolean, nullable=False, server_default=expression.false())
|
||||
is_fixture: Mapped[bool] = mapped_column(Boolean, nullable=False, server_default=expression.false())
|
||||
|
||||
def __init__(self, name=None, voucher_type=None, reporting_level=None, has_reason=None, is_fixture=None, id_=None):
|
||||
def __init__(
|
||||
self,
|
||||
id_: int,
|
||||
name: str,
|
||||
voucher_type: VoucherType,
|
||||
reporting_level: ReportingLevel,
|
||||
has_reason: bool,
|
||||
is_fixture: bool = False,
|
||||
):
|
||||
self.id = id_
|
||||
self.name = name
|
||||
self.voucher_type = voucher_type
|
||||
@@ -27,21 +35,21 @@ class SettleOption:
|
||||
self.is_fixture = is_fixture
|
||||
|
||||
@classmethod
|
||||
def UNSETTLED(cls):
|
||||
def UNSETTLED(cls) -> int:
|
||||
return 1
|
||||
|
||||
@classmethod
|
||||
def ROUND_OFF(cls):
|
||||
def ROUND_OFF(cls) -> int:
|
||||
return 7
|
||||
|
||||
@classmethod
|
||||
def AMOUNT(cls):
|
||||
def AMOUNT(cls) -> int:
|
||||
return 8
|
||||
|
||||
@classmethod
|
||||
def VOID(cls):
|
||||
def VOID(cls) -> int:
|
||||
return 9
|
||||
|
||||
@classmethod
|
||||
def CANCEL(cls):
|
||||
def CANCEL(cls) -> int:
|
||||
return 12
|
||||
@@ -32,8 +32,9 @@ class Settlement:
|
||||
settle_option: Mapped["SettleOption"] = relationship("SettleOption")
|
||||
voucher: Mapped["Voucher"] = relationship(back_populates="settlements")
|
||||
|
||||
def __init__(self, voucher_id=None, settled=None, amount=None, id_=None):
|
||||
self.id = id_
|
||||
def __init__(self, voucher_id: uuid.UUID, settled: int, amount: Decimal, id_: uuid.UUID | None = None):
|
||||
if id_ is not None:
|
||||
self.id = id_
|
||||
self.voucher_id = voucher_id
|
||||
self.settled = settled
|
||||
self.amount = amount
|
||||
@@ -29,9 +29,12 @@ class Tax:
|
||||
inventories: Mapped[list["Inventory"]] = relationship(back_populates="tax")
|
||||
regime: Mapped["Regime"] = relationship(back_populates="taxes")
|
||||
|
||||
def __init__(self, name=None, rate=None, regime_id=None, is_fixture=False, id_=None):
|
||||
def __init__(
|
||||
self, name: str, rate: Decimal, regime_id: int, is_fixture: bool = False, id_: uuid.UUID | None = None
|
||||
):
|
||||
self.name = name
|
||||
self.rate = rate
|
||||
self.regime_id = regime_id
|
||||
self.is_fixture = is_fixture
|
||||
self.id = id_
|
||||
if id_ is not None:
|
||||
self.id = id_
|
||||
@@ -29,29 +29,36 @@ class User:
|
||||
roles: Mapped[list[Role]] = relationship(
|
||||
"Role",
|
||||
secondary=UserRole.__table__,
|
||||
order_by="Role.name", # type: ignore[attr-defined]
|
||||
order_by="Role.name",
|
||||
)
|
||||
login_history: Mapped[list[LoginHistory]] = relationship(order_by=desc(LoginHistory.date), back_populates="user")
|
||||
|
||||
Index("uq_users_name", func.lower(name), unique=True)
|
||||
|
||||
@hybrid_property
|
||||
def password(self):
|
||||
def password(self) -> str:
|
||||
return self._password
|
||||
|
||||
@password.inplace.setter
|
||||
def _password_setter(self, value: str) -> None:
|
||||
self._password = encrypt(value)
|
||||
|
||||
def __init__(self, name=None, password=None, locked_out=None, id_=None):
|
||||
def __init__(
|
||||
self,
|
||||
name: str,
|
||||
password: str,
|
||||
locked_out: bool,
|
||||
id_: uuid.UUID | None = None,
|
||||
):
|
||||
self.name = name
|
||||
self.password = password
|
||||
self.locked_out = locked_out
|
||||
self.id = id_
|
||||
if id_ is not None:
|
||||
self.id = id_
|
||||
|
||||
@classmethod
|
||||
def auth(cls, name: str, password: str, db: Session) -> User | None:
|
||||
if password is None:
|
||||
if not password:
|
||||
return None
|
||||
user = db.execute(select(User).where(User.name.ilike(name))).scalars().one_or_none()
|
||||
if not user:
|
||||
@@ -62,5 +69,5 @@ class User:
|
||||
return user
|
||||
|
||||
|
||||
def encrypt(val):
|
||||
def encrypt(val: str) -> str:
|
||||
return md5(val.encode("utf-8") + b"v2").hexdigest()
|
||||
@@ -1,6 +1,7 @@
|
||||
import uuid
|
||||
|
||||
from datetime import datetime
|
||||
from decimal import Decimal
|
||||
from typing import TYPE_CHECKING, Optional
|
||||
|
||||
from sqlalchemy import DateTime, Enum, ForeignKey, Integer, Text, Uuid, text
|
||||
@@ -37,8 +38,8 @@ class Voucher:
|
||||
nullable=False,
|
||||
)
|
||||
customer_id: Mapped[uuid.UUID | None] = mapped_column(Uuid, ForeignKey("customers.id"), nullable=True)
|
||||
narration: Mapped[str] = mapped_column(Text, nullable=True)
|
||||
reason: Mapped[str] = mapped_column(Text, nullable=True)
|
||||
narration: Mapped[str | None] = mapped_column(Text, nullable=True)
|
||||
reason: Mapped[str | None] = mapped_column(Text, nullable=True)
|
||||
voucher_type: Mapped[VoucherType] = mapped_column(Enum(VoucherType), nullable=False)
|
||||
user_id: Mapped[uuid.UUID] = mapped_column(Uuid, ForeignKey("users.id"), nullable=False)
|
||||
|
||||
@@ -67,13 +68,13 @@ class Voucher:
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
date,
|
||||
pax,
|
||||
kot_id,
|
||||
food_table_id,
|
||||
customer_id,
|
||||
voucher_type,
|
||||
user_id,
|
||||
date: datetime,
|
||||
pax: int,
|
||||
kot_id: int,
|
||||
food_table_id: uuid.UUID,
|
||||
customer_id: uuid.UUID | None,
|
||||
voucher_type: VoucherType,
|
||||
user_id: uuid.UUID,
|
||||
):
|
||||
self.date = date
|
||||
self.pax = pax
|
||||
@@ -87,5 +88,5 @@ class Voucher:
|
||||
self.user_id = user_id
|
||||
|
||||
@property
|
||||
def amount(self):
|
||||
return round(sum(i.amount for k in self.kots for i in k.inventories), 2)
|
||||
def amount(self) -> Decimal:
|
||||
return round(sum([i.amount for k in self.kots for i in k.inventories], Decimal(0)), 2)
|
||||
@@ -23,7 +23,7 @@ from ..models.voucher_type import VoucherType
|
||||
from . import currency_format, format_no_decimals
|
||||
|
||||
|
||||
def print_bill(voucher_id: uuid.UUID, db: Session):
|
||||
def print_bill(voucher_id: uuid.UUID, db: Session) -> None:
|
||||
locale.setlocale(locale.LC_MONETARY, "en_IN")
|
||||
voucher: Voucher = db.execute(select(Voucher).where(Voucher.id == voucher_id)).scalar_one()
|
||||
|
||||
@@ -83,6 +83,9 @@ def get_inventories(voucher: Voucher) -> list[Inventory]:
|
||||
tax_rate=i.tax_rate,
|
||||
product=i.product,
|
||||
tax=i.tax,
|
||||
kot_id=i.kot_id,
|
||||
tax_id=i.tax_id,
|
||||
sort_order=i.sort_order,
|
||||
)
|
||||
return list([item for item in items_dict.values() if item.quantity != 0])
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ from ..schemas.cashier_report import CashierReport
|
||||
from . import currency_format
|
||||
|
||||
|
||||
def print_cashier_report(report: CashierReport, device_id: uuid.UUID, db: Session):
|
||||
def print_cashier_report(report: CashierReport, device_id: uuid.UUID, db: Session) -> None:
|
||||
locale.setlocale(locale.LC_MONETARY, "en_IN")
|
||||
data = design_cashier_report(report)
|
||||
section_id = db.execute(select(Device.section_id).where(Device.id == device_id)).scalar_one()
|
||||
@@ -38,7 +38,7 @@ def print_cashier_report(report: CashierReport, device_id: uuid.UUID, db: Sessio
|
||||
loop.close()
|
||||
|
||||
|
||||
def design_cashier_report(report: CashierReport):
|
||||
def design_cashier_report(report: CashierReport) -> str:
|
||||
now = datetime.now() + timedelta(minutes=settings.TIMEZONE_OFFSET_MINUTES)
|
||||
s = f"{report.cashier.name} Checkout By {report.user.name} @ {now:%d-%b-%Y %H:%M}".center(42)
|
||||
s += "\n\r" + "-" * 42
|
||||
|
||||
@@ -14,7 +14,7 @@ from ..schemas.discount_report import DiscountReport
|
||||
from . import currency_format
|
||||
|
||||
|
||||
def print_discount_report(report: DiscountReport, device_id: uuid.UUID, db: Session):
|
||||
def print_discount_report(report: DiscountReport, device_id: uuid.UUID, db: Session) -> None:
|
||||
locale.setlocale(locale.LC_MONETARY, "en_IN")
|
||||
data = design_discount_report(report)
|
||||
section_id = db.execute(select(Device.section_id).where(Device.id == device_id)).scalar_one()
|
||||
@@ -35,7 +35,7 @@ def print_discount_report(report: DiscountReport, device_id: uuid.UUID, db: Sess
|
||||
loop.close()
|
||||
|
||||
|
||||
def design_discount_report(report: DiscountReport):
|
||||
def design_discount_report(report: DiscountReport) -> str:
|
||||
s = f"{report.start_date:%d-%b-%Y} To {report.finish_date:%d-%b-%Y}".center(42)
|
||||
s += "\n\r" + "-" * 42
|
||||
s += f"\n\r{'Name': <29.29} {'Amount': >12.12}"
|
||||
|
||||
@@ -64,7 +64,7 @@ def design_kot(voucher: Voucher, kot: Kot, items: list[Inventory], copy_number:
|
||||
return s
|
||||
|
||||
|
||||
def print_kot(voucher_id: uuid.UUID, db: Session):
|
||||
def print_kot(voucher_id: uuid.UUID, db: Session) -> None:
|
||||
voucher: Voucher = db.execute(select(Voucher).where(Voucher.id == voucher_id)).scalar_one()
|
||||
my_hash: dict[tuple[uuid.UUID, int], tuple[Printer, list[Any]]] = {}
|
||||
kot: Kot = voucher.kots[-1]
|
||||
|
||||
@@ -13,9 +13,10 @@ from ..core.config import settings
|
||||
from ..models.device import Device
|
||||
from ..models.printer import Printer
|
||||
from ..models.section_printer import SectionPrinter
|
||||
from ..schemas.product_sale_report import ProductSaleReport
|
||||
|
||||
|
||||
def print_product_sale_report(report, device_id: uuid.UUID, db: Session):
|
||||
def print_product_sale_report(report: ProductSaleReport, device_id: uuid.UUID, db: Session) -> None:
|
||||
locale.setlocale(locale.LC_MONETARY, "en_IN")
|
||||
data = design_product_sale_report(report)
|
||||
section_id = db.execute(select(Device.section_id).where(Device.id == device_id)).scalar_one()
|
||||
@@ -36,22 +37,22 @@ def print_product_sale_report(report, device_id: uuid.UUID, db: Session):
|
||||
loop.close()
|
||||
|
||||
|
||||
def design_product_sale_report(report):
|
||||
def design_product_sale_report(report: ProductSaleReport) -> str:
|
||||
now = datetime.now() + timedelta(minutes=settings.TIMEZONE_OFFSET_MINUTES)
|
||||
s = f"{report['userName']} @ {now:%d-%b-%Y %H:%M}".center(42)
|
||||
s = f"{report.user.name} @ {now:%d-%b-%Y %H:%M}".center(42)
|
||||
s += "\n\r" + "-" * 42
|
||||
s += f"\n\r{report['startDate']} To {report['finishDate']}".center(42)
|
||||
s += f"\n\r{report.start_date} To {report.finish_date}".center(42)
|
||||
s += "\n\r" + "-" * 42
|
||||
s += "\n\rUnbilled Sale NC Staff Void"
|
||||
for item in report["amounts"]:
|
||||
for item in report.amounts:
|
||||
s += (
|
||||
f"\n\r{item['name']: ^42.42}"
|
||||
f"\n\r{item.name: ^42.42}"
|
||||
f"\n\r"
|
||||
+ (f"{item['kot']: >7.2f} " if "kot" in item else " ")
|
||||
+ (f"{item['regularBill']: >7.2f} " if "regularBill" in item else " ")
|
||||
+ (f"{item['noCharge']: >7.2f} " if "noCharge" in item else " ")
|
||||
+ (f"{item['staff']: >7.2f} " if "staff" in item else " ")
|
||||
+ (f"{item['void']: >7.2f}" if "void" in item else " ")
|
||||
+ (f"{item['kot']: >7.2f} " if item["kot"] else " ")
|
||||
+ (f"{item['regularBill']: >7.2f} " if item["regularBill"] else " ")
|
||||
+ (f"{item['noCharge']: >7.2f} " if item["noCharge"] else " ")
|
||||
+ (f"{item['staff']: >7.2f} " if item["staff"] else " ")
|
||||
+ (f"{item['void']: >7.2f}" if item["void"] else " ")
|
||||
)
|
||||
s += "\n\r" + "=" * 42
|
||||
return s
|
||||
@@ -17,7 +17,7 @@ from ..schemas.sale_report import SaleReport
|
||||
from . import currency_format
|
||||
|
||||
|
||||
def print_sale_report(report: SaleReport, device_id: uuid.UUID, db: Session):
|
||||
def print_sale_report(report: SaleReport, device_id: uuid.UUID, db: Session) -> None:
|
||||
locale.setlocale(locale.LC_MONETARY, "en_IN")
|
||||
data = design_sale_report(report)
|
||||
section_id = db.execute(select(Device.section_id).where(Device.id == device_id)).scalar_one()
|
||||
@@ -38,7 +38,7 @@ def print_sale_report(report: SaleReport, device_id: uuid.UUID, db: Session):
|
||||
loop.close()
|
||||
|
||||
|
||||
def design_sale_report(report: SaleReport):
|
||||
def design_sale_report(report: SaleReport) -> str:
|
||||
now = datetime.now() + timedelta(minutes=settings.TIMEZONE_OFFSET_MINUTES)
|
||||
s = f"{report.user.name} @ {now:%d-%b-%Y %H:%M}".center(42)
|
||||
s += "\n\r" + "-" * 42
|
||||
|
||||
@@ -40,13 +40,12 @@ def update_route(
|
||||
def delete_route(
|
||||
id_: uuid.UUID,
|
||||
user: UserToken = Security(get_user, scopes=["add-devices"]),
|
||||
):
|
||||
) -> None:
|
||||
try:
|
||||
with SessionFuture() as db:
|
||||
db.execute(delete(LoginHistory).where(LoginHistory.device_id == id_))
|
||||
db.execute(delete(Device).where(Device.id == id_))
|
||||
db.commit()
|
||||
return {}
|
||||
except SQLAlchemyError as e:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
||||
@@ -55,7 +54,7 @@ def delete_route(
|
||||
|
||||
|
||||
@router.get("/list", response_model=list[schemas.Device])
|
||||
def show_list(user: UserToken = Depends(get_user)):
|
||||
def show_list(user: UserToken = Depends(get_user)) -> list[schemas.Device]:
|
||||
with SessionFuture() as db:
|
||||
return [device_info(item) for item in db.execute(select(Device).order_by(Device.name)).scalars().all()]
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ def login_for_access_token(
|
||||
response: Response,
|
||||
form_data: OAuth2PasswordRequestForm = Depends(),
|
||||
device_id: uuid.UUID | None = Cookie(None),
|
||||
):
|
||||
) -> Token | JSONResponse:
|
||||
with SessionFuture() as db:
|
||||
user = authenticate_user(form_data.username.strip(), form_data.password.strip(), db)
|
||||
if not user:
|
||||
@@ -76,11 +76,11 @@ def login_for_access_token(
|
||||
},
|
||||
expires_delta=access_token_expires,
|
||||
)
|
||||
return {"access_token": access_token, "token_type": "bearer"}
|
||||
return Token(access_token=access_token, token_type="bearer")
|
||||
|
||||
|
||||
@router.post("/refresh", response_model=Token)
|
||||
def refresh_token(user: UserToken = Security(get_current_active_user)):
|
||||
def refresh_token(user: UserToken = Security(get_current_active_user)) -> Token:
|
||||
access_token_expires = timedelta(minutes=settings.JWT_TOKEN_EXPIRE_MINUTES)
|
||||
access_token = create_access_token(
|
||||
data={
|
||||
@@ -92,4 +92,4 @@ def refresh_token(user: UserToken = Security(get_current_active_user)):
|
||||
},
|
||||
expires_delta=access_token_expires,
|
||||
)
|
||||
return {"access_token": access_token, "token_type": "bearer"}
|
||||
return Token(access_token=access_token, token_type="bearer")
|
||||
@@ -280,7 +280,9 @@ def modifier_category_blank(date_: date, db: Session) -> schemas.ModifierCategor
|
||||
)
|
||||
|
||||
|
||||
def add_products(modifier_category: ModifierCategory, menu_categories: list[schemas.MenuCategoryLink], db: Session):
|
||||
def add_products(
|
||||
modifier_category: ModifierCategory, menu_categories: list[schemas.MenuCategoryLink], db: Session
|
||||
) -> None:
|
||||
for mc in menu_categories:
|
||||
for p in mc.products:
|
||||
old = next((x for x in modifier_category.products if x.id == p.id_), None)
|
||||
|
||||
@@ -83,7 +83,7 @@ def show_blank(
|
||||
|
||||
|
||||
@router.get("/list", response_model=list[schemas.Printer])
|
||||
def show_list(user: UserToken = Depends(get_user)):
|
||||
def show_list(user: UserToken = Depends(get_user)) -> list[schemas.Printer]:
|
||||
with SessionFuture() as db:
|
||||
return [printer_info(item) for item in db.execute(select(Printer).order_by(Printer.name)).scalars().all()]
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ def sort_order(
|
||||
data: list[schemas.Product],
|
||||
date_: date = Depends(effective_date),
|
||||
user: UserToken = Security(get_user, scopes=["products"]),
|
||||
):
|
||||
) -> list[schemas.Product]:
|
||||
try:
|
||||
with SessionFuture() as db:
|
||||
indexes: dict[uuid.UUID, int] = {}
|
||||
@@ -104,7 +104,7 @@ def save(
|
||||
)
|
||||
|
||||
|
||||
def add_modifiers(product_id: uuid.UUID, menu_category_id: uuid.UUID, date_: date, db: Session):
|
||||
def add_modifiers(product_id: uuid.UUID, menu_category_id: uuid.UUID, date_: date, db: Session) -> None:
|
||||
products_in_category = db.execute(
|
||||
select(count(ProductVersion.id)).where(
|
||||
and_(
|
||||
|
||||
@@ -21,7 +21,7 @@ def report_finish_date(f: str | None = None) -> date:
|
||||
)
|
||||
|
||||
|
||||
def check_audit_permission(start_date: date, user_permissions: list[str]):
|
||||
def check_audit_permission(start_date: date, user_permissions: list[str]) -> None:
|
||||
today = (datetime.now(UTC).replace(tzinfo=None) + timedelta(minutes=settings.TIMEZONE_OFFSET_MINUTES)).date()
|
||||
if (today - start_date).days > 5 and "audit" not in user_permissions:
|
||||
raise HTTPException(
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
from datetime import date, timedelta
|
||||
from operator import or_
|
||||
from typing import Any
|
||||
|
||||
from fastapi import APIRouter, Depends, Security
|
||||
from sqlalchemy import and_
|
||||
@@ -15,6 +14,7 @@ from ...models.product import Product
|
||||
from ...models.product_version import ProductVersion
|
||||
from ...models.voucher import Voucher
|
||||
from ...models.voucher_type import VoucherType
|
||||
from ...schemas.beer_consumption_report import BeerConsumptionReport, BeerConsumptionReportItem
|
||||
from ...schemas.user_token import UserToken
|
||||
from . import check_audit_permission, report_finish_date, report_start_date
|
||||
|
||||
@@ -22,7 +22,7 @@ from . import check_audit_permission, report_finish_date, report_start_date
|
||||
router = APIRouter()
|
||||
|
||||
|
||||
@router.get("")
|
||||
@router.get("", response_model=BeerConsumptionReport)
|
||||
def beer_consumption(
|
||||
start_date: date = Depends(report_start_date),
|
||||
finish_date: date = Depends(report_finish_date),
|
||||
@@ -31,7 +31,7 @@ def beer_consumption(
|
||||
st: bool | None = True,
|
||||
n: bool | None = True,
|
||||
user: UserToken = Security(get_user, scopes=["beer-sale-report"]),
|
||||
):
|
||||
) -> BeerConsumptionReport:
|
||||
check_audit_permission(start_date, user.permissions)
|
||||
day = func.date_trunc(
|
||||
"day", Voucher.date + timedelta(minutes=settings.NEW_DAY_OFFSET_MINUTES - settings.TIMEZONE_OFFSET_MINUTES)
|
||||
@@ -63,7 +63,7 @@ def beer_consumption(
|
||||
query = query.where(Inventory.is_happy_hour == h)
|
||||
if r is False and h is not False:
|
||||
query = query.where(Inventory.is_happy_hour != r)
|
||||
vt = []
|
||||
vt: list[VoucherType] = []
|
||||
if h is True or r is True:
|
||||
vt.append(VoucherType.REGULAR_BILL)
|
||||
if st is True:
|
||||
@@ -78,23 +78,25 @@ def beer_consumption(
|
||||
.having(sum_ != 0)
|
||||
.order_by(day, ProductVersion.name)
|
||||
).all()
|
||||
headers = []
|
||||
data: list[Any] = []
|
||||
headers: list[str] = []
|
||||
data: list[BeerConsumptionReportItem] = []
|
||||
for date_, name, quantity in list_:
|
||||
if name not in headers:
|
||||
headers.append(name)
|
||||
old = [d for d in data if d["date"] == date_.strftime("%d-%b-%Y")]
|
||||
if len(old):
|
||||
old[0][name] = quantity
|
||||
old = next((d for d in data if d["date"] == date_.strftime("%d-%b-%Y")), None)
|
||||
if old:
|
||||
old[name] = quantity
|
||||
else:
|
||||
data.append({"date": date_.strftime("%d-%b-%Y"), name: quantity})
|
||||
return {
|
||||
"startDate": start_date.strftime("%d-%b-%Y"),
|
||||
"finishDate": finish_date.strftime("%d-%b-%Y"),
|
||||
"regular": r,
|
||||
"happy": h,
|
||||
"staff": st,
|
||||
"nc": n,
|
||||
"headers": headers,
|
||||
"data": data,
|
||||
}
|
||||
item = BeerConsumptionReportItem(date_=date_)
|
||||
item[name] = quantity
|
||||
data.append(item)
|
||||
return BeerConsumptionReport(
|
||||
start_date=start_date,
|
||||
finish_date=finish_date,
|
||||
regular=r,
|
||||
happy=h,
|
||||
staff=st,
|
||||
nc=n,
|
||||
headers=headers,
|
||||
data=data,
|
||||
)
|
||||
@@ -32,17 +32,18 @@ def menu_engineering_report_view(
|
||||
start_date: date = Depends(report_start_date),
|
||||
finish_date: date = Depends(report_finish_date),
|
||||
user: UserToken = Security(get_user, scopes=["product-sale-report"]),
|
||||
):
|
||||
) -> MeReport:
|
||||
check_audit_permission(start_date, user.permissions)
|
||||
with SessionFuture() as db:
|
||||
return MeReport(
|
||||
user_name=user.name,
|
||||
start_date=start_date,
|
||||
finish_date=finish_date,
|
||||
amounts=menu_engineering_report(start_date, finish_date, db),
|
||||
)
|
||||
|
||||
|
||||
def menu_engineering_report(start_date: date, finish_date: date, db: Session):
|
||||
def menu_engineering_report(start_date: date, finish_date: date, db: Session) -> list[MeItem]:
|
||||
day = func.date_trunc(
|
||||
"day", Voucher.date + timedelta(minutes=settings.NEW_DAY_OFFSET_MINUTES - settings.TIMEZONE_OFFSET_MINUTES)
|
||||
).label("day")
|
||||
@@ -134,11 +135,11 @@ def print_report(
|
||||
) -> bool:
|
||||
check_audit_permission(start_date, user.permissions)
|
||||
with SessionFuture() as db:
|
||||
report = {
|
||||
"userName": user.name,
|
||||
"startDate": start_date.strftime("%d-%b-%Y"),
|
||||
"finishDate": finish_date.strftime("%d-%b-%Y"),
|
||||
"amounts": menu_engineering_report(start_date, finish_date, db),
|
||||
}
|
||||
report = MeReport(
|
||||
user_name=user.name,
|
||||
start_date=start_date,
|
||||
finish_date=finish_date,
|
||||
amounts=menu_engineering_report(start_date, finish_date, db),
|
||||
)
|
||||
print_product_sale_report(report, device_id, db)
|
||||
return True
|
||||
@@ -1,7 +1,7 @@
|
||||
import uuid
|
||||
|
||||
from datetime import date, timedelta
|
||||
from typing import Annotated, Any
|
||||
from typing import Annotated
|
||||
|
||||
from fastapi import APIRouter, Cookie, Depends, Query, Security
|
||||
from sqlalchemy import and_, func, or_, select
|
||||
@@ -21,6 +21,7 @@ from ...models.voucher import Voucher
|
||||
from ...models.voucher_type import VoucherType
|
||||
from ...printing.product_sale_report import print_product_sale_report
|
||||
from ...schemas import to_camel
|
||||
from ...schemas.product_sale_report import ProductSaleReport, ProductSaleReportItem, UserLink
|
||||
from ...schemas.user_token import UserToken
|
||||
from . import check_audit_permission, report_finish_date, report_start_date
|
||||
|
||||
@@ -28,24 +29,27 @@ from . import check_audit_permission, report_finish_date, report_start_date
|
||||
router = APIRouter()
|
||||
|
||||
|
||||
@router.get("")
|
||||
@router.get("", response_model=ProductSaleReport)
|
||||
def product_sale_report_view(
|
||||
start_date: date = Depends(report_start_date),
|
||||
finish_date: date = Depends(report_finish_date),
|
||||
section: Annotated[uuid.UUID | None, Query()] = None,
|
||||
user: UserToken = Security(get_user, scopes=["product-sale-report"]),
|
||||
):
|
||||
) -> ProductSaleReport:
|
||||
check_audit_permission(start_date, user.permissions)
|
||||
with SessionFuture() as db:
|
||||
return {
|
||||
"startDate": start_date.strftime("%d-%b-%Y"),
|
||||
"finishDate": finish_date.strftime("%d-%b-%Y"),
|
||||
"sectionId": str(section) if section is not None else None,
|
||||
"amounts": product_sale_report(start_date, finish_date, section, db),
|
||||
}
|
||||
return ProductSaleReport(
|
||||
start_date=start_date,
|
||||
finish_date=finish_date,
|
||||
section_id=section,
|
||||
user=UserLink(id_=user.id_, name=user.name),
|
||||
amounts=product_sale_report(start_date, finish_date, section, db),
|
||||
)
|
||||
|
||||
|
||||
def product_sale_report(start_date: date, finish_date: date, id_: uuid.UUID | None, db: Session):
|
||||
def product_sale_report(
|
||||
start_date: date, finish_date: date, id_: uuid.UUID | None, db: Session
|
||||
) -> list[ProductSaleReportItem]:
|
||||
day = func.date_trunc(
|
||||
"day", Voucher.date + timedelta(minutes=settings.NEW_DAY_OFFSET_MINUTES - settings.TIMEZONE_OFFSET_MINUTES)
|
||||
).label("day")
|
||||
@@ -91,23 +95,16 @@ def product_sale_report(start_date: date, finish_date: date, id_: uuid.UUID | No
|
||||
Inventory.is_happy_hour,
|
||||
).order_by(SaleCategory.name, MenuCategory.name, ProductVersion.full_name)
|
||||
list_ = db.execute(query).all()
|
||||
info: list[Any] = []
|
||||
for id_, name, v_type, hh, quantity in list_:
|
||||
info: list[ProductSaleReportItem] = []
|
||||
for product_version_id, name, v_type, hh, quantity in list_:
|
||||
type_ = to_camel(VoucherType(v_type).name)
|
||||
old = [i for i in info if i["id"] == id_ and i["isHappyHour"] == hh]
|
||||
if len(old):
|
||||
if type_ not in old[0]:
|
||||
old[0][type_] = 0
|
||||
old[0][type_] += quantity
|
||||
old = next((i for i in info if i.product_version_id == product_version_id and i.is_happy_hour == hh), None)
|
||||
if old:
|
||||
old[type_] = old[type_] + quantity
|
||||
else:
|
||||
info.append(
|
||||
{
|
||||
"id": id_,
|
||||
"name": "H H " + name if hh else name,
|
||||
"isHappyHour": hh,
|
||||
type_: quantity,
|
||||
}
|
||||
)
|
||||
item = ProductSaleReportItem(product_version_id=product_version_id, name=name, is_happy_hour=hh)
|
||||
item[type_] = quantity
|
||||
info.append(item)
|
||||
return info
|
||||
|
||||
|
||||
@@ -121,12 +118,12 @@ def print_report(
|
||||
) -> bool:
|
||||
check_audit_permission(start_date, user.permissions)
|
||||
with SessionFuture() as db:
|
||||
report = {
|
||||
"userName": user.name,
|
||||
"startDate": start_date.strftime("%d-%b-%Y"),
|
||||
"finishDate": finish_date.strftime("%d-%b-%Y"),
|
||||
"sectionId": str(section) if section is not None else None,
|
||||
"amounts": product_sale_report(start_date, finish_date, section, db),
|
||||
}
|
||||
report = ProductSaleReport(
|
||||
user=UserLink(id_=user.id_, name=user.name),
|
||||
start_date=start_date,
|
||||
finish_date=finish_date,
|
||||
section_id=section,
|
||||
amounts=product_sale_report(start_date, finish_date, section, db),
|
||||
)
|
||||
print_product_sale_report(report, device_id, db)
|
||||
return True
|
||||
@@ -138,7 +138,7 @@ def role_blank(db: Session) -> schemas.RoleBlank:
|
||||
)
|
||||
|
||||
|
||||
def add_permissions(role: Role, permissions: list[schemas.PermissionItem], db: Session):
|
||||
def add_permissions(role: Role, permissions: list[schemas.PermissionItem], db: Session) -> None:
|
||||
for permission in permissions:
|
||||
gp = next((p for p in role.permissions if p.id == permission.id_), None)
|
||||
if permission.enabled and gp is None:
|
||||
|
||||
@@ -93,7 +93,7 @@ def show_blank(
|
||||
|
||||
|
||||
@router.get("/list", response_model=list[schemas.Section])
|
||||
def show_list(user: UserToken = Depends(get_user)):
|
||||
def show_list(user: UserToken = Depends(get_user)) -> list[schemas.Section]:
|
||||
with SessionFuture() as db:
|
||||
return [section_info(item) for item in db.execute(select(Section).order_by(Section.name)).scalars().all()]
|
||||
|
||||
|
||||
@@ -81,7 +81,7 @@ def update_route(
|
||||
def delete_route(
|
||||
id_: int,
|
||||
user: UserToken = Security(get_user, scopes=["owner"]),
|
||||
):
|
||||
) -> None:
|
||||
with SessionFuture() as db:
|
||||
item: SettleOption = db.execute(select(SettleOption).where(SettleOption.id == id_)).scalar_one()
|
||||
if item is None:
|
||||
@@ -104,7 +104,7 @@ def show_blank(
|
||||
|
||||
|
||||
@router.get("/list", response_model=list[schemas.SettleOption])
|
||||
def show_list(user: UserToken = Depends(get_user)):
|
||||
def show_list(user: UserToken = Depends(get_user)) -> list[schemas.SettleOption]:
|
||||
with SessionFuture() as db:
|
||||
return [
|
||||
settle_option_info(item)
|
||||
@@ -113,7 +113,7 @@ def show_list(user: UserToken = Depends(get_user)):
|
||||
|
||||
|
||||
@router.get("/for-type/{vt}", response_model=list[schemas.SettleOption])
|
||||
def show_list_for_type(vt: VoucherType, user: UserToken = Depends(get_user)):
|
||||
def show_list_for_type(vt: VoucherType, user: UserToken = Depends(get_user)) -> list[schemas.SettleOption]:
|
||||
with SessionFuture() as db:
|
||||
return [
|
||||
settle_option_info(item)
|
||||
|
||||
@@ -117,7 +117,7 @@ def show_blank(
|
||||
|
||||
|
||||
@router.get("/list", response_model=list[schemas.Table])
|
||||
def show_list(user: UserToken = Depends(get_user)):
|
||||
def show_list(user: UserToken = Depends(get_user)) -> list[schemas.Table]:
|
||||
with SessionFuture() as db:
|
||||
return [
|
||||
food_table_info(item)
|
||||
|
||||
@@ -76,7 +76,7 @@ def update_route(
|
||||
)
|
||||
|
||||
|
||||
def check_product(old: ProductVersion, data: schemas.Product, db: Session):
|
||||
def check_product(old: ProductVersion, data: schemas.Product, db: Session) -> None:
|
||||
query = select(count(ProductVersion.id)).where(ProductVersion.id != old.id)
|
||||
if data.valid_from is not None:
|
||||
query = query.where(ProductVersion.valid_till >= data.valid_from)
|
||||
@@ -95,7 +95,7 @@ def check_product(old: ProductVersion, data: schemas.Product, db: Session):
|
||||
)
|
||||
|
||||
|
||||
def check_inventories(old: ProductVersion, data: schemas.Product, db: Session):
|
||||
def check_inventories(old: ProductVersion, data: schemas.Product, db: Session) -> None:
|
||||
day = func.date_trunc(
|
||||
"day", Voucher.date + timedelta(minutes=settings.NEW_DAY_OFFSET_MINUTES - settings.TIMEZONE_OFFSET_MINUTES)
|
||||
).label("day")
|
||||
@@ -123,7 +123,7 @@ def check_inventories(old: ProductVersion, data: schemas.Product, db: Session):
|
||||
)
|
||||
|
||||
|
||||
def update_inventories(old: ProductVersion, data: schemas.Product, db: Session):
|
||||
def update_inventories(old: ProductVersion, data: schemas.Product, db: Session) -> None:
|
||||
if old.product_id != data.id_:
|
||||
day = func.date_trunc(
|
||||
"day", Voucher.date + timedelta(minutes=settings.NEW_DAY_OFFSET_MINUTES - settings.TIMEZONE_OFFSET_MINUTES)
|
||||
|
||||
@@ -125,7 +125,7 @@ def save_update_product_prices_id(
|
||||
)
|
||||
|
||||
|
||||
def update_product(id_: uuid.UUID, price: Decimal, date_: date, db: Session):
|
||||
def update_product(id_: uuid.UUID, price: Decimal, date_: date, db: Session) -> None:
|
||||
item: ProductVersion = db.execute(
|
||||
select(ProductVersion).where(
|
||||
and_(
|
||||
|
||||
@@ -91,7 +91,7 @@ def update_route(
|
||||
)
|
||||
|
||||
|
||||
def add_roles(user: User, roles: list[schemas.RoleItem], db: Session):
|
||||
def add_roles(user: User, roles: list[schemas.RoleItem], db: Session) -> None:
|
||||
for role in roles:
|
||||
ug = next((g for g in user.roles if g.id == role.id_), None)
|
||||
if role.enabled and ug is None:
|
||||
@@ -104,7 +104,7 @@ def add_roles(user: User, roles: list[schemas.RoleItem], db: Session):
|
||||
def delete_route(
|
||||
id_: uuid.UUID,
|
||||
user: UserToken = Security(get_user, scopes=["users"]),
|
||||
):
|
||||
) -> None:
|
||||
if id_ == user.id_:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_501_NOT_IMPLEMENTED,
|
||||
|
||||
@@ -23,9 +23,9 @@ from ...schemas import voucher as schemas
|
||||
from ...schemas.receive_payment import ReceivePaymentItem as SettleSchema
|
||||
|
||||
|
||||
def get_tax(tax, voucher_type):
|
||||
def get_tax(tax: Decimal, voucher_type: VoucherType) -> Decimal:
|
||||
if voucher_type in [VoucherType.STAFF, VoucherType.NO_CHARGE]:
|
||||
return 0
|
||||
return Decimal(0)
|
||||
elif voucher_type in [VoucherType.KOT, VoucherType.REGULAR_BILL]:
|
||||
return tax
|
||||
else:
|
||||
@@ -35,7 +35,7 @@ def get_tax(tax, voucher_type):
|
||||
)
|
||||
|
||||
|
||||
def do_update_table(item: Voucher, guest_book: GuestBook | None, db: Session):
|
||||
def do_update_table(item: Voucher, guest_book: GuestBook | None, db: Session) -> None:
|
||||
status_ = OverviewStatus.running if item.voucher_type == VoucherType.KOT else OverviewStatus.printed
|
||||
if item.status is None:
|
||||
item.status = Overview(
|
||||
@@ -54,7 +54,7 @@ def do_update_table(item: Voucher, guest_book: GuestBook | None, db: Session):
|
||||
item.status.guest_book_id = guest_book.id
|
||||
|
||||
|
||||
def check_permissions(item: Voucher | None, voucher_type: VoucherType, permissions: list[str]):
|
||||
def check_permissions(item: Voucher | None, voucher_type: VoucherType, permissions: list[str]) -> None:
|
||||
if voucher_type == VoucherType.KOT and "print-kot" not in permissions:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_403_FORBIDDEN,
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import uuid
|
||||
|
||||
from decimal import Decimal
|
||||
|
||||
from fastapi import APIRouter, HTTPException, Security, status
|
||||
from sqlalchemy import delete, select
|
||||
from sqlalchemy.exc import SQLAlchemyError
|
||||
@@ -24,14 +26,16 @@ def cancel(
|
||||
u: bool, # Update table?
|
||||
reason: str,
|
||||
user: UserToken = Security(get_user, scopes=["void-bill"]),
|
||||
):
|
||||
) -> bool:
|
||||
try:
|
||||
with SessionFuture() as db:
|
||||
item: Voucher = db.execute(select(Voucher).where(Voucher.id == id_)).scalar_one()
|
||||
item.reason = f"{reason}"
|
||||
item.voucher_type = VoucherType.CANCEL
|
||||
do_update_bill_numbers(item, db)
|
||||
do_update_settlements(item, [SettleSchema(id_=SettleOption.CANCEL(), amount=round(item.amount))], db)
|
||||
do_update_settlements(
|
||||
item, [SettleSchema(id_=SettleOption.CANCEL(), amount=Decimal(round(item.amount)))], db
|
||||
)
|
||||
|
||||
if u: # Update table
|
||||
db.execute(delete(Overview).where(Overview.voucher_id == item.id))
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import uuid
|
||||
|
||||
from decimal import Decimal
|
||||
|
||||
from fastapi import APIRouter, HTTPException, Security, status
|
||||
from sqlalchemy import select, update
|
||||
from sqlalchemy.exc import SQLAlchemyError
|
||||
@@ -36,7 +38,7 @@ def change(
|
||||
u: bool, # Update table?
|
||||
g: uuid.UUID | None = None, # Guest book id
|
||||
user: UserToken = Security(get_user, scopes=["edit-printed-bill"]),
|
||||
):
|
||||
) -> None:
|
||||
try:
|
||||
with SessionFuture() as db:
|
||||
old: Voucher = db.execute(select(Voucher).where(Voucher.id == id_)).scalar_one()
|
||||
@@ -73,7 +75,7 @@ def change(
|
||||
)
|
||||
|
||||
|
||||
def reprint_bill(voucher_id: uuid.UUID, user_id: uuid.UUID, db: Session):
|
||||
def reprint_bill(voucher_id: uuid.UUID, user_id: uuid.UUID, db: Session) -> None:
|
||||
item = Reprint(voucher_id=voucher_id, user_id=user_id)
|
||||
db.add(item)
|
||||
|
||||
@@ -95,13 +97,13 @@ def void_and_issue_new_bill(
|
||||
old.reason = f"Bill Discounted or Changed / Old Bill: {old_bill_id} / New Bill: {new_bill_id}."
|
||||
old.voucher_type = VoucherType.VOID
|
||||
do_update_bill_numbers(old, db)
|
||||
do_update_settlements(old, [SettleSchema(id_=SettleOption.VOID(), amount=round(old.amount))], db)
|
||||
do_update_settlements(old, [SettleSchema(id_=SettleOption.VOID(), amount=Decimal(round(old.amount)))], db)
|
||||
|
||||
if update_table:
|
||||
if old.status is None:
|
||||
guest_book_id = None if guest_book is None else guest_book.id
|
||||
item.status = Overview(
|
||||
voucher_id=None,
|
||||
voucher_id=item.id,
|
||||
food_table_id=item.food_table_id,
|
||||
guest_book_id=guest_book_id,
|
||||
status=OverviewStatus.printed,
|
||||
|
||||
@@ -32,7 +32,7 @@ router = APIRouter()
|
||||
def merge_kot(
|
||||
data: schemas.MergeKot,
|
||||
user: UserToken = Security(get_user, scopes=["merge-kots"]),
|
||||
):
|
||||
) -> None:
|
||||
try:
|
||||
with SessionFuture() as db:
|
||||
check_if_voucher_is_unprinted(data.voucher_id, db)
|
||||
@@ -75,7 +75,7 @@ def merge_kot(
|
||||
def move_kot(
|
||||
data: schemas.MoveKot,
|
||||
user: UserToken = Security(get_user, scopes=["move-kot-to-new-table"]),
|
||||
):
|
||||
) -> None:
|
||||
try:
|
||||
with SessionFuture() as db:
|
||||
now = datetime.now(UTC).replace(tzinfo=None)
|
||||
@@ -128,7 +128,7 @@ def move_kot(
|
||||
def move_table(
|
||||
data: schemas.MoveTable,
|
||||
user: UserToken = Security(get_user, scopes=["move-table"]),
|
||||
):
|
||||
) -> None:
|
||||
try:
|
||||
with SessionFuture() as db:
|
||||
db.execute(
|
||||
@@ -147,7 +147,7 @@ def move_table(
|
||||
def merge_table(
|
||||
data: schemas.MergeTable,
|
||||
user: UserToken = Security(get_user, scopes=["merge-tables"]),
|
||||
):
|
||||
) -> None:
|
||||
try:
|
||||
with SessionFuture() as db:
|
||||
check_if_voucher_is_unprinted(data.voucher_id, db)
|
||||
|
||||
@@ -24,7 +24,7 @@ def update_route(
|
||||
data: schemas.ReceivePayment,
|
||||
u: bool, # Update table?
|
||||
user: UserToken = Security(get_user, scopes=["settle-bill"]),
|
||||
):
|
||||
) -> bool:
|
||||
try:
|
||||
with SessionFuture() as db:
|
||||
update_table = u
|
||||
|
||||
@@ -45,7 +45,7 @@ def save(
|
||||
p: int, # Print type
|
||||
g: uuid.UUID | None = None, # Guest book id
|
||||
user: UserToken = Security(get_user),
|
||||
):
|
||||
) -> None:
|
||||
try:
|
||||
with SessionFuture() as db:
|
||||
update_table = u
|
||||
@@ -76,7 +76,7 @@ def do_save(
|
||||
guest_book: GuestBook | None,
|
||||
db: Session,
|
||||
user: UserToken,
|
||||
):
|
||||
) -> Voucher:
|
||||
now = datetime.now(UTC).replace(tzinfo=None)
|
||||
product_date = (now + timedelta(minutes=settings.TIMEZONE_OFFSET_MINUTES - settings.NEW_DAY_OFFSET_MINUTES)).date()
|
||||
check_permissions(None, voucher_type, user.permissions)
|
||||
|
||||
@@ -38,7 +38,7 @@ def split(
|
||||
data: schemas.Split,
|
||||
u: bool, # Update table?
|
||||
user: UserToken = Security(get_user, scopes=["split-bill"]),
|
||||
):
|
||||
) -> None:
|
||||
try:
|
||||
with SessionFuture() as db:
|
||||
now = datetime.now(UTC).replace(tzinfo=None)
|
||||
@@ -48,7 +48,7 @@ def split(
|
||||
item.voucher_type = VoucherType.VOID
|
||||
item.reason = "Bill Split"
|
||||
do_update_bill_numbers(item, db)
|
||||
do_update_settlements(item, [SettleSchema(id_=SettleOption.VOID(), amount=round(item.amount))], db)
|
||||
do_update_settlements(item, [SettleSchema(id_=SettleOption.VOID(), amount=Decimal(round(item.amount)))], db)
|
||||
if update_table:
|
||||
db.execute(delete(Overview).where(Overview.voucher_id == item.id))
|
||||
check_permissions(None, item.voucher_type, user.permissions)
|
||||
@@ -97,7 +97,7 @@ def save(
|
||||
customer_id: uuid.UUID | None,
|
||||
user_id: uuid.UUID,
|
||||
db: Session,
|
||||
):
|
||||
) -> Voucher:
|
||||
if not are_product_quantities_positive(inventories):
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_422_UNPROCESSABLE_ENTITY,
|
||||
@@ -153,8 +153,8 @@ def save(
|
||||
return item
|
||||
|
||||
|
||||
def split_into_kots(inventories: list[Inventory]) -> list:
|
||||
kots = defaultdict(list)
|
||||
def split_into_kots(inventories: list[Inventory]) -> list[list[Inventory]]:
|
||||
kots: dict[uuid.UUID, list[Inventory]] = defaultdict(list)
|
||||
for item in inventories:
|
||||
kots[item.kot_id].append(item)
|
||||
return [k for k in kots.values() if len(k) > 0]
|
||||
|
||||
@@ -44,7 +44,7 @@ def update_route(
|
||||
p: int, # Print type
|
||||
g: uuid.UUID | None = None, # Guest book id
|
||||
user: UserToken = Security(get_user),
|
||||
):
|
||||
) -> None:
|
||||
try:
|
||||
with SessionFuture() as db:
|
||||
now = datetime.now(UTC).replace(tzinfo=None)
|
||||
@@ -168,6 +168,7 @@ def update_route(
|
||||
is_hh=nki.is_happy_hour,
|
||||
tax_rate=tax_rate,
|
||||
sort_order=index,
|
||||
tax_id=product.sale_category.tax_id,
|
||||
tax=product.sale_category.tax,
|
||||
)
|
||||
kot.inventories.append(inv)
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
from datetime import date, datetime
|
||||
from typing import Any
|
||||
|
||||
from pydantic import BaseModel, ConfigDict, field_serializer, field_validator
|
||||
|
||||
@@ -14,13 +15,13 @@ class BillSettlementItem(BaseModel):
|
||||
|
||||
@field_validator("date_", mode="before")
|
||||
@classmethod
|
||||
def parse_date(cls, value):
|
||||
def parse_date(cls, value: str | datetime) -> datetime:
|
||||
if isinstance(value, datetime):
|
||||
return value
|
||||
return datetime.strptime(value, "%d-%b-%Y %H:%M")
|
||||
|
||||
@field_serializer("date_")
|
||||
def serialize_date(self, value: datetime, _info):
|
||||
def serialize_date(self, value: datetime, _info: Any) -> str:
|
||||
return value.strftime("%d-%b-%Y %H:%M")
|
||||
|
||||
|
||||
@@ -32,22 +33,22 @@ class BillSettlement(BaseModel):
|
||||
|
||||
@field_validator("start_date", mode="before")
|
||||
@classmethod
|
||||
def parse_start_date(cls, value):
|
||||
def parse_start_date(cls, value: str | date) -> date:
|
||||
if isinstance(value, date):
|
||||
return value
|
||||
return datetime.strptime(value, "%d-%b-%Y").date()
|
||||
|
||||
@field_serializer("start_date")
|
||||
def serialize_start_date(self, value: date, _info):
|
||||
def serialize_start_date(self, value: date, _info: Any) -> str:
|
||||
return value.strftime("%d-%b-%Y")
|
||||
|
||||
@field_validator("finish_date", mode="before")
|
||||
@classmethod
|
||||
def parse_finish_date(cls, value):
|
||||
def parse_finish_date(cls, value: str | date) -> date:
|
||||
if isinstance(value, date):
|
||||
return value
|
||||
return datetime.strptime(value, "%d-%b-%Y").date()
|
||||
|
||||
@field_serializer("finish_date")
|
||||
def serialize_finish_date(self, value: date, _info):
|
||||
def serialize_finish_date(self, value: date, _info: Any) -> str:
|
||||
return value.strftime("%d-%b-%Y")
|
||||
@@ -1,4 +1,5 @@
|
||||
from datetime import date, datetime
|
||||
from typing import Any
|
||||
|
||||
from pydantic import BaseModel, ConfigDict, field_serializer, field_validator
|
||||
|
||||
@@ -13,10 +14,12 @@ class NameAmount(BaseModel):
|
||||
|
||||
|
||||
class SettleOptionSchema(BaseModel):
|
||||
def __hash__(self):
|
||||
def __hash__(self) -> int:
|
||||
return hash(self.id_)
|
||||
|
||||
def __eq__(self, other):
|
||||
def __eq__(self, other: object) -> bool:
|
||||
if not isinstance(other, SettleOptionSchema):
|
||||
return NotImplemented
|
||||
return self.id_ == other.id_
|
||||
|
||||
id_: int
|
||||
@@ -33,7 +36,7 @@ class InfoItem(BaseModel):
|
||||
|
||||
@field_validator("date", mode="before")
|
||||
@classmethod
|
||||
def parse_date(cls, value):
|
||||
def parse_date(cls, value: str | datetime) -> datetime:
|
||||
if isinstance(value, datetime):
|
||||
return value
|
||||
return datetime.strptime(value, "%d-%b-%Y %H:%M")
|
||||
@@ -51,22 +54,22 @@ class CashierReport(BaseModel):
|
||||
|
||||
@field_validator("start_date", mode="before")
|
||||
@classmethod
|
||||
def parse_start_date(cls, value):
|
||||
def parse_start_date(cls, value: str | date) -> date:
|
||||
if isinstance(value, date):
|
||||
return value
|
||||
return datetime.strptime(value, "%d-%b-%Y").date()
|
||||
|
||||
@field_serializer("start_date")
|
||||
def serialize_start_date(self, value: date, _info):
|
||||
def serialize_start_date(self, value: date, _info: Any) -> str:
|
||||
return value.strftime("%d-%b-%Y")
|
||||
|
||||
@field_validator("finish_date", mode="before")
|
||||
@classmethod
|
||||
def parse_finish_date(cls, value):
|
||||
def parse_finish_date(cls, value: str | date) -> date:
|
||||
if isinstance(value, date):
|
||||
return value
|
||||
return datetime.strptime(value, "%d-%b-%Y").date()
|
||||
|
||||
@field_serializer("finish_date")
|
||||
def serialize_finish_date(self, value: date, _info):
|
||||
def serialize_finish_date(self, value: date, _info: Any) -> str:
|
||||
return value.strftime("%d-%b-%Y")
|
||||
@@ -1,6 +1,7 @@
|
||||
import uuid
|
||||
|
||||
from datetime import datetime
|
||||
from typing import Any
|
||||
|
||||
from pydantic import BaseModel, ConfigDict, Field, field_serializer
|
||||
|
||||
@@ -23,11 +24,11 @@ class Device(DeviceIn):
|
||||
model_config = ConfigDict(str_strip_whitespace=True, alias_generator=to_camel, populate_by_name=True)
|
||||
|
||||
@field_serializer("creation_date")
|
||||
def serialize_creation_date(self, value: datetime, _info):
|
||||
def serialize_creation_date(self, value: datetime, _info: Any) -> str:
|
||||
return value.strftime("%d-%b-%Y %H:%M")
|
||||
|
||||
@field_serializer("last_date")
|
||||
def serialize_last_date(self, value: datetime | None, _info):
|
||||
def serialize_last_date(self, value: datetime | None, _info: Any) -> str | None:
|
||||
return None if value is None else value.strftime("%d-%b-%Y %H:%M")
|
||||
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
from datetime import date, datetime
|
||||
from typing import Any
|
||||
|
||||
from pydantic import BaseModel, ConfigDict, field_serializer, field_validator
|
||||
|
||||
@@ -19,22 +20,22 @@ class DiscountReport(BaseModel):
|
||||
|
||||
@field_validator("start_date", mode="before")
|
||||
@classmethod
|
||||
def parse_start_date(cls, value: date | str):
|
||||
def parse_start_date(cls, value: date | str) -> date:
|
||||
if isinstance(value, date):
|
||||
return value
|
||||
return datetime.strptime(value, "%d-%b-%Y").date()
|
||||
|
||||
@field_serializer("start_date")
|
||||
def serialize_start_date(self, value: date, _info):
|
||||
def serialize_start_date(self, value: date, _info: Any) -> str:
|
||||
return value.strftime("%d-%b-%Y")
|
||||
|
||||
@field_validator("finish_date", mode="before")
|
||||
@classmethod
|
||||
def parse_finish_date(cls, value: date | str):
|
||||
def parse_finish_date(cls, value: date | str) -> date:
|
||||
if isinstance(value, date):
|
||||
return value
|
||||
return datetime.strptime(value, "%d-%b-%Y").date()
|
||||
|
||||
@field_serializer("finish_date")
|
||||
def serialize_finish_date(self, value: date, _info):
|
||||
def serialize_finish_date(self, value: date, _info: Any) -> str:
|
||||
return value.strftime("%d-%b-%Y")
|
||||
@@ -1,6 +1,7 @@
|
||||
import uuid
|
||||
|
||||
from datetime import date, datetime
|
||||
from typing import Any
|
||||
|
||||
from pydantic import (
|
||||
BaseModel,
|
||||
@@ -29,7 +30,7 @@ class GuestBookIn(BaseModel):
|
||||
|
||||
@field_validator("booking_date", mode="before")
|
||||
@classmethod
|
||||
def parse_booking_date(cls, value):
|
||||
def parse_booking_date(cls, value: str | datetime | None) -> datetime | None:
|
||||
if value is None:
|
||||
return None
|
||||
if isinstance(value, datetime):
|
||||
@@ -37,12 +38,12 @@ class GuestBookIn(BaseModel):
|
||||
return datetime.strptime(value, "%d-%b-%Y %H:%M")
|
||||
|
||||
@field_serializer("booking_date")
|
||||
def serialize_booking_date(self, value: datetime | None, _info):
|
||||
def serialize_booking_date(self, value: datetime | None, _info: Any) -> str | None:
|
||||
return None if value is None else value.strftime("%d-%b-%Y %H:%M")
|
||||
|
||||
@field_validator("arrival_date", mode="before")
|
||||
@classmethod
|
||||
def parse_arrival_date(cls, value):
|
||||
def parse_arrival_date(cls, value: str | datetime | None) -> datetime | None:
|
||||
if value is None:
|
||||
return None
|
||||
if isinstance(value, datetime):
|
||||
@@ -50,7 +51,7 @@ class GuestBookIn(BaseModel):
|
||||
return datetime.strptime(value, "%d-%b-%Y %H:%M")
|
||||
|
||||
@field_serializer("arrival_date")
|
||||
def serialize_arrival_date(self, value: datetime | None, _info):
|
||||
def serialize_arrival_date(self, value: datetime | None, _info: Any) -> str | None:
|
||||
return None if value is None else value.strftime("%d-%b-%Y %H:%M")
|
||||
|
||||
@model_validator(mode="after")
|
||||
@@ -68,13 +69,13 @@ class GuestBook(GuestBookIn):
|
||||
|
||||
@field_validator("last_edit_date", mode="before")
|
||||
@classmethod
|
||||
def parse_last_edit_date(cls, value):
|
||||
def parse_last_edit_date(cls, value: str | datetime) -> datetime:
|
||||
if isinstance(value, datetime):
|
||||
return value
|
||||
return datetime.strptime(value, "%d-%b-%Y %H:%M")
|
||||
|
||||
@field_serializer("last_edit_date")
|
||||
def serialize_last_edit_date(self, value: datetime, _info):
|
||||
def serialize_last_edit_date(self, value: datetime, _info: Any) -> str:
|
||||
return value.strftime("%d-%b-%Y %H:%M")
|
||||
|
||||
|
||||
@@ -98,7 +99,7 @@ class GuestBookListItem(BaseModel):
|
||||
|
||||
@field_validator("booking_date", mode="before")
|
||||
@classmethod
|
||||
def parse_booking_date(cls, value):
|
||||
def parse_booking_date(cls, value: str | datetime | None) -> datetime | None:
|
||||
if value is None:
|
||||
return None
|
||||
if isinstance(value, datetime):
|
||||
@@ -106,12 +107,12 @@ class GuestBookListItem(BaseModel):
|
||||
return datetime.strptime(value, "%d-%b-%Y %H:%M")
|
||||
|
||||
@field_serializer("booking_date")
|
||||
def serialize_booking_date(self, value: datetime | None, _info):
|
||||
def serialize_booking_date(self, value: datetime | None, _info: Any) -> str | None:
|
||||
return None if value is None else value.strftime("%d-%b-%Y %H:%M")
|
||||
|
||||
@field_validator("arrival_date", mode="before")
|
||||
@classmethod
|
||||
def parse_arrival_date(cls, value):
|
||||
def parse_arrival_date(cls, value: str | datetime | None) -> datetime | None:
|
||||
if value is None:
|
||||
return None
|
||||
if isinstance(value, datetime):
|
||||
@@ -119,18 +120,18 @@ class GuestBookListItem(BaseModel):
|
||||
return datetime.strptime(value, "%d-%b-%Y %H:%M")
|
||||
|
||||
@field_serializer("arrival_date")
|
||||
def serialize_arrival_date(self, value: datetime | None, _info):
|
||||
def serialize_arrival_date(self, value: datetime | None, _info: Any) -> str | None:
|
||||
return None if value is None else value.strftime("%d-%b-%Y %H:%M")
|
||||
|
||||
@field_validator("last_edit_date", mode="before")
|
||||
@classmethod
|
||||
def parse_last_edit_date(cls, value):
|
||||
def parse_last_edit_date(cls, value: str | datetime) -> datetime:
|
||||
if isinstance(value, datetime):
|
||||
return value
|
||||
return datetime.strptime(value, "%d-%b-%Y %H:%M")
|
||||
|
||||
@field_serializer("last_edit_date")
|
||||
def serialize_last_edit_date(self, value: datetime, _info):
|
||||
def serialize_last_edit_date(self, value: datetime, _info: Any) -> str:
|
||||
return value.strftime("%d-%b-%Y %H:%M")
|
||||
|
||||
|
||||
@@ -141,11 +142,11 @@ class GuestBookList(BaseModel):
|
||||
|
||||
@field_validator("date_", mode="before")
|
||||
@classmethod
|
||||
def parse_date(cls, value):
|
||||
def parse_date(cls, value: str | date) -> date:
|
||||
if isinstance(value, date):
|
||||
return value
|
||||
return datetime.strptime(value, "%d-%b-%Y").date()
|
||||
|
||||
@field_serializer("date_")
|
||||
def serialize_date(self, value: date, _info):
|
||||
def serialize_date(self, value: date, _info: Any) -> str:
|
||||
return value.strftime("%d-%b-%Y")
|
||||
@@ -1,6 +1,7 @@
|
||||
import uuid
|
||||
|
||||
from datetime import date, datetime
|
||||
from typing import Any
|
||||
|
||||
from pydantic import BaseModel, ConfigDict, field_serializer, field_validator
|
||||
|
||||
@@ -22,6 +23,7 @@ class MeItem(BaseModel):
|
||||
|
||||
|
||||
class MeReport(BaseModel):
|
||||
user_name: str
|
||||
start_date: date
|
||||
finish_date: date
|
||||
amounts: list[MeItem]
|
||||
@@ -29,22 +31,22 @@ class MeReport(BaseModel):
|
||||
|
||||
@field_validator("start_date", mode="before")
|
||||
@classmethod
|
||||
def parse_start_date(cls, value):
|
||||
def parse_start_date(cls, value: str | date) -> date:
|
||||
if isinstance(value, date):
|
||||
return value
|
||||
return datetime.strptime(value, "%d-%b-%Y").date()
|
||||
|
||||
@field_serializer("start_date")
|
||||
def serialize_start_date(self, value: date, _info):
|
||||
def serialize_start_date(self, value: date, _info: Any) -> str:
|
||||
return value.strftime("%d-%b-%Y")
|
||||
|
||||
@field_validator("finish_date", mode="before")
|
||||
@classmethod
|
||||
def parse_finish_date(cls, value):
|
||||
def parse_finish_date(cls, value: str | date) -> date:
|
||||
if isinstance(value, date):
|
||||
return value
|
||||
return datetime.strptime(value, "%d-%b-%Y").date()
|
||||
|
||||
@field_serializer("finish_date")
|
||||
def serialize_finish_date(self, value: date, _info):
|
||||
def serialize_finish_date(self, value: date, _info: Any) -> str:
|
||||
return value.strftime("%d-%b-%Y")
|
||||
@@ -2,6 +2,7 @@ import uuid
|
||||
|
||||
from datetime import date, datetime
|
||||
from decimal import Decimal
|
||||
from typing import Any
|
||||
|
||||
from pydantic import BaseModel, ConfigDict, Field, field_serializer, field_validator
|
||||
|
||||
@@ -33,7 +34,7 @@ class Product(ProductIn):
|
||||
|
||||
@field_validator("valid_from", mode="before")
|
||||
@classmethod
|
||||
def parse_valid_from(cls, value):
|
||||
def parse_valid_from(cls, value: str | date | None) -> date | None:
|
||||
if value is None:
|
||||
return None
|
||||
if isinstance(value, date):
|
||||
@@ -41,12 +42,12 @@ class Product(ProductIn):
|
||||
return datetime.strptime(value, "%d-%b-%Y").date()
|
||||
|
||||
@field_serializer("valid_from")
|
||||
def serialize_valid_from(self, value: date | None, _info):
|
||||
def serialize_valid_from(self, value: date | None, _info: Any) -> str | None:
|
||||
return None if value is None else value.strftime("%d-%b-%Y")
|
||||
|
||||
@field_validator("valid_till", mode="before")
|
||||
@classmethod
|
||||
def parse_valid_till(cls, value):
|
||||
def parse_valid_till(cls, value: str | date | None) -> date | None:
|
||||
if value is None:
|
||||
return None
|
||||
if isinstance(value, date):
|
||||
@@ -54,7 +55,7 @@ class Product(ProductIn):
|
||||
return datetime.strptime(value, "%d-%b-%Y").date()
|
||||
|
||||
@field_serializer("valid_till")
|
||||
def serialize_valid_till(self, value: date | None, _info):
|
||||
def serialize_valid_till(self, value: date | None, _info: Any) -> str | None:
|
||||
return None if value is None else value.strftime("%d-%b-%Y")
|
||||
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import uuid
|
||||
|
||||
from datetime import date, datetime
|
||||
from typing import Any
|
||||
|
||||
from pydantic import BaseModel, ConfigDict, field_serializer, field_validator
|
||||
|
||||
@@ -24,22 +25,22 @@ class SaleReport(BaseModel):
|
||||
|
||||
@field_validator("start_date", mode="before")
|
||||
@classmethod
|
||||
def parse_start_date(cls, value):
|
||||
def parse_start_date(cls, value: str | date) -> date:
|
||||
if isinstance(value, date):
|
||||
return value
|
||||
return datetime.strptime(value, "%d-%b-%Y").date()
|
||||
|
||||
@field_serializer("start_date")
|
||||
def serialize_start_date(self, value: date, _info):
|
||||
def serialize_start_date(self, value: date, _info: Any) -> str:
|
||||
return value.strftime("%d-%b-%Y")
|
||||
|
||||
@field_validator("finish_date", mode="before")
|
||||
@classmethod
|
||||
def parse_finish_date(cls, value):
|
||||
def parse_finish_date(cls, value: str | date) -> date:
|
||||
if isinstance(value, date):
|
||||
return value
|
||||
return datetime.strptime(value, "%d-%b-%Y").date()
|
||||
|
||||
@field_serializer("finish_date")
|
||||
def serialize_finish_date(self, value: date, _info):
|
||||
def serialize_finish_date(self, value: date, _info: Any) -> str:
|
||||
return value.strftime("%d-%b-%Y")
|
||||
@@ -1,4 +1,5 @@
|
||||
from datetime import date, datetime
|
||||
from typing import Any
|
||||
|
||||
from pydantic import BaseModel, ConfigDict, field_serializer, field_validator
|
||||
|
||||
@@ -21,22 +22,22 @@ class TaxReport(BaseModel):
|
||||
|
||||
@field_validator("start_date", mode="before")
|
||||
@classmethod
|
||||
def parse_start_date(cls, value):
|
||||
def parse_start_date(cls, value: str | date) -> date:
|
||||
if isinstance(value, date):
|
||||
return value
|
||||
return datetime.strptime(value, "%d-%b-%Y").date()
|
||||
|
||||
@field_serializer("start_date")
|
||||
def serialize_start_date(self, value: date, _info):
|
||||
def serialize_start_date(self, value: date, _info: Any) -> str:
|
||||
return value.strftime("%d-%b-%Y")
|
||||
|
||||
@field_validator("finish_date", mode="before")
|
||||
@classmethod
|
||||
def parse_finish_date(cls, value):
|
||||
def parse_finish_date(cls, value: str | date) -> date:
|
||||
if isinstance(value, date):
|
||||
return value
|
||||
return datetime.strptime(value, "%d-%b-%Y").date()
|
||||
|
||||
@field_serializer("finish_date")
|
||||
def serialize_finish_date(self, value: date, _info):
|
||||
def serialize_finish_date(self, value: date, _info: Any) -> str:
|
||||
return value.strftime("%d-%b-%Y")
|
||||
@@ -1,6 +1,7 @@
|
||||
import uuid
|
||||
|
||||
from datetime import date, datetime
|
||||
from typing import Any
|
||||
|
||||
from pydantic import BaseModel, ConfigDict, field_serializer, field_validator
|
||||
|
||||
@@ -23,11 +24,11 @@ class UpdateProductPrices(BaseModel):
|
||||
|
||||
@field_validator("date_", mode="before")
|
||||
@classmethod
|
||||
def parse_date(cls, value):
|
||||
def parse_date(cls, value: str | date) -> date:
|
||||
if isinstance(value, date):
|
||||
return value
|
||||
return datetime.strptime(value, "%d-%b-%Y").date()
|
||||
|
||||
@field_serializer("date_")
|
||||
def serialize_date(self, value: date, _info):
|
||||
def serialize_date(self, value: date, _info: Any) -> str:
|
||||
return value.strftime("%d-%b-%Y")
|
||||
@@ -1,6 +1,7 @@
|
||||
import uuid
|
||||
|
||||
from datetime import datetime
|
||||
from typing import Any
|
||||
|
||||
from pydantic import BaseModel, ConfigDict, field_serializer
|
||||
|
||||
@@ -43,5 +44,5 @@ class UserList(BaseModel):
|
||||
model_config = ConfigDict(str_strip_whitespace=True, alias_generator=to_camel, populate_by_name=True)
|
||||
|
||||
@field_serializer("last_date")
|
||||
def serialize_last_date(self, value: datetime | None, _info):
|
||||
def serialize_last_date(self, value: datetime | None, _info: Any) -> str | None:
|
||||
return None if value is None else value.strftime("%d-%b-%Y %H:%M")
|
||||
@@ -58,7 +58,7 @@ class Inventory(BaseModel):
|
||||
price = 0 if self.is_happy_hour else self.price
|
||||
self.amount = round(
|
||||
Decimal(price * self.quantity * (1 - self.discount) * (1 + (self.tax_rate or Decimal(0)))),
|
||||
2, # type: ignore
|
||||
2,
|
||||
)
|
||||
return self
|
||||
|
||||
|
||||
@@ -79,10 +79,15 @@ class Inventory(BaseModel):
|
||||
|
||||
@model_validator(mode="after")
|
||||
def calculate_amount(self) -> "Inventory":
|
||||
price = 0 if self.is_happy_hour else self.price
|
||||
price = Decimal(0) if self.is_happy_hour else (self.price or Decimal(0))
|
||||
self.amount = round(
|
||||
Decimal(price * self.quantity * (1 - self.discount) * (1 + (self.tax_rate or Decimal(0)))), # type: ignore
|
||||
2, # type: ignore
|
||||
(
|
||||
price
|
||||
* (self.quantity or Decimal(0))
|
||||
* (1 - (self.discount or Decimal(0)))
|
||||
* (1 + (self.tax_rate or Decimal(0)))
|
||||
),
|
||||
2,
|
||||
)
|
||||
return self
|
||||
|
||||
|
||||
Reference in new issue
Block a user