File tree Expand file tree Collapse file tree 1 file changed +17
-15
lines changed
Expand file tree Collapse file tree 1 file changed +17
-15
lines changed Original file line number Diff line number Diff 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+
1726def 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
You can’t perform that action at this time.
0 commit comments