Skip to content

Commit d1e2e6e

Browse files
committedFeb 24, 2021

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed
 

‎services.py

+22
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)
Please sign in to comment.