Skip to content

Commit a80c0e0

Browse files
committed
s/stock/warehouse/
1 parent db17106 commit a80c0e0

2 files changed

Lines changed: 54 additions & 54 deletions

File tree

‎domain_model.py‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@ def quantities(self):
2828
@dataclass
2929
class Order(SkuLines):
3030

31-
def allocate(self, stock, shipments):
32-
self.allocation = Allocation.for_order(self, stock, shipments)
31+
def allocate(self, warehouse, shipments):
32+
self.allocation = Allocation.for_order(self, warehouse, shipments)
3333
self.allocation.decrement_source_quantities()
3434

3535

3636
@dataclass
37-
class Stock(SkuLines):
37+
class Warehouse(SkuLines):
3838

3939
def can_allocate(self, line: OrderLine):
4040
return line.sku in self.skus and self.quantities[line.sku] > line.quantity
@@ -44,11 +44,11 @@ def decrement_quantity(self, sku, quantity):
4444
if line.sku == sku:
4545
line.quantity -= quantity
4646
return
47-
raise Exception(f'sku {sku} not found in stock skus ({self.skus})')
47+
raise Exception(f'sku {sku} not found in warehouse skus ({self.skus})')
4848

4949

5050
@dataclass
51-
class Shipment(Stock):
51+
class Shipment(Warehouse):
5252
eta: date = None
5353

5454
def __lt__(self, other):
@@ -59,7 +59,7 @@ def __lt__(self, other):
5959
class AllocationLine:
6060
sku: str
6161
quantity: int
62-
source: Stock
62+
source: Warehouse
6363

6464
def decrement_source_quantity(self):
6565
self.source.decrement_quantity(self.sku, self.quantity)
@@ -79,17 +79,17 @@ def sources(self):
7979
return {l.sku: l.source for l in self.lines}
8080

8181
@staticmethod
82-
def for_source(order: Order, source: Stock):
82+
def for_source(order: Order, source: Warehouse):
8383
return Allocation(lines=[
8484
AllocationLine(sku=line.sku, quantity=line.quantity, source=source)
8585
for line in order.lines
8686
if source.can_allocate(line)
8787
], order=order)
8888

8989
@staticmethod
90-
def for_order(order: Order, stock: Stock, shipments: List[Shipment]):
90+
def for_order(order: Order, warehouse: Warehouse, shipments: List[Shipment]):
9191
allocation = Allocation(lines=[], order=order)
92-
for source in [stock] + sorted(shipments):
92+
for source in [warehouse] + sorted(shipments):
9393
source_allocation = Allocation.for_source(order, source)
9494
allocation.supplement_with(source_allocation)
9595
return allocation

‎test_allocation.py‎

Lines changed: 45 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -6,39 +6,39 @@
66
later = tomorrow + timedelta(days=10)
77

88
Order = lambda d: domain_model.Order(lines=[domain_model.OrderLine(sku, qty) for sku, qty in d.items()])
9-
Stock = lambda d: domain_model.Stock(lines=[domain_model.OrderLine(sku, qty) for sku, qty in d.items()])
9+
Warehouse = lambda d: domain_model.Warehouse(lines=[domain_model.OrderLine(sku, qty) for sku, qty in d.items()])
1010
Shipment = lambda d, eta: domain_model.Shipment(
1111
lines=[domain_model.OrderLine(sku, qty) for sku, qty in d.items()],
1212
eta=eta,
1313
)
1414

1515

16-
def test_can_allocate_to_stock():
16+
def test_can_allocate_to_warehouse():
1717
order = Order({'a-sku': 10})
18-
stock = Stock({'a-sku': 1000})
18+
warehouse = Warehouse({'a-sku': 1000})
1919

20-
order.allocate(stock, shipments=[])
20+
order.allocate(warehouse, shipments=[])
2121

22-
assert order.allocation.sources['a-sku'] == stock
23-
assert stock.quantities['a-sku'] == 990
22+
assert order.allocation.sources['a-sku'] == warehouse
23+
assert warehouse.quantities['a-sku'] == 990
2424

2525

2626
def test_can_allocate_to_shipment():
2727
order = Order({'a-sku': 10})
2828
shipment = Shipment({'a-sku': 1000}, eta=tomorrow)
2929

30-
order.allocate(stock=Stock({}), shipments=[shipment])
30+
order.allocate(warehouse=Warehouse({}), shipments=[shipment])
3131

3232
assert order.allocation.sources['a-sku'] == shipment
3333
assert shipment.quantities['a-sku'] == 990
3434

3535

36-
def test_ignores_irrelevant_stock():
36+
def test_ignores_irrelevant_warehouse():
3737
order = Order({'sku1': 10})
38-
stock = Stock({'sku2': 1000})
38+
warehouse = Warehouse({'sku2': 1000})
3939
shipment = Shipment({'sku1': 1000}, eta=tomorrow)
4040

41-
order.allocate(stock=stock, shipments=[shipment])
41+
order.allocate(warehouse=warehouse, shipments=[shipment])
4242

4343
assert order.allocation.sources['sku1'] == shipment
4444

@@ -49,39 +49,39 @@ def test_can_allocate_to_correct_shipment():
4949
shipment1 = Shipment({'sku1': 1000}, eta=tomorrow)
5050
shipment2 = Shipment({'sku2': 1000}, eta=tomorrow)
5151

52-
order.allocate(stock=Stock({}), shipments=[shipment1, shipment2])
52+
order.allocate(warehouse=Warehouse({}), shipments=[shipment1, shipment2])
5353

5454
assert order.allocation.sources['sku2'] == shipment2
5555

5656

57-
def test_allocates_to_stock_in_preference_to_shipment():
57+
def test_allocates_to_warehouse_in_preference_to_shipment():
5858
order = Order({'sku1': 10})
59-
stock = Stock({'sku1': 1000})
59+
warehouse = Warehouse({'sku1': 1000})
6060
shipment = Shipment({'sku1': 1000}, eta=tomorrow)
6161

62-
order.allocate(stock, shipments=[shipment])
62+
order.allocate(warehouse, shipments=[shipment])
6363

64-
assert order.allocation.sources['sku1'] == stock
65-
assert stock.quantities['sku1'] == 990
64+
assert order.allocation.sources['sku1'] == warehouse
65+
assert warehouse.quantities['sku1'] == 990
6666
assert shipment.quantities['sku1'] == 1000
6767

6868

6969
def test_can_allocate_multiple_lines_to_wh():
7070
order = Order({'sku1': 5, 'sku2': 10})
71-
stock = Stock({'sku1': 1000, 'sku2': 1000})
71+
warehouse = Warehouse({'sku1': 1000, 'sku2': 1000})
7272

73-
order.allocate(stock, shipments=[])
74-
assert order.allocation.sources['sku1'] == stock
75-
assert order.allocation.sources['sku2'] == stock
76-
assert stock.quantities['sku1'] == 995
77-
assert stock.quantities['sku2'] == 990
73+
order.allocate(warehouse, shipments=[])
74+
assert order.allocation.sources['sku1'] == warehouse
75+
assert order.allocation.sources['sku2'] == warehouse
76+
assert warehouse.quantities['sku1'] == 995
77+
assert warehouse.quantities['sku2'] == 990
7878

7979

8080
def test_can_allocate_multiple_lines_to_shipment():
8181
order = Order({'sku1': 5, 'sku2': 10})
8282
shipment = Shipment({'sku1': 1000, 'sku2': 1000}, eta=tomorrow)
8383

84-
order.allocate(stock=Stock({}), shipments=[shipment])
84+
order.allocate(warehouse=Warehouse({}), shipments=[shipment])
8585

8686
assert order.allocation.sources['sku1'] == shipment
8787
assert order.allocation.sources['sku2'] == shipment
@@ -92,41 +92,41 @@ def test_can_allocate_multiple_lines_to_shipment():
9292
def test_can_allocate_to_both():
9393
order = Order({'sku1': 5, 'sku2': 10})
9494
shipment = Shipment({'sku2': 1000}, eta=tomorrow)
95-
stock = Stock({'sku1': 1000})
95+
warehouse = Warehouse({'sku1': 1000})
9696

97-
order.allocate(stock, shipments=[shipment])
97+
order.allocate(warehouse, shipments=[shipment])
9898

99-
assert order.allocation.sources['sku1'] == stock
99+
assert order.allocation.sources['sku1'] == warehouse
100100
assert order.allocation.sources['sku2'] == shipment
101-
assert stock.quantities['sku1'] == 995
101+
assert warehouse.quantities['sku1'] == 995
102102
assert shipment.quantities['sku2'] == 990
103103

104104

105-
def test_can_allocate_to_both_preferring_stock():
105+
def test_can_allocate_to_both_preferring_warehouse():
106106
order = Order({'sku1': 1, 'sku2': 2, 'sku3': 3, 'sku4': 4})
107107
shipment = Shipment({'sku1': 1000, 'sku2': 1000, 'sku3': 1000}, eta=tomorrow)
108-
stock = Stock({'sku3': 1000, 'sku4': 1000})
108+
warehouse = Warehouse({'sku3': 1000, 'sku4': 1000})
109109

110-
order.allocate(stock, shipments=[shipment])
110+
order.allocate(warehouse, shipments=[shipment])
111111

112112
assert order.allocation.sources['sku1'] == shipment
113113
assert order.allocation.sources['sku2'] == shipment
114-
assert order.allocation.sources['sku3'] == stock
115-
assert order.allocation.sources['sku4'] == stock
114+
assert order.allocation.sources['sku3'] == warehouse
115+
assert order.allocation.sources['sku4'] == warehouse
116116
assert shipment.quantities['sku1'] == 999
117117
assert shipment.quantities['sku2'] == 998
118118
assert shipment.quantities['sku3'] == 1000
119-
assert stock.quantities['sku3'] == 997
120-
assert stock.quantities['sku4'] == 996
119+
assert warehouse.quantities['sku3'] == 997
120+
assert warehouse.quantities['sku4'] == 996
121121

122122

123123
def test_allocated_to_earliest_suitable_shipment_in_list():
124124
order = Order({'sku1': 10, 'sku2': 10})
125125
shipment1 = Shipment({'sku1': 1000, 'sku2': 1000}, eta=today)
126126
shipment2 = Shipment({'sku1': 1000, 'sku2': 1000}, eta=tomorrow)
127-
stock = Stock({})
127+
warehouse = Warehouse({})
128128

129-
order.allocate(stock, shipments=[shipment2, shipment1])
129+
order.allocate(warehouse, shipments=[shipment2, shipment1])
130130

131131
assert order.allocation.sources['sku1'] == shipment1
132132
assert order.allocation.sources['sku2'] == shipment1
@@ -137,34 +137,34 @@ def test_still_chooses_earliest_if_split_across_shipments():
137137
shipment1 = Shipment({'sku1': 1000}, eta=today)
138138
shipment2 = Shipment({'sku2': 1000, 'sku3': 1000}, eta=tomorrow)
139139
shipment3 = Shipment({'sku2': 1000, 'sku3': 1000}, eta=later)
140-
stock = Stock({})
140+
warehouse = Warehouse({})
141141

142-
order.allocate(stock, shipments=[shipment3, shipment2, shipment1])
142+
order.allocate(warehouse, shipments=[shipment3, shipment2, shipment1])
143143

144144
assert order.allocation.sources['sku1'] == shipment1
145145
assert order.allocation.sources['sku2'] == shipment2
146146
assert order.allocation.sources['sku3'] == shipment2
147147

148148

149-
def test_stock_not_quite_enough_means_we_use_shipment():
149+
def test_warehouse_not_quite_enough_means_we_use_shipment():
150150
order = Order({'sku1': 10, 'sku2': 10})
151-
stock = Stock({'sku1': 10, 'sku2': 5})
151+
warehouse = Warehouse({'sku1': 10, 'sku2': 5})
152152
shipment = Shipment({
153153
'sku1': 1000,
154154
'sku2': 1000,
155155
}, eta=tomorrow)
156156

157-
order.allocate(stock, shipments=[shipment])
157+
order.allocate(warehouse, shipments=[shipment])
158158

159159
assert order.allocation.sources['sku1'] == shipment
160160
assert order.allocation.sources['sku2'] == shipment
161161

162162

163-
def test_cannot_allocate_if_insufficent_quantity_in_stock():
163+
def test_cannot_allocate_if_insufficent_quantity_in_warehouse():
164164
order = Order({'a-sku': 10})
165-
stock = Stock({'a-sku': 5})
165+
warehouse = Warehouse({'a-sku': 5})
166166

167-
order.allocate(stock, shipments=[])
167+
order.allocate(warehouse, shipments=[])
168168

169169
assert 'a-sku' not in order.allocation.skus
170170

@@ -173,7 +173,7 @@ def test_cannot_allocate_if_insufficent_quantity_in_shipment():
173173
order = Order({'a-sku': 10})
174174
shipment = Shipment({'a-sku': 5}, eta=tomorrow)
175175

176-
order.allocate(stock=Stock({}), shipments=[shipment])
176+
order.allocate(warehouse=Warehouse({}), shipments=[shipment])
177177

178178
assert 'a-sku' not in order.allocation.skus
179179

0 commit comments

Comments
 (0)