We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent d75eaf7 commit 184d90dCopy full SHA for 184d90d
model.py
@@ -4,10 +4,17 @@
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)
- return batch.reference
12
+ try:
13
+ batch = next(b for b in sorted(batches) if b.can_allocate(line))
14
+ batch.allocate(line)
15
+ return batch.reference
16
+ except StopIteration:
17
+ raise OutOfStock(f"Out of stock for sku {line.sku}")
18
19
20
@dataclass(frozen=True)
0 commit comments