Consider the following scenario:
class Order:
def __init__(self):
self.lines = []
def order(self, product_id, amount, price, discount=None):
item = OrderItem(product_id, amount, price)
self.lines.append(item)
class OrderItem:
def __init__(self, product_id, amount, price, discount=None):
self.product_id = product_id
self.amount = amount
self.price = price
self.discount = discount or decimal.Decimal(0)
def discount(self, amount):
self.discount = discount
In the scenario that we want to add a discount to a specific line item, after the Order aggregate has been created, do I need to get the OrderItem entity from the aggregate, or expose a method on the aggregate?
E.g.
class Order:
...
def discount_item(self, index, amount):
self.lines[index].discount(amount)
And if I can invoke the OrderItem.discount() directly -- how do I keep track of the domain events published as a result of that?
Aucun commentaire:
Enregistrer un commentaire