Skip to content

Commit 792d6e5

Browse files
committed
add a new method for supplementing allocation
1 parent dc06fe1 commit 792d6e5

1 file changed

Lines changed: 11 additions & 7 deletions

File tree

‎domain_model.py‎

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
from dataclasses import dataclass
2-
from datetime import date
32

43
class Allocation(dict):
54

65
@property
76
def skus(self):
87
return self.keys()
98

9+
def supplement_with(self, allocation):
10+
for sku, quantity in allocation.items():
11+
if sku in self:
12+
continue
13+
self[sku] = quantity
14+
1015

1116
@dataclass
1217
class Order:
@@ -23,18 +28,17 @@ def fully_allocated(self):
2328

2429

2530
def allocate(self, stock, shipments):
26-
self.allocation = {}
31+
self.allocation = Allocation()
2732
for source in [stock] + sorted(shipments, key=lambda x: x.eta):
28-
allocation = Allocation({
33+
source_allocation = Allocation({
2934
sku: source
3035
for sku, quantity in self.lines.items()
3136
if source.can_allocate(sku, quantity)
3237
})
33-
if allocation.skus == self.skus:
34-
self.allocation = allocation
38+
if source_allocation.skus == self.skus:
39+
self.allocation = source_allocation
3540
return
36-
allocation.update(self.allocation)
37-
self.allocation = allocation
41+
self.allocation.supplement_with(source_allocation)
3842

3943

4044
class Stock(dict):

0 commit comments

Comments
 (0)