1- from dataclasses import dataclass
2-
3- @dataclass
41class Order (dict ):
5- def __init__ (self , d ):
2+ def __init__ (self , lines ):
63 self .allocations = {}
7- super ().__init__ (d )
4+ super ().__init__ (lines )
85
96
107class Shipment (dict ):
@@ -21,20 +18,11 @@ def skus(thing):
2118 return thing .keys ()
2219
2320
24- def allocate_to (order , source , name ):
21+ def allocate_to (order , source ):
2522 for sku , quantity in order .items ():
2623 if source .get (sku , 0 ) > quantity :
2724 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' )
3826
3927
4028def allocate_to_shipments (order , shipments ):
@@ -50,15 +38,15 @@ def allocate_to_shipments(order, shipments):
5038
5139def allocate (order , stock , shipments ):
5240 if skus (order ) <= skus (stock ):
53- allocate_to_stock (order , stock )
41+ allocate_to (order , stock )
5442 return
5543
5644 shipments .sort (key = lambda s : s .eta )
5745
5846 for shipment in shipments :
5947 if skus (order ) <= skus (shipment ):
60- allocate_to_shipment (order , shipment )
48+ allocate_to (order , shipment )
6149 return
6250
63- allocate_to_stock (order , stock )
51+ allocate_to (order , stock )
6452 allocate_to_shipments (order , shipments )
0 commit comments