File tree Expand file tree Collapse file tree 1 file changed +5
-18
lines changed
Expand file tree Collapse file tree 1 file changed +5
-18
lines changed Original file line number Diff line number Diff line change 11def allocate (order , stock , shipments ):
2- allocations = []
3- for source in [stock ] + shipments :
4- allocation = allocate_to (order , source )
5- if allocated_completely (order , allocation ):
6- return allocation
7- allocations .append (allocation )
8- return combine_preferring_first (allocations )
2+ allocation = {}
3+ for source in shipments + [stock ]:
4+ allocation .update (allocation_from (order , source ))
5+ return allocation
96
10- def allocate_to (order , source ):
7+ def allocation_from (order , source ):
118 return {
129 sku : source
1310 for sku , quantity in order .items ()
1411 if sku in source
1512 and source [sku ] > quantity
1613 }
17-
18- def allocated_completely (order , allocation ):
19- return order .keys () == allocation .keys ()
20-
21- def combine_preferring_first (allocations ):
22- return {
23- k : v
24- for d in reversed (allocations )
25- for k , v in d .items ()
26- }
You can’t perform that action at this time.
0 commit comments