File tree Expand file tree Collapse file tree 1 file changed +15
-5
lines changed
Expand file tree Collapse file tree 1 file changed +15
-5
lines changed Original file line number Diff line number Diff line change 11from dataclasses import dataclass
22from datetime import date
33
4+ class Allocation (dict ):
5+
6+ @property
7+ def skus (self ):
8+ return self .keys ()
9+
10+
411@dataclass
512class 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-
You can’t perform that action at this time.
0 commit comments