Skip to content

Commit 5a79e53

Browse files
committed
allocation now modifies quantity state in place
1 parent 14e27e5 commit 5a79e53

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

domain_model.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ def allocate_to(line, allocation, quantities):
3030
for quantity in quantities:
3131
if quantity.sku == line.sku and quantity.quantity > line.quantity:
3232
line.allocation = allocation
33+
quantity.quantity -= line.quantity
3334
return
3435

3536
def allocate_to_stock(line, stock):
@@ -51,7 +52,9 @@ def allocate(order, stock, shipments):
5152
for line in order:
5253
allocate_to_stock(line, stock)
5354
return
55+
5456
shipments.sort(key=lambda s: s.eta)
57+
5558
for shipment in shipments:
5659
if skus(order) <= skus(shipment):
5760
for line in order:

test_allocation.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,3 +232,14 @@ def test_cannot_allocate_if_insufficent_quantity_in_shipment():
232232

233233
assert order[0].allocation is None
234234

235+
236+
def test_allocation_decreases_quantity_available_on_shipments():
237+
order1 = [OrderLine(sku='a-sku', quantity=10)]
238+
order2 = [OrderLine(sku='a-sku', quantity=10)]
239+
stock = [Line(sku='a-sku', quantity=15)]
240+
241+
allocate(order1, stock, shipments=[])
242+
allocate(order2, stock, shipments=[])
243+
244+
assert order2[0].allocation is None
245+

0 commit comments

Comments
 (0)