コード例 #1
0
def test_returns_allocated_batch_id():
    warehouse_batch = Batch('wh-batch', 'sku1', 100, eta=None)
    shipment_batch = Batch('sh-batch', 'sku1', 100, eta=tomorrow)
    line = OrderLine('oref', 'sku1', 10)
    product = Product(sku='sku1', batches=[warehouse_batch, shipment_batch])
    allocation = product.allocate(line, )
    assert allocation == 'wh-batch'
コード例 #2
0
def test_returns_allocated_batch_ref():
    in_stock_batch = Batch("in-stock-batch-ref", "HIGHBROW-POSTER", 100, eta=None)
    shipment_batch = Batch("shipment-batch-ref", "HIGHBROW-POSTER", 100, eta=tomorrow)
    line = OrderLine("oref", "HIGHBROW-POSTER", 10)
    product = Product(sku="HIGHBROW-POSTER", batches=[in_stock_batch, shipment_batch])
    allocation = product.allocate(line)
    assert allocation == in_stock_batch.reference
コード例 #3
0
def test_increments_version_number():
    line = OrderLine('oref', "SCANDI-PEN", 10)
    product = Product(sku="SCANDI-PEN",
                      batches=[Batch('b1', "SCANDI-PEN", 100, eta=None)])
    product.version_number = 7
    product.allocate(line)
    assert product.version_number == 8
コード例 #4
0
def test_records_out_of_stock_event_if_cannot_allocate():
    batch = Batch("batch1", "HEAVY-SPOON", 100, eta=today)
    different_sku_line = OrderLine("oref", "SMALL-FORK", 10)
    product = Product(sku="HEAVY-SPOON", batches=[batch])

    allocation = product.allocate(different_sku_line)
    assert product.events[-1] == events.OutOfStock(sku="SMALL-FORK")
    assert allocation is None
コード例 #5
0
def test_records_out_of_stock_event_if_cannot_allocate():
    batch = Batch('batch1', 'SMALL-FORK', 10, eta=today)
    product = Product(sku="SMALL-FORK", batches=[batch])
    product.allocate(OrderLine('order1', 'SMALL-FORK', 10))

    allocation = product.allocate(OrderLine('order2', 'SMALL-FORK', 1))
    assert product.events[-1] == events.OutOfStock(sku="SMALL-FORK")
    assert allocation is None
コード例 #6
0
def test_records_out_of_stock_event_if_cannot_allocate():
    sku1_batch = Batch('batch1', 'sku1', 100, eta=today)
    sku2_line = OrderLine('oref', 'sku2', 10)
    product = Product(sku='sku1', batches=[sku1_batch])

    allocation = product.allocate(sku2_line)
    assert product.events[-1] == events.OutOfStock(sku='sku2')
    assert allocation is None
コード例 #7
0
def test_outputs_allocated_event():
    batch = Batch("batchref", "RETRO-LAMPSHADE", 100, eta=None)
    line = OrderLine("oref", "RETRO-LAMPSHADE", 10)
    product = Product(sku="RETRO-LAMPSHADE", batches=[batch])
    product.allocate(line)
    expected = events.Allocated(
        orderid="oref", sku="RETRO-LAMPSHADE", qty=10, batchref=batch.reference
    )
    assert product.events[-1] == expected
コード例 #8
0
def test_prefers_warehouse_batches_to_shipments():
    in_stock_batch = Batch("in-stock-batch", "RETRO-CLOCK", 100, eta=None)
    shipment_batch = Batch("shipment-batch", "RETRO-CLOCK", 100, eta=tomorrow)
    product = Product(sku="RETRO-CLOCK", batches=[in_stock_batch, shipment_batch])
    line = OrderLine("oref", "RETRO-CLOCK", 10)

    product.allocate(line)

    assert in_stock_batch.available_quantity == 90
    assert shipment_batch.available_quantity == 100
コード例 #9
0
def test_prefers_warehouse_batches_to_shipments():
    warehouse_batch = Batch('wh-batch', 'sku1', 100, eta=None)
    shipment_batch = Batch('sh-batch', 'sku1', 100, eta=tomorrow)
    product = Product(sku='sku1', batches=[warehouse_batch, shipment_batch])
    line = OrderLine('oref', 'sku1', 10)

    product.allocate(line)

    assert warehouse_batch.available_quantity == 90
    assert shipment_batch.available_quantity == 100
コード例 #10
0
def test_prefers_earlier_batches():
    earliest = Batch("speedy-batch", "MINIMALIST-SPOON", 100, eta=today)
    medium = Batch("normal-batch", "MINIMALIST-SPOON", 100, eta=tomorrow)
    latest = Batch("slow-batch", "MINIMALIST-SPOON", 100, eta=later)
    product = Product(sku="MINIMALIST-SPOON", batches=[medium, earliest, latest])
    line = OrderLine("order1", "MINIMALIST-SPOON", 10)

    product.allocate(line)

    assert earliest.available_quantity == 90
    assert medium.available_quantity == 100
    assert latest.available_quantity == 100
コード例 #11
0
def test_prefers_earlier_batches():
    earliest = Batch('sh-batch', 'sku1', 100, eta=today)
    medium = Batch('sh-batch', 'sku1', 100, eta=tomorrow)
    latest = Batch('sh-batch', 'sku1', 100, eta=later)
    product = Product(sku='sku1', batches=[medium, earliest, latest])
    line = OrderLine('oref', 'sku1', 10)

    product.allocate(line)

    assert earliest.available_quantity == 90
    assert medium.available_quantity == 100
    assert latest.available_quantity == 100