Ejemplo n.º 1
0
    def test_changes_available_quantity():
        bus = FakeBus()
        bus.handle([commands.CreateBatch('b1', 'sku1', 100, None)])
        [batch] = bus.uow.products.get(sku='sku1').batches
        assert batch.available_quantity == 100

        bus.handle([commands.ChangeBatchQuantity('b1', 50)])
        assert batch.available_quantity == 50
Ejemplo n.º 2
0
    def test_changes_available_quantity():
        bus = FakeBus()
        bus.handle([commands.CreateBatch("b1", "ADORABLE-SETTEE", 100, None)])
        [batch] = bus.uow.products.get(sku="ADORABLE-SETTEE").batches
        assert batch.available_quantity == 100

        bus.handle([commands.ChangeBatchQuantity("b1", 50)])
        assert batch.available_quantity == 50
Ejemplo n.º 3
0
def test_deallocation(sqlite_bus):
    sqlite_bus.handle(commands.CreateBatch('b1', 'sku1', 50, None))
    sqlite_bus.handle(commands.CreateBatch('b2', 'sku1', 50, date.today()))
    sqlite_bus.handle(commands.Allocate('o1', 'sku1', 40))
    sqlite_bus.handle(commands.ChangeBatchQuantity('b1', 10))

    assert views.allocations('o1', sqlite_bus.uow) == [
        {'sku': 'sku1', 'batchref': 'b2'},
    ]
Ejemplo n.º 4
0
    def test_reallocates_if_necessary():
        bus = FakeBus()
        bus.handle([
            commands.CreateBatch('b1', 'sku1', 50, None),
            commands.CreateBatch('b2', 'sku1', 50, date.today()),
            commands.Allocate('o1', 'sku1', 20),
            commands.Allocate('o2', 'sku1', 20),
        ])
        [batch1, batch2] = bus.uow.products.get(sku='sku1').batches
        assert batch1.available_quantity == 10

        bus.handle([commands.ChangeBatchQuantity('b1', 25)])

        # o1 or o2 will be deallocated, so we'll have 25 - 20 * 1
        assert batch1.available_quantity == 5
        # and 20 will be reallocated to the next batch
        assert batch2.available_quantity == 30
Ejemplo n.º 5
0
    def test_reallocates_if_necessary():
        bus = FakeBus()
        bus.handle([
            commands.CreateBatch("b1", "INDIFFERENT-TABLE", 50, None),
            commands.CreateBatch("b2", "INDIFFERENT-TABLE", 50, date.today()),
            commands.Allocate("o1", "INDIFFERENT-TABLE", 20),
            commands.Allocate("o2", "INDIFFERENT-TABLE", 20),
        ])
        [batch1,
         batch2] = bus.uow.products.get(sku="INDIFFERENT-TABLE").batches
        assert batch1.available_quantity == 10

        bus.handle([commands.ChangeBatchQuantity("b1", 25)])

        # o1 or o2 will be deallocated, so we"ll have 25 - 20 * 1
        assert batch1.available_quantity == 5
        # and 20 will be reallocated to the next batch
        assert batch2.available_quantity == 30
Ejemplo n.º 6
0
def handle_change_batch_quantity(m, bus: messagebus.MessageBus):
    print('handling', m, flush=True)
    data = json.loads(m['data'])
    command = commands.ChangeBatchQuantity(ref=data['batchid'],
                                           qty=data['qty'])
    bus.handle([command])
Ejemplo n.º 7
0
def handle_change_batch_quantity(m, bus: messagebus.MessageBus):
    logger.info('handling %s', m)
    data = json.loads(m['data'])
    cmd = commands.ChangeBatchQuantity(ref=data['batchref'], qty=data['qty'])
    bus.handle(cmd)