Skip to content

Commit 4073e41

Browse files
committed
remove polymorphism from allocate_to
1 parent bce4c15 commit 4073e41

File tree

2 files changed

+5
-12
lines changed

2 files changed

+5
-12
lines changed

domain_model.py

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,10 @@ def skus(thing):
2929

3030

3131
def allocate_to(line, allocation, source):
32-
try:
33-
if source.get(line.sku, 0) > line.quantity:
34-
line.allocation = allocation
35-
source[line.sku] -= line.quantity
36-
37-
except AttributeError:
38-
for source_line in source:
39-
if source_line.sku == line.sku and source_line.quantity > line.quantity:
40-
line.allocation = allocation
41-
source_line.quantity -= line.quantity
42-
return
32+
if source.get(line.sku, 0) > line.quantity:
33+
line.allocation = allocation
34+
source[line.sku] -= line.quantity
35+
4336

4437
def allocate_to_stock(order, stock):
4538
for line in order:

test_allocation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ def test_prefer_allocating_to_earlier_even_if_multiple_shipments():
216216
'sku2': 1000,
217217
'sku3': 1000,
218218
})
219-
stock = []
219+
stock = {}
220220

221221
allocate(order, stock, shipments=[shipment3, shipment2, shipment1])
222222

0 commit comments

Comments
 (0)