Skip to content

Commit cb78b82

Browse files
committed
first cut of a view with raw sql [views_dot_py]
1 parent 1d100f0 commit cb78b82

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/allocation/views.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from allocation.service_layer import unit_of_work
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]

0 commit comments

Comments
 (0)