def reallocate( event: events.Deallocated, uow: unit_of_work.AbstractUnitOfWork ): with uow: product = uow.products.get(sku=event.sku) product.events.append(commands.Allocate(**asdict(event))) uow.commit()
def change_batch_quantity( cmd: commands.ChangeBatchQuantity, uow: unit_of_work.AbstractUnitOfWork ): with uow: product = uow.products.get_by_batchref(batchref=cmd.ref) product.change_batch_quantity(ref=cmd.ref, qty=cmd.qty) uow.commit()
def change_batch_quantity( event: commands.ChangeBatchQuantity, uow: unit_of_work.AbstractUnitOfWork ): with uow: product = uow.products.get_by_batchid(batchid=event.ref) product.change_batch_quantity(ref=event.ref, qty=event.qty) uow.commit()
def allocate(cmd: commands.Allocate, uow: unit_of_work.AbstractUnitOfWork): line = OrderLine(cmd.orderid, cmd.sku, cmd.qty) with uow: product = uow.products.get(sku=line.sku) if product is None: raise exceptions.InvalidSku(f'Invalid sku {line.sku}') product.allocate(line) uow.commit()
def add_batch(cmd: commands.CreateBatch, uow: unit_of_work.AbstractUnitOfWork): with uow: product = uow.products.get(sku=cmd.sku) if product is None: product = model.Product(cmd.sku, batches=[]) uow.products.add(product) product.batches.append(model.Batch(cmd.ref, cmd.sku, cmd.qty, cmd.eta)) uow.commit()