Skip to content

Commit da05078

Browse files
committed
use repository and go via Product [view_using_repo]
1 parent e535570 commit da05078

File tree

1 file changed

+7
-11
lines changed

1 file changed

+7
-11
lines changed

src/allocation/views.py

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,10 @@
33

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

0 commit comments

Comments
 (0)