Modify cart items
This commit is contained in:
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user