mirror of
https://github.com/almet/copanier.git
synced 2025-04-28 19:42:37 +02:00
Allow to remove a product from a delivery with orders
Eg. when some products are missing from the real delivery while being ordered.
This commit is contained in:
parent
bd2fb3958e
commit
b3062fd385
2 changed files with 15 additions and 2 deletions
|
@ -134,9 +134,12 @@ class Order(Base):
|
||||||
|
|
||||||
def total(self, products):
|
def total(self, products):
|
||||||
products = {p.ref: p for p in products}
|
products = {p.ref: p for p in products}
|
||||||
return round(
|
total = sum(
|
||||||
sum(p.quantity * products[ref].price for ref, p in self.products.items()), 2
|
p.quantity * products[ref].price
|
||||||
|
for ref, p in self.products.items()
|
||||||
|
if ref in products
|
||||||
)
|
)
|
||||||
|
return round(total, 2)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def has_adjustments(self):
|
def has_adjustments(self):
|
||||||
|
|
|
@ -105,6 +105,16 @@ def test_order_has_adjustments():
|
||||||
assert order.has_adjustments
|
assert order.has_adjustments
|
||||||
|
|
||||||
|
|
||||||
|
def test_order_total(delivery):
|
||||||
|
delivery.products = [Product(name="Lait", ref="123", price=1.5)]
|
||||||
|
order = Order()
|
||||||
|
assert order.total(delivery.products) == 0
|
||||||
|
order.products["123"] = ProductOrder(wanted=2)
|
||||||
|
assert order.total(delivery.products) == 3
|
||||||
|
order.products["unknown"] = ProductOrder(wanted=2)
|
||||||
|
assert order.total(delivery.products) == 3
|
||||||
|
|
||||||
|
|
||||||
def test_can_persist_delivery(delivery):
|
def test_can_persist_delivery(delivery):
|
||||||
with pytest.raises(AssertionError):
|
with pytest.raises(AssertionError):
|
||||||
delivery.path
|
delivery.path
|
||||||
|
|
Loading…
Reference in a new issue