Skip to content

Commit d0d72ae

Browse files
committed
first cut of a product with a version number
1 parent d77ebf3 commit d0d72ae

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/allocation/model.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,18 @@ class OutOfStock(Exception):
1010

1111
class Product:
1212

13-
def __init__(self, sku: str, batches: List[Batch]):
13+
def __init__(self, sku: str, batches: List[Batch], version_number: int = 0):
1414
self.sku = sku
1515
self.batches = batches
16+
self.version_number = version_number
1617

1718
def allocate(self, line: OrderLine) -> str:
1819
try:
1920
batch = next(
2021
b for b in sorted(self.batches) if b.can_allocate(line)
2122
)
2223
batch.allocate(line)
24+
self.version_number += 1
2325
return batch.reference
2426
except StopIteration:
2527
raise OutOfStock(f'Out of stock for sku {line.sku}')

tests/unit/test_product.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,11 @@ def test_raises_out_of_stock_exception_if_cannot_allocate():
4848

4949
with pytest.raises(OutOfStock, match='SMALL-FORK'):
5050
product.allocate(OrderLine('order2', 'SMALL-FORK', 1))
51+
52+
53+
def test_increments_version_number():
54+
line = OrderLine('oref', "SCANDI-PEN", 10)
55+
product = Product(sku="SCANDI-PEN", batches=[Batch('b1', "SCANDI-PEN", 100, eta=None)])
56+
product.version_number = 7
57+
product.allocate(line)
58+
assert product.version_number == 8

0 commit comments

Comments
 (0)