File tree Expand file tree Collapse file tree 2 files changed +12
-10
lines changed
Expand file tree Collapse file tree 2 files changed +12
-10
lines changed Original file line number Diff line number Diff line change @@ -14,13 +14,17 @@ def fully_allocated(self):
1414 def allocate (self , stock , shipments ):
1515 self .allocations = {}
1616 for source in [stock ] + shipments :
17- self . allocations . update ( {
18- key : stock
17+ allocation = {
18+ key : source
1919 for key in self .lines
2020 if key in source .lines
21- })
22- if self .fully_allocated :
21+ and source .lines [key ] > self .lines [key ]
22+ }
23+ if set (allocation .keys ()) == set (self .lines ):
24+ self .allocations = allocation
2325 return
26+ allocation .update (self .allocations )
27+ self .allocations = allocation
2428
2529
2630@dataclass
Original file line number Diff line number Diff line change @@ -130,15 +130,14 @@ def test_still_preserves_ordering_if_split_across_shipments():
130130 assert order .allocations ['sku2' ] == shipment2
131131 assert order .allocations ['sku3' ] == shipment2
132132
133- '''
134133
135134def test_stock_not_quite_enough_means_we_use_shipment ():
136135 order = Order ({'sku1' : 10 , 'sku2' : 10 })
137136 stock = Stock ({'sku1' : 10 , 'sku2' : 5 })
138- shipment = Stock({)
137+ shipment = Stock ({
139138 'sku1' : 1000 ,
140139 'sku2' : 1000 ,
141- }
140+ })
142141
143142 order .allocate (stock , shipments = [shipment ])
144143
@@ -157,12 +156,11 @@ def test_cannot_allocate_if_insufficent_quantity_in_stock():
157156
158157def test_cannot_allocate_if_insufficent_quantity_in_shipment ():
159158 order = Order ({'a-sku' : 10 })
160- shipment = Stock({)
159+ shipment = Stock ({
161160 'a-sku' : 5 ,
162- }
161+ })
163162
164163 order .allocate (stock = Stock ({}), shipments = [shipment ])
165164
166165 assert 'a-sku' not in order .allocations
167166
168- '''
You can’t perform that action at this time.
0 commit comments