|
| 1 | +from datetime import date, timedelta |
| 2 | +from model import allocate, OrderLine, Batch |
| 3 | + |
| 4 | +today = date.today() |
| 5 | +tomorrow = today + timedelta(days=1) |
| 6 | +later = tomorrow + timedelta(days=10) |
| 7 | + |
| 8 | + |
| 9 | +def test_prefers_current_stock_batches_to_shipments(): |
| 10 | + in_stock_batch = Batch("in-warehouse-stock", "RETRO-CLOCK", 100, eta=None) |
| 11 | + shipment_batch = Batch("shipment-batch", "RETRO-CLOCK", 100, eta=tomorrow) |
| 12 | + line = OrderLine("oref", "RETRO-CLOCK", 10) |
| 13 | + |
| 14 | + allocate(line, [in_stock_batch, shipment_batch]) |
| 15 | + |
| 16 | + assert in_stock_batch.available_quantity == 90 |
| 17 | + assert shipment_batch.available_quantity == 100 |
| 18 | + |
| 19 | + |
| 20 | +def test_prefers_earlier_batches(): |
| 21 | + earliest = Batch("speedy-batch", "MINIMALIST-SPOON", 100, eta=today) |
| 22 | + medium = Batch("normal-batch", "MINIMALIST-SPOON", 100, eta=tomorrow) |
| 23 | + latest = Batch("slow-batch", "MINIMALIST-SPOON", 100, eta=later) |
| 24 | + line = OrderLine("order1", "MINIMALIST-SPOON", 10) |
| 25 | + |
| 26 | + allocate(line, [medium, earliest, latest]) |
| 27 | + |
| 28 | + assert earliest.available_quantity == 90 |
| 29 | + assert medium.available_quantity == 100 |
| 30 | + assert latest.available_quantity == 100 |
0 commit comments