1 parent eded7eb commit d1e2e6eCopy full SHA for d1e2e6e
1 file changed
services.py
@@ -0,0 +1,22 @@
1
+from __future__ import annotations
2
+
3
+import model
4
+from model import OrderLine
5
+from repository import AbstractRepository
6
7
8
+class InvalidSku(Exception):
9
+ pass
10
11
12
+def is_valid_sku(sku, batches):
13
+ return sku in {b.sku for b in batches}
14
15
16
+def allocate(line: OrderLine, repo: AbstractRepository, session) -> str:
17
+ batches = repo.list()
18
+ if not is_valid_sku(line.sku, batches):
19
+ raise InvalidSku(f"Invalid sku {line.sku}")
20
+ batchref = model.allocate(line, batches)
21
+ session.commit()
22
+ return batchref
0 commit comments