1 parent d82358c commit 27aadfdCopy full SHA for 27aadfd
1 file changed
model.py
@@ -4,12 +4,19 @@
4
from typing import Optional, List, Set
5
6
7
+class OutOfStock(Exception):
8
+ pass
9
+
10
11
def allocate(line: OrderLine, batches: List[Batch]) -> str:
- batch = next(
- b for b in sorted(batches) if b.can_allocate(line)
- )
- batch.allocate(line)
12
- return batch.reference
+ try:
13
+ batch = next(
14
+ b for b in sorted(batches) if b.can_allocate(line)
15
+ )
16
+ batch.allocate(line)
17
+ return batch.reference
18
+ except StopIteration:
19
+ raise OutOfStock(f'Out of stock for sku {line.sku}')
20
21
22
@dataclass(frozen=True)
0 commit comments