Implement shopping cart

This commit is contained in:
2025-12-05 11:39:51 +01:00
parent f4618f4d05
commit 00246819cc
12 changed files with 288 additions and 36 deletions

View File

@@ -82,6 +82,7 @@ class Area(Base):
UnitsOfMeasure = typing.Literal[
"g",
"kg",
"l",
"piece",
]
@@ -121,6 +122,10 @@ class Order(Base):
def is_in_shopping_cart(self):
return self.account is None
@property
def total_amount(self):
return sum(item.total_amount for item in self.items)
class OrderItem(Base):
__tablename__ = TABLE_PREFIX + "order_item"
@@ -130,7 +135,7 @@ class OrderItem(Base):
product_id: Mapped[int] = mapped_column(ForeignKey(TABLE_PREFIX + "product.id"))
product: Mapped[Product] = relationship("Product")
quantity: Mapped[int] = mapped_column(nullable=False)
quantity: Mapped[decimal.Decimal] = mapped_column(nullable=False)
total_amount: Mapped[decimal.Decimal] = mapped_column(
Numeric(10, 2), nullable=False
)