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