We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 43c2df7 commit ccbaa5aCopy full SHA for ccbaa5a
src/allocation/views.py
@@ -2,12 +2,10 @@
2
3
def allocations(orderid: str, uow: unit_of_work.SqlAlchemyUnitOfWork):
4
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]
+ products = uow.products.for_order(orderid=orderid)
+ batches = [b for p in products for b in p.batches]
+ return [
+ {'sku': b.sku, 'batchref': b.reference}
+ for b in batches
+ if orderid in b.orderids
+ ]
0 commit comments