Modify cart items

This commit is contained in:
2025-12-13 14:30:14 +01:00
parent 5d2dfe37c1
commit d1fc874c35
6 changed files with 137 additions and 11 deletions

View File

@@ -94,6 +94,8 @@ class Product(Base):
price: Mapped[decimal.Decimal] = mapped_column(Numeric(10, 2))
unit_of_measure: Mapped[UnitsOfMeasure] = mapped_column(nullable=False)
allow_fractional: Mapped[bool] = mapped_column(nullable=False, default=True)
# TODO: limit this to actually used vat rates?
vat_rate: Mapped[decimal.Decimal] = mapped_column(Numeric(10, 2))
@@ -162,6 +164,13 @@ class OrderItem(Base):
Numeric(10, 2), nullable=False
)
def update_quantity(self, new_quantity: decimal.Decimal):
if new_quantity <= 0:
raise ValueError("Quantity must be positive.")
self.quantity = new_quantity
self.total_amount = self.product.price * new_quantity
TransactionTypes = typing.Literal[
"order",