Skip to content

Commit 27b3362

Browse files
committed
this is getting silly now. where's all my code gone?
1 parent 572e0ee commit 27b3362

File tree

1 file changed

+17
-15
lines changed

1 file changed

+17
-15
lines changed

domain_model.py

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,22 @@ def allocate_to(order, source):
1414
}
1515

1616

17+
def merge(allocations):
18+
return {
19+
k: v
20+
for d in allocations
21+
for k, v in d.items()
22+
}
23+
24+
25+
1726
def allocate(order, stock, shipments):
18-
stock_allocation = allocate_to(order, stock)
19-
if allocated_completely(order, stock_allocation):
20-
return stock_allocation
21-
22-
shipment_allocations = []
23-
for shipment in shipments:
24-
shipment_allocation = allocate_to(order, shipment)
25-
if allocated_completely(order, shipment_allocation):
26-
return shipment_allocation
27-
shipment_allocations.append(shipment_allocation)
28-
29-
mixed_allocation = {}
30-
for allocation in shipment_allocations + [stock_allocation]:
31-
mixed_allocation.update(allocation)
32-
return mixed_allocation
27+
allocations = []
28+
for source in [stock] + shipments:
29+
allocation = allocate_to(order, source)
30+
if allocated_completely(order, allocation):
31+
return allocation
32+
allocations.append(allocation)
33+
34+
return merge(reversed(allocations))
3335

0 commit comments

Comments
 (0)