File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -57,11 +57,3 @@ def _get_by_batchref(self, batchref):
5757 return self .session .query (model .Product ).join (model .Batch ).filter (
5858 orm .batches .c .reference == batchref ,
5959 ).first ()
60-
61-
62- def for_order (self , orderid ):
63- order_lines = self .session .query (model .OrderLine ).filter_by (orderid = orderid )
64- skus = {l .sku for l in order_lines }
65- return self .session .query (model .Product ).join (model .Batch ).filter (
66- model .Batch .sku .in_ (skus )
67- )
Original file line number Diff line number Diff line change @@ -73,10 +73,6 @@ def __gt__(self, other):
7373 return True
7474 return self .eta > other .eta
7575
76- @property
77- def orderids (self ):
78- return {l .orderid for l in self ._allocations }
79-
8076 def allocate (self , line : OrderLine ):
8177 if self .can_allocate (line ):
8278 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
34def allocations (orderid : str , uow : unit_of_work .SqlAlchemyUnitOfWork ):
45 with uow :
5- products = uow .products .for_order (orderid = orderid )
6- batches = [b for p in products for b in p .batches ]
7- return [
8- {'sku' : b .sku , 'batchref' : b .reference }
9- for b in batches
10- if orderid in b .orderids
11- ]
6+ batches = uow .session .query (model .Batch ).join (
7+ model .OrderLine , model .Batch ._allocations
8+ ).filter (
9+ model .OrderLine .orderid == orderid
10+ )
11+ return [{'sku' : b .sku , 'batchref' : b .reference } for b in batches ]
You can’t perform that action at this time.
0 commit comments