Skip to content

Commit 08cb29f

Browse files
committed
putting it in the services layer isn't lovely either [email_in_services]
1 parent eb91a6e commit 08cb29f

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

src/allocation/model.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
from datetime import date
44
from typing import Optional, List, Set
55
from allocation import exceptions
6-
from allocation import email
76

87

98
class Product:
@@ -22,7 +21,6 @@ def allocate(self, line: OrderLine) -> str:
2221
self.version_number += 1
2322
return batch.reference
2423
except StopIteration:
25-
email.send_mail('stock@made.com', f'Out of stock for {line.sku}')
2624
raise exceptions.OutOfStock(f'Out of stock for sku {line.sku}')
2725

2826

src/allocation/services.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from typing import Optional
33
from datetime import date
44

5-
from allocation import exceptions, model, unit_of_work
5+
from allocation import email, exceptions, model, unit_of_work
66
from allocation.model import OrderLine
77

88

@@ -28,6 +28,10 @@ def allocate(
2828
product = uow.products.get(sku=line.sku)
2929
if product is None:
3030
raise exceptions.InvalidSku(f'Invalid sku {line.sku}')
31-
batchref = product.allocate(line)
32-
uow.commit()
33-
return batchref
31+
try:
32+
batchref = product.allocate(line)
33+
uow.commit()
34+
return batchref
35+
except exceptions.OutOfStock:
36+
email.send_mail('stock@made.com', f'Out of stock for {line.sku}')
37+
raise

0 commit comments

Comments
 (0)