File tree Expand file tree Collapse file tree 3 files changed +7
-19
lines changed Expand file tree Collapse file tree 3 files changed +7
-19
lines changed Original file line number Diff line number Diff line change @@ -57,11 +57,3 @@ def _get_by_batchref(self, batchref):
57
57
return self .session .query (model .Product ).join (model .Batch ).filter (
58
58
orm .batches .c .reference == batchref ,
59
59
).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):
73
73
return True
74
74
return self .eta > other .eta
75
75
76
- @property
77
- def orderids (self ):
78
- return {l .orderid for l in self ._allocations }
79
-
80
76
def allocate (self , line : OrderLine ):
81
77
if self .can_allocate (line ):
82
78
self ._allocations .add (line )
Original file line number Diff line number Diff line change
1
+ from allocation .domain import model
1
2
from allocation .service_layer import unit_of_work
2
3
3
4
def allocations (orderid : str , uow : unit_of_work .SqlAlchemyUnitOfWork ):
4
5
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