Skip to content

Commit defc3e3

Browse files
committed
classy version now at same stage
1 parent bb9c5b9 commit defc3e3

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

domain_model.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff 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

test_allocation.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff 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

135134
def 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

158157
def 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-
'''

0 commit comments

Comments
 (0)