Skip to content

Commit 27aadfd

Browse files
committed
raising out of stock exception [out_of_stock]
1 parent d82358c commit 27aadfd

1 file changed

Lines changed: 12 additions & 5 deletions

File tree

model.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,19 @@
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(
9-
b for b in sorted(batches) if b.can_allocate(line)
10-
)
11-
batch.allocate(line)
12-
return batch.reference
12+
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}')
1320

1421

1522
@dataclass(frozen=True)

0 commit comments

Comments
 (0)