Skip to content

Commit 8e6162a

Browse files
committed
services layer with valid-sku check [service_function]
1 parent 58d21bf commit 8e6162a

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

‎services.py‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
from __future__ import annotations
2+
3+
import model
4+
from model import OrderLine
5+
from repository import AbstractRepository
6+
7+
class InvalidSku(Exception):
8+
pass
9+
10+
11+
def is_valid_sku(sku, batches):
12+
return sku in {b.sku for b in batches}
13+
14+
def allocate(line: OrderLine, repo: AbstractRepository, session) -> str:
15+
batches = repo.list()
16+
if not is_valid_sku(line.sku, batches):
17+
raise InvalidSku(f'Invalid sku {line.sku}')
18+
batchref = model.allocate(line, batches)
19+
session.commit()
20+
return batchref

0 commit comments

Comments
 (0)