Skip to content

Commit eb11e04

Browse files
committed
start on handler for change quantity [change_quantity_handler]
1 parent f4b7851 commit eb11e04

2 files changed

Lines changed: 14 additions & 3 deletions

File tree

src/allocation/handlers.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
from __future__ import annotations
2-
import typing
2+
from typing import TYPE_CHECKING
33
from allocation import events, email, exceptions, model
44
from allocation.model import OrderLine
5-
if typing.TYPE_CHECKING:
5+
if TYPE_CHECKING:
66
from allocation import unit_of_work
77

88

9-
109
def add_batch(
1110
event: events.BatchCreated, uow: unit_of_work.AbstractUnitOfWork
1211
):
@@ -34,6 +33,16 @@ def allocate(
3433
return batchref
3534

3635

36+
37+
def change_batch_quantity(
38+
event: events.BatchQuantityChanged, uow: unit_of_work.AbstractUnitOfWork
39+
):
40+
with uow:
41+
product = uow.products.get_by_batchref(batchref=event.ref)
42+
product.change_batch_quantity(ref=event.ref, qty=event.qty)
43+
uow.commit()
44+
45+
3746
# pylint: disable=unused-argument
3847

3948
def send_out_of_stock_notification(

src/allocation/messagebus.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ def handle(event: events.Event, uow: unit_of_work.AbstractUnitOfWork):
1616

1717
HANDLERS = {
1818
events.BatchCreated: [handlers.add_batch],
19+
events.BatchQuantityChanged: [handlers.change_batch_quantity],
1920
events.AllocationRequired: [handlers.allocate],
2021
events.OutOfStock: [handlers.send_out_of_stock_notification],
22+
2123
} # type: Dict[Type[events.Event], List[Callable]]

0 commit comments

Comments
 (0)