Skip to content

Commit d1e2e6e

Browse files
committed
services layer with valid-sku check [service_function]
1 parent eded7eb commit d1e2e6e

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

services.py

Lines changed: 22 additions & 0 deletions
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)