Skip to content

Commit f0e0c55

Browse files
committed
start to make the model more OO by adding a .can_allocate() method to Stock
1 parent defc3e3 commit f0e0c55

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

domain_model.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,9 @@ def allocate(self, stock, shipments):
1515
self.allocations = {}
1616
for source in [stock] + shipments:
1717
allocation = {
18-
key: source
19-
for key in self.lines
20-
if key in source.lines
21-
and source.lines[key] > self.lines[key]
18+
sku: source
19+
for sku, quantity in self.lines.items()
20+
if source.can_allocate(sku, quantity)
2221
}
2322
if set(allocation.keys()) == set(self.lines):
2423
self.allocations = allocation
@@ -32,4 +31,7 @@ class Stock:
3231
lines: dict
3332
eta: date = None
3433

34+
def can_allocate(self, sku, quantity):
35+
return sku in self.lines and self.lines[sku] > quantity
36+
3537

0 commit comments

Comments
 (0)