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:
Yohan Boniface 2019-05-25 17:33:20 +02:00
parent bd2fb3958e
commit b3062fd385
2 changed files with 15 additions and 2 deletions

View file

@ -134,9 +134,12 @@ class Order(Base):
def total(self, products):
products = {p.ref: p for p in products}
return round(
sum(p.quantity * products[ref].price for ref, p in self.products.items()), 2
total = sum(
p.quantity * products[ref].price
for ref, p in self.products.items()
if ref in products
)
return round(total, 2)
@property
def has_adjustments(self):

View file

@ -105,6 +105,16 @@ def test_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):
with pytest.raises(AssertionError):
delivery.path