File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 22from dataclasses import dataclass
33from datetime import date
44from typing import Optional , List , Set
5- from allocation .adapters import email
65
76
87class OutOfStock (Exception ):
@@ -25,7 +24,6 @@ def allocate(self, line: OrderLine) -> str:
2524 self .version_number += 1
2625 return batch .reference
2726 except StopIteration :
28- email .send_mail ('stock@made.com' , f'Out of stock for { line .sku } ' )
2927 raise OutOfStock (f'Out of stock for sku { line .sku } ' )
3028
3129
@@ -82,4 +80,3 @@ def available_quantity(self) -> int:
8280
8381 def can_allocate (self , line : OrderLine ) -> bool :
8482 return self .sku == line .sku and self .available_quantity >= line .qty
85-
Original file line number Diff line number Diff line change 22from typing import Optional
33from datetime import date
44
5+ from allocation .adapters import email
56from allocation .domain import model
67from allocation .domain .model import OrderLine
78from allocation .service_layer import unit_of_work
@@ -33,6 +34,10 @@ def allocate(
3334 product = uow .products .get (sku = line .sku )
3435 if product is None :
3536 raise InvalidSku (f'Invalid sku { line .sku } ' )
36- batchref = product .allocate (line )
37- uow .commit ()
38- return batchref
37+ try :
38+ batchref = product .allocate (line )
39+ uow .commit ()
40+ return batchref
41+ except model .OutOfStock :
42+ email .send_mail ('stock@made.com' , f'Out of stock for { line .sku } ' )
43+ raise
You can’t perform that action at this time.
0 commit comments