Skip to content

Commit f815b0d

Browse files
committed
start on both
1 parent 2f046ae commit f815b0d

File tree

2 files changed

+25
-8
lines changed

2 files changed

+25
-8
lines changed

domain_model.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,10 @@ def to_list(fn):
4141
@to_list
4242
def allocate(order, stock, shipments):
4343
for line in order.lines:
44-
if stock:
44+
for stock_line in stock:
4545
yield Allocation(order.id, line.sku, line.quantity, shipment_id=None)
46-
else:
47-
for shipment in shipments:
48-
for shipment_line in shipment.lines:
49-
if shipment_line.sku == line.sku:
50-
yield Allocation(order.id, line.sku, line.quantity, shipment.id)
46+
for shipment in shipments:
47+
for shipment_line in shipment.lines:
48+
if shipment_line.sku == line.sku:
49+
yield Allocation(order.id, line.sku, line.quantity, shipment.id)
5150

test_allocation.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,6 @@ def test_can_allocate_to_correct_shipment():
6767
assert allocations[0].quantity == 10
6868

6969

70-
71-
7270
def test_allocates_to_warehouse_stock_in_preference_to_shipment():
7371
sku = random_id()
7472
order = Order(id=random_id(), lines=[
@@ -118,3 +116,23 @@ def test_can_allocate_multiple_lines_to_shipment():
118116
assert Allocation(order.id, sku1, 10, shipment_id=shipment.id) in allocations
119117
assert Allocation(order.id, sku2, 10, shipment_id=shipment.id) in allocations
120118

119+
120+
def test_can_allocate_to_both():
121+
sku1, sku2 = random_id(), random_id()
122+
order = Order(id=random_id(), lines=[
123+
OrderLine(sku=sku1, quantity=10),
124+
OrderLine(sku=sku2, quantity=10),
125+
])
126+
shipment = Shipment(id=random_id(), eta=date.today(), lines=[
127+
OrderLine(sku=sku2, quantity=1000),
128+
])
129+
stock = [
130+
Stock(sku=sku1, quantity=1000),
131+
]
132+
133+
allocations = allocate(order, stock, shipments=[shipment])
134+
assert Allocation(order.id, sku1, 10, shipment_id=None) in allocations
135+
assert Allocation(order.id, sku2, 10, shipment_id=shipment.id) in allocations
136+
137+
138+

0 commit comments

Comments
 (0)