Exemple #1
0
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()
Exemple #2
0
def add_batch(
        ref: str, sku: str, qty: int, eta: Optional[date],
        uow: unit_of_work.AbstractUnitOfWork
):
    with uow:
        uow.batches.add(model.Batch(ref, sku, qty, eta))
        uow.commit()
Exemple #3
0
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 InvalidSku(f'Invalid sku {line.sku}')
        product.allocate(line)
        uow.commit()
Exemple #4
0
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()
Exemple #5
0
def add_batch(ref: str, sku: str, qty: int, eta: Optional[date],
              uow: unit_of_work.AbstractUnitOfWork):
    with uow:
        product = uow.products.get(sku=sku)
        if product is None:
            product = model.Product(sku, batches=[])
            uow.products.add(product)
        product.batches.append(model.Batch(ref, sku, qty, eta))
        uow.commit()
Exemple #6
0
def allocate(orderid: str, sku: str, qty: int,
             uow: unit_of_work.AbstractUnitOfWork) -> str:
    line = OrderLine(orderid, sku, qty)
    with uow:
        product = uow.products.get(sku=line.sku)
        if product is None:
            raise InvalidSku(f'Invalid sku {line.sku}')
        batchref = product.allocate(line)
        uow.commit()
    return batchref
def allocate(orderid: str, sku: str, qty: int,
             uow: unit_of_work.AbstractUnitOfWork) -> str:
    line = model.OrderLine(orderid, sku, qty)
    with uow:
        batches = uow.batches.list()
        if not is_valid_sku(sku, batches):
            raise InvalidSku(f"Invalid sku {sku}")
        batchref = model.allocate(line, batches)
        uow.commit()
    return batchref
Exemple #8
0
def change_batch_quantity(
    message: commands.ChangeBatchQuantity, uow: unit_of_work.AbstractUnitOfWork
):
    with uow:
        product = uow.products.get_by_batch_reference(
            reference=message.reference
        )
        product.change_batch_quantity(
            reference=message.reference, qty=message.qty
        )
        uow.commit()
Exemple #9
0
def deallocate(
    message: commands.Deallocate, uow: unit_of_work.AbstractUnitOfWork
) -> None:
    line = model.OrderLine(message.orderid, message.sku, message.qty)
    with uow:
        product = uow.products.get(sku=message.sku)

        if product is None:
            raise InvalidSku(f"Invalid sku {line.sku}")

        product.deallocate(line)
        uow.commit()
Exemple #10
0
def remove_allocation_from_read_model(
    message: events.Deallocated, uow: unit_of_work.AbstractUnitOfWork
):
    with uow:
        uow.session.execute(
            "DELETE FROM allocations_view"
            " WHERE orderid = :orderid AND sku = :sku",
            {
                "orderid": message.orderid,
                "sku": message.sku,
            },
        )
        uow.commit()
Exemple #11
0
def add_batch(
    message: commands.CreateBatch, uow: unit_of_work.AbstractUnitOfWork
):
    sku = message.sku
    batch = model.Batch(
        message.reference, message.sku, message.qty, message.eta
    )
    with uow:
        product = uow.products.get(sku=sku)
        if product is None:
            product = model.Product(sku, [])
            uow.products.add(product)
        product.batches.append(batch)
        uow.commit()
Exemple #12
0
def add_allocation_to_read_model(
    message: events.Allocated, uow: unit_of_work.AbstractUnitOfWork
):
    with uow:
        uow.session.execute(
            "INSERT INTO allocations_view (orderid, sku, qty, batchref)"
            " VALUES (:orderid, :sku, :qty, :batchref)",
            {
                "orderid": message.orderid,
                "sku": message.sku,
                "qty": message.qty,
                "batchref": message.batchref,
            },
        )
        uow.commit()