Skip to content

Commit f63f7a5

Browse files
committed
first cut of a view with raw sql [views_dot_py]
1 parent 0866c72 commit f63f7a5

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/allocation/views.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from allocation.service_layer import unit_of_work
2+
3+
4+
def allocations(orderid: str, uow: unit_of_work.SqlAlchemyUnitOfWork):
5+
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]

0 commit comments

Comments
 (0)