@@ -9,13 +9,22 @@ def skus(self):
9
9
return self .keys ()
10
10
11
11
@staticmethod
12
- def for_ (order , source ):
12
+ def for_source (order , source ):
13
13
return Allocation ({
14
14
sku : source
15
15
for sku , quantity in order .items ()
16
16
if source .can_allocate (sku , quantity )
17
17
}, order = order )
18
18
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
+
19
28
def supplement_with (self , allocation ):
20
29
for sku , quantity in allocation .items ():
21
30
if sku in self :
@@ -34,10 +43,7 @@ def skus(self):
34
43
return self .keys ()
35
44
36
45
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 )
41
47
self .allocation .apply ()
42
48
43
49
0 commit comments