Exemple #1
0
def test_prefers_current_stock_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)
    line = OrderLine("oref", "RETRO-CLOCK", 10)
    allocate(line, [in_stock_batch, shipment_batch])
    assert in_stock_batch.available_quantity == 90
    assert shipment_batch.available_quantity == 100
Exemple #2
0
def test_allocate_prefers_warehouse():
    batch_warehouse = Batch(sku="SMALL-TABLE", qty=20)
    batch_shipping = Batch(sku="SMALL-TABLE", qty=20, eta=10)
    order_line = OrderLine(ref="bla", sku="SMALL-TABLE", qty=20)
    allocate(order_line, [batch_shipping, batch_warehouse])

    assert batch_warehouse.qty == 0
    assert batch_shipping.qty == 20
Exemple #3
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)
    line = OrderLine("order1", "MINIMALIST-SPOON", 10)
    allocate(line, [medium, earliest, latest])
    assert earliest.available_quantity == 90
    assert medium.available_quantity == 100
    assert latest.available_quantity == 100
Exemple #4
0
def test_allocate_quickest_warehouse():
    batch_warehouse_slow = Batch(sku="SMALL-TABLE", qty=20, eta=10)
    batch_shipping_unavaiable = Batch(sku="SMALL-TABLE", qty=2, eta=1)
    batch_shipping_ok = Batch(sku="SMALL-TABLE", qty=20, eta=5)
    order_line = OrderLine(ref="bla", sku="SMALL-TABLE", qty=20)
    allocate(
        order_line, [batch_warehouse_slow, batch_shipping_unavaiable, batch_shipping_ok]
    )
    assert batch_warehouse_slow.qty == 20
    assert batch_shipping_unavaiable.qty == 2
    assert batch_shipping_ok.qty == 0
Exemple #5
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)
    allocation = allocate(line, [in_stock_batch, shipment_batch])
    assert allocation == in_stock_batch.reference
Exemple #6
0
def test_allocation():
    batch = Batch(sku="SMALL-TABLE", qty=20)
    order_line = OrderLine(sku="SMALL-TABLE", qty=2, ref="some order")
    allocate(order_line, batch)
    assert batch.qty == 18
Exemple #7
0
def test_cant_allocate_twice():
    batch = Batch(sku="SMALL-TABLE", qty=20)
    order_line = OrderLine(ref="some orderline", sku="SMALL-TABLE", qty=2)
    allocate(order_line, batch)
    allocate(order_line, batch)
    assert batch.qty == 18
Exemple #8
0
def test_allocation_not_enough():
    batch = Batch(sku="BLUE-CUSHION", qty=1)
    order_line = OrderLine(sku="BLUE-CUSHION", qty=2, ref="some order")
    allocate(order_line, batch)
    assert batch.qty == 1
Exemple #9
0
def test_raises_out_of_stock_exception_if_cannot_allocate():
    batch = Batch('batch1', 'SMALL-FORK', 10, eta=today)
    allocate(OrderLine('order1', 'SMALL-FORK', 10), [batch])
    with pytest.raises(OutOfStock, match='SMALL-FORK'):
        allocate(OrderLine('order2', 'SMALL-FORK', 1), [batch])