Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ba3fbe4

Browse files
committed
move some methods around
1 parent c446500 commit ba3fbe4

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

domain_model.py

+11-5
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,22 @@ def skus(self):
99
return self.keys()
1010

1111
@staticmethod
12-
def for_(order, source):
12+
def for_source(order, source):
1313
return Allocation({
1414
sku: source
1515
for sku, quantity in order.items()
1616
if source.can_allocate(sku, quantity)
1717
}, order=order)
1818

19+
20+
@staticmethod
21+
def for_order(order, stock, shipments):
22+
allocation = Allocation({}, order=order)
23+
for source in [stock] + sorted(shipments):
24+
source_allocation = Allocation.for_source(order, source)
25+
allocation.supplement_with(source_allocation)
26+
return allocation
27+
1928
def supplement_with(self, allocation):
2029
for sku, quantity in allocation.items():
2130
if sku in self:
@@ -34,10 +43,7 @@ def skus(self):
3443
return self.keys()
3544

3645
def allocate(self, stock, shipments):
37-
self.allocation = Allocation({}, order=self)
38-
for source in [stock] + sorted(shipments):
39-
source_allocation = Allocation.for_(self, source)
40-
self.allocation.supplement_with(source_allocation)
46+
self.allocation = Allocation.for_order(self, stock, shipments)
4147
self.allocation.apply()
4248

4349

0 commit comments

Comments
 (0)