File tree Expand file tree Collapse file tree 3 files changed +7
-20
lines changed
Expand file tree Collapse file tree 3 files changed +7
-20
lines changed Original file line number Diff line number Diff line change @@ -57,12 +57,3 @@ def _get_by_batchref(self, batchref):
5757 )
5858 .first ()
5959 )
60-
61- def for_order (self , orderid ):
62- order_lines = self .session .query (model .OrderLine ).filter_by (orderid = orderid )
63- skus = {l .sku for l in order_lines }
64- return (
65- self .session .query (model .Product )
66- .join (model .Batch )
67- .filter (model .Batch .sku .in_ (skus ))
68- )
Original file line number Diff line number Diff line change @@ -71,10 +71,6 @@ def __gt__(self, other):
7171 return True
7272 return self .eta > other .eta
7373
74- @property
75- def orderids (self ):
76- return {l .orderid for l in self ._allocations }
77-
7874 def allocate (self , line : OrderLine ):
7975 if self .can_allocate (line ):
8076 self ._allocations .add (line )
Original file line number Diff line number Diff line change 1+ from allocation .domain import model
12from allocation .service_layer import unit_of_work
23
34
45def allocations (orderid : str , uow : unit_of_work .SqlAlchemyUnitOfWork ):
56 with uow :
6- products = uow .products .for_order (orderid = orderid )
7- batches = [b for p in products for b in p .batches ]
8- return [
9- {"sku" : b .sku , "batchref" : b .reference }
10- for b in batches
11- if orderid in b .orderids
12- ]
7+ batches = (
8+ uow .session .query (model .Batch )
9+ .join (model .OrderLine , model .Batch ._allocations )
10+ .filter (model .OrderLine .orderid == orderid )
11+ )
12+ return [{"sku" : b .sku , "batchref" : b .reference } for b in batches ]
You can’t perform that action at this time.
0 commit comments