Skip to content

Commit 48cb8b9

Browse files
committed
first cut of a product with a version number
1 parent aa4bad7 commit 48cb8b9

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/allocation/domain/model.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,16 @@ class OutOfStock(Exception):
99

1010

1111
class Product:
12-
def __init__(self, sku: str, batches: List[Batch]):
12+
def __init__(self, sku: str, batches: List[Batch], version_number: int = 0):
1313
self.sku = sku
1414
self.batches = batches
15+
self.version_number = version_number
1516

1617
def allocate(self, line: OrderLine) -> str:
1718
try:
1819
batch = next(b for b in sorted(self.batches) if b.can_allocate(line))
1920
batch.allocate(line)
21+
self.version_number += 1
2022
return batch.reference
2123
except StopIteration:
2224
raise OutOfStock(f"Out of stock for sku {line.sku}")

tests/unit/test_product.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,13 @@ def test_raises_out_of_stock_exception_if_cannot_allocate():
4949

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

0 commit comments

Comments
 (0)