Skip to content

Commit d1af5d1

Browse files
committed
add a skus property
1 parent f0e0c55 commit d1af5d1

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

domain_model.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,36 @@
11
from dataclasses import dataclass
22
from datetime import date
33

4+
class Allocation(dict):
5+
6+
@property
7+
def skus(self):
8+
return self.keys()
9+
10+
411
@dataclass
512
class Order:
613
lines: dict
714
allocations: dict = None
815

16+
@property
17+
def skus(self):
18+
return self.lines.keys()
19+
920
@property
1021
def fully_allocated(self):
11-
return set(self.allocations.keys()) == set(self.lines.keys())
22+
return self.allocations.skus == self.skus
1223

1324

1425
def allocate(self, stock, shipments):
1526
self.allocations = {}
1627
for source in [stock] + shipments:
17-
allocation = {
28+
allocation = Allocation({
1829
sku: source
1930
for sku, quantity in self.lines.items()
2031
if source.can_allocate(sku, quantity)
21-
}
22-
if set(allocation.keys()) == set(self.lines):
32+
})
33+
if allocation.skus == self.skus:
2334
self.allocations = allocation
2435
return
2536
allocation.update(self.allocations)
@@ -34,4 +45,3 @@ class Stock:
3445
def can_allocate(self, sku, quantity):
3546
return sku in self.lines and self.lines[sku] > quantity
3647

37-

0 commit comments

Comments
 (0)