1
- from dataclasses import dataclass
2
-
3
- @dataclass
4
1
class Order (dict ):
5
- def __init__ (self , d ):
2
+ def __init__ (self , lines ):
6
3
self .allocations = {}
7
- super ().__init__ (d )
4
+ super ().__init__ (lines )
8
5
9
6
10
7
class Shipment (dict ):
@@ -21,20 +18,11 @@ def skus(thing):
21
18
return thing .keys ()
22
19
23
20
24
- def allocate_to (order , source , name ):
21
+ def allocate_to (order , source ):
25
22
for sku , quantity in order .items ():
26
23
if source .get (sku , 0 ) > quantity :
27
24
source [sku ] -= quantity
28
- order .allocations [sku ] = name
29
-
30
-
31
- def allocate_to_stock (order , stock ):
32
- allocate_to (order , stock , 'STOCK' )
33
-
34
- def allocate_to_shipment (order , shipment ):
35
- allocate_to (order , shipment , shipment .id )
36
-
37
-
25
+ order .allocations [sku ] = getattr (source , 'id' , 'STOCK' )
38
26
39
27
40
28
def allocate_to_shipments (order , shipments ):
@@ -50,15 +38,15 @@ def allocate_to_shipments(order, shipments):
50
38
51
39
def allocate (order , stock , shipments ):
52
40
if skus (order ) <= skus (stock ):
53
- allocate_to_stock (order , stock )
41
+ allocate_to (order , stock )
54
42
return
55
43
56
44
shipments .sort (key = lambda s : s .eta )
57
45
58
46
for shipment in shipments :
59
47
if skus (order ) <= skus (shipment ):
60
- allocate_to_shipment (order , shipment )
48
+ allocate_to (order , shipment )
61
49
return
62
50
63
- allocate_to_stock (order , stock )
51
+ allocate_to (order , stock )
64
52
allocate_to_shipments (order , shipments )
0 commit comments