@@ -23,6 +23,7 @@ def test_can_allocate_to_stock():
23
23
allocate (order , stock , shipments = [])
24
24
25
25
assert order [0 ].allocation == 'STOCK'
26
+ assert stock [0 ].quantity == 990
26
27
27
28
28
29
def test_can_allocate_to_shipment ():
@@ -34,6 +35,7 @@ def test_can_allocate_to_shipment():
34
35
allocate (order , stock = [], shipments = [shipment ])
35
36
36
37
assert order [0 ].allocation == shipment .id
38
+ assert shipment [0 ].quantity == 990
37
39
38
40
39
41
def test_ignores_invalid_stock ():
@@ -46,6 +48,8 @@ def test_ignores_invalid_stock():
46
48
allocate (order , stock = stock , shipments = [shipment ])
47
49
48
50
assert order [0 ].allocation == shipment .id
51
+ assert stock [0 ].quantity == 1000
52
+ assert shipment [0 ].quantity == 990
49
53
50
54
51
55
def test_can_allocate_to_correct_shipment ():
@@ -60,6 +64,8 @@ def test_can_allocate_to_correct_shipment():
60
64
allocate (order , stock = [], shipments = [shipment1 , shipment2 ])
61
65
62
66
assert order [0 ].allocation == shipment2 .id
67
+ assert shipment1 [0 ].quantity == 1000
68
+ assert shipment2 [0 ].quantity == 990
63
69
64
70
65
71
def test_allocates_to_stock_in_preference_to_shipment ():
@@ -73,11 +79,13 @@ def test_allocates_to_stock_in_preference_to_shipment():
73
79
allocate (order , stock , shipments = [shipment ])
74
80
75
81
assert order [0 ].allocation == 'STOCK'
82
+ assert stock [0 ].quantity == 990
83
+ assert shipment [0 ].quantity == 1000
76
84
77
85
78
86
def test_can_allocate_multiple_lines_to_wh ():
79
87
order = [
80
- OrderLine (sku = 'sku1' , quantity = 10 ),
88
+ OrderLine (sku = 'sku1' , quantity = 5 ),
81
89
OrderLine (sku = 'sku2' , quantity = 10 ),
82
90
]
83
91
stock = [
@@ -88,11 +96,13 @@ def test_can_allocate_multiple_lines_to_wh():
88
96
allocate (order , stock , shipments = [])
89
97
assert order [0 ].allocation == 'STOCK'
90
98
assert order [1 ].allocation == 'STOCK'
99
+ assert stock [0 ].quantity == 995
100
+ assert stock [1 ].quantity == 990
91
101
92
102
93
103
def test_can_allocate_multiple_lines_to_shipment ():
94
104
order = [
95
- OrderLine (sku = 'sku1' , quantity = 10 ),
105
+ OrderLine (sku = 'sku1' , quantity = 5 ),
96
106
OrderLine (sku = 'sku2' , quantity = 10 ),
97
107
]
98
108
shipment = Shipment ('shipment1' , eta = date .today (), lines = [
@@ -104,11 +114,13 @@ def test_can_allocate_multiple_lines_to_shipment():
104
114
105
115
assert order [0 ].allocation == shipment .id
106
116
assert order [1 ].allocation == shipment .id
117
+ assert shipment [0 ].quantity == 995
118
+ assert shipment [1 ].quantity == 990
107
119
108
120
109
121
def test_can_allocate_to_both ():
110
122
order = [
111
- OrderLine (sku = 'sku1' , quantity = 10 ),
123
+ OrderLine (sku = 'sku1' , quantity = 5 ),
112
124
OrderLine (sku = 'sku2' , quantity = 10 ),
113
125
]
114
126
shipment = Shipment ('shipment1' , eta = date .today (), lines = [
@@ -120,14 +132,16 @@ def test_can_allocate_to_both():
120
132
121
133
assert order [0 ].allocation == 'STOCK'
122
134
assert order [1 ].allocation == shipment .id
135
+ assert stock [0 ].quantity == 995
136
+ assert shipment [0 ].quantity == 990
123
137
124
138
125
139
def test_can_allocate_to_both_preferring_stock ():
126
140
order = [
127
- OrderLine (sku = 'sku1' , quantity = 10 ),
128
- OrderLine (sku = 'sku2' , quantity = 10 ),
129
- OrderLine (sku = 'sku3' , quantity = 10 ),
130
- OrderLine (sku = 'sku4' , quantity = 10 ),
141
+ OrderLine (sku = 'sku1' , quantity = 1 ),
142
+ OrderLine (sku = 'sku2' , quantity = 2 ),
143
+ OrderLine (sku = 'sku3' , quantity = 3 ),
144
+ OrderLine (sku = 'sku4' , quantity = 4 ),
131
145
]
132
146
shipment = Shipment ('shipment1' , eta = date .today (), lines = [
133
147
Line (sku = 'sku1' , quantity = 1000 ),
@@ -145,6 +159,12 @@ def test_can_allocate_to_both_preferring_stock():
145
159
assert order [1 ].allocation == shipment .id
146
160
assert order [2 ].allocation == 'STOCK'
147
161
assert order [3 ].allocation == 'STOCK'
162
+ assert shipment [0 ].quantity == 999
163
+ assert shipment [1 ].quantity == 998
164
+ assert shipment [2 ].quantity == 1000
165
+ assert shipment [3 ].quantity == 1000
166
+ assert stock [0 ].quantity == 997
167
+ assert stock [1 ].quantity == 996
148
168
149
169
150
170
def test_mixed_allocations_are_avoided_if_possible ():
@@ -233,7 +253,7 @@ def test_cannot_allocate_if_insufficent_quantity_in_shipment():
233
253
assert order [0 ].allocation is None
234
254
235
255
236
- def test_allocation_decreases_quantity_available_on_shipments ():
256
+ def test_cannot_allocate_more_orders_than_we_have_stock_for ():
237
257
order1 = [OrderLine (sku = 'a-sku' , quantity = 10 )]
238
258
order2 = [OrderLine (sku = 'a-sku' , quantity = 10 )]
239
259
stock = [Line (sku = 'a-sku' , quantity = 15 )]
0 commit comments