Skip to content

Commit 184d90d

Browse files
committed
raising out of stock exception [out_of_stock]
1 parent d75eaf7 commit 184d90d

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

model.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,17 @@
44
from typing import Optional, List, Set
55

66

7+
class OutOfStock(Exception):
8+
pass
9+
10+
711
def allocate(line: OrderLine, batches: List[Batch]) -> str:
8-
batch = next(b for b in sorted(batches) if b.can_allocate(line))
9-
batch.allocate(line)
10-
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}")
1118

1219

1320
@dataclass(frozen=True)

0 commit comments

Comments
 (0)