Skip to content

Commit ccbaa5a

Browse files
committed
use repository and go via Product [view_using_repo]
1 parent 43c2df7 commit ccbaa5a

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

src/allocation/views.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,10 @@
22

33
def allocations(orderid: str, uow: unit_of_work.SqlAlchemyUnitOfWork):
44
with uow:
5-
results = list(uow.session.execute(
6-
'SELECT ol.sku, b.reference'
7-
' FROM allocations AS a'
8-
' JOIN batches AS b ON a.batch_id = b.id'
9-
' JOIN order_lines AS ol ON a.orderline_id = ol.id'
10-
' WHERE ol.orderid = :orderid',
11-
dict(orderid=orderid)
12-
))
13-
return [{'sku': sku, 'batchref': batchref} for sku, batchref in results]
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+
]

0 commit comments

Comments
 (0)