@@ -28,59 +28,58 @@ def test_can_allocate_to_stock():
28
28
29
29
def test_can_allocate_to_shipment ():
30
30
order = [OrderLine (sku = 'a-sku' , quantity = 10 )]
31
- shipment = Shipment (id = 'shipment-id' , eta = date .today (), lines = [
32
- Line ( sku = 'a-sku' , quantity = 1000 ),
33
- ] )
31
+ shipment = Shipment (id = 'shipment-id' , eta = date .today (), lines = {
32
+ 'a-sku' : 1000
33
+ } )
34
34
35
35
allocate (order , stock = [], shipments = [shipment ])
36
36
37
37
assert order [0 ].allocation == shipment .id
38
- assert shipment [0 ]. quantity == 990
38
+ assert shipment ['a-sku' ] == 990
39
39
40
40
41
41
def test_ignores_invalid_stock ():
42
42
order = [OrderLine (sku = 'sku1' , quantity = 10 ), ]
43
43
stock = [Line (sku = 'sku2' , quantity = 1000 )]
44
- shipment = Shipment (id = 'shipment-id' , eta = date .today (), lines = [
45
- Line ( sku = 'sku1' , quantity = 1000 ) ,
46
- ] )
44
+ shipment = Shipment (id = 'shipment-id' , eta = date .today (), lines = {
45
+ 'sku1' : 1000 ,
46
+ } )
47
47
48
48
allocate (order , stock = stock , shipments = [shipment ])
49
49
50
50
assert order [0 ].allocation == shipment .id
51
51
assert stock [0 ].quantity == 1000
52
- assert shipment [0 ]. quantity == 990
52
+ assert shipment ['sku1' ] == 990
53
53
54
54
55
55
def test_can_allocate_to_correct_shipment ():
56
56
order = [OrderLine (sku = 'sku2' , quantity = 10 )]
57
- shipment1 = Shipment ('shipment1' , eta = date .today (), lines = [
58
- Line ( sku = 'sku1' , quantity = 1000 ) ,
59
- ] )
60
- shipment2 = Shipment ('shipment2' , eta = date .today (), lines = [
61
- Line ( sku = 'sku2' , quantity = 1000 ) ,
62
- ] )
57
+ shipment1 = Shipment ('shipment1' , eta = date .today (), lines = {
58
+ 'sku1' : 1000 ,
59
+ } )
60
+ shipment2 = Shipment ('shipment2' , eta = date .today (), lines = {
61
+ 'sku2' : 1000 ,
62
+ } )
63
63
64
64
allocate (order , stock = [], shipments = [shipment1 , shipment2 ])
65
65
66
66
assert order [0 ].allocation == shipment2 .id
67
- assert shipment1 [0 ]. quantity == 1000
68
- assert shipment2 [0 ]. quantity == 990
67
+ assert shipment1 ['sku1' ] == 1000
68
+ assert shipment2 ['sku2' ] == 990
69
69
70
70
71
71
def test_allocates_to_stock_in_preference_to_shipment ():
72
- sku = random_id ()
73
- order = [OrderLine (sku = sku , quantity = 10 )]
74
- stock = [Line (sku = sku , quantity = 1000 )]
75
- shipment = Shipment ('shipment1' , eta = date .today (), lines = [
76
- Line (sku = sku , quantity = 1000 ),
77
- ])
72
+ order = [OrderLine (sku = 'sku1' , quantity = 10 )]
73
+ stock = [Line (sku = 'sku1' , quantity = 1000 )]
74
+ shipment = Shipment ('shipment1' , eta = date .today (), lines = {
75
+ 'sku1' : 1000 ,
76
+ })
78
77
79
78
allocate (order , stock , shipments = [shipment ])
80
79
81
80
assert order [0 ].allocation == 'STOCK'
82
81
assert stock [0 ].quantity == 990
83
- assert shipment [0 ]. quantity == 1000
82
+ assert shipment ['sku1' ] == 1000
84
83
85
84
86
85
def test_can_allocate_multiple_lines_to_wh ():
@@ -105,35 +104,35 @@ def test_can_allocate_multiple_lines_to_shipment():
105
104
OrderLine (sku = 'sku1' , quantity = 5 ),
106
105
OrderLine (sku = 'sku2' , quantity = 10 ),
107
106
]
108
- shipment = Shipment ('shipment1' , eta = date .today (), lines = [
109
- Line ( sku = 'sku1' , quantity = 1000 ) ,
110
- Line ( sku = 'sku2' , quantity = 1000 ) ,
111
- ] )
107
+ shipment = Shipment ('shipment1' , eta = date .today (), lines = {
108
+ 'sku1' : 1000 ,
109
+ 'sku2' : 1000 ,
110
+ } )
112
111
113
112
allocate (order , [], shipments = [shipment ])
114
113
115
114
assert order [0 ].allocation == shipment .id
116
115
assert order [1 ].allocation == shipment .id
117
- assert shipment [0 ]. quantity == 995
118
- assert shipment [1 ]. quantity == 990
116
+ assert shipment ['sku1' ] == 995
117
+ assert shipment ['sku2' ] == 990
119
118
120
119
121
120
def test_can_allocate_to_both ():
122
121
order = [
123
122
OrderLine (sku = 'sku1' , quantity = 5 ),
124
123
OrderLine (sku = 'sku2' , quantity = 10 ),
125
124
]
126
- shipment = Shipment ('shipment1' , eta = date .today (), lines = [
127
- Line ( sku = 'sku2' , quantity = 1000 ) ,
128
- ] )
125
+ shipment = Shipment ('shipment1' , eta = date .today (), lines = {
126
+ 'sku2' : 1000 ,
127
+ } )
129
128
stock = [Line (sku = 'sku1' , quantity = 1000 )]
130
129
131
130
allocate (order , stock , shipments = [shipment ])
132
131
133
132
assert order [0 ].allocation == 'STOCK'
134
133
assert order [1 ].allocation == shipment .id
135
134
assert stock [0 ].quantity == 995
136
- assert shipment [0 ]. quantity == 990
135
+ assert shipment ['sku2' ] == 990
137
136
138
137
139
138
def test_can_allocate_to_both_preferring_stock ():
@@ -143,11 +142,11 @@ def test_can_allocate_to_both_preferring_stock():
143
142
OrderLine (sku = 'sku3' , quantity = 3 ),
144
143
OrderLine (sku = 'sku4' , quantity = 4 ),
145
144
]
146
- shipment = Shipment ('shipment1' , eta = date .today (), lines = [
147
- Line ( sku = 'sku1' , quantity = 1000 ) ,
148
- Line ( sku = 'sku2' , quantity = 1000 ) ,
149
- Line ( sku = 'sku3' , quantity = 1000 ) ,
150
- ] )
145
+ shipment = Shipment ('shipment1' , eta = date .today (), lines = {
146
+ 'sku1' : 1000 ,
147
+ 'sku2' : 1000 ,
148
+ 'sku3' : 1000 ,
149
+ } )
151
150
stock = [
152
151
Line (sku = 'sku3' , quantity = 1000 ),
153
152
Line (sku = 'sku4' , quantity = 1000 ),
@@ -159,10 +158,9 @@ def test_can_allocate_to_both_preferring_stock():
159
158
assert order [1 ].allocation == shipment .id
160
159
assert order [2 ].allocation == 'STOCK'
161
160
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
161
+ assert shipment ['sku1' ] == 999
162
+ assert shipment ['sku2' ] == 998
163
+ assert shipment ['sku3' ] == 1000
166
164
assert stock [0 ].quantity == 997
167
165
assert stock [1 ].quantity == 996
168
166
@@ -172,10 +170,10 @@ def test_mixed_allocations_are_avoided_if_possible():
172
170
OrderLine (sku = 'sku1' , quantity = 10 ),
173
171
OrderLine (sku = 'sku2' , quantity = 10 ),
174
172
]
175
- shipment = Shipment ('shipment1' , eta = date .today (), lines = [
176
- Line ( sku = 'sku1' , quantity = 1000 ) ,
177
- Line ( sku = 'sku2' , quantity = 1000 ) ,
178
- ] )
173
+ shipment = Shipment ('shipment1' , eta = date .today (), lines = {
174
+ 'sku1' : 1000 ,
175
+ 'sku2' : 1000 ,
176
+ } )
179
177
stock = [Line (sku = 'sku1' , quantity = 1000 )]
180
178
181
179
allocate (order , stock , shipments = [shipment ])
@@ -189,15 +187,15 @@ def test_prefer_allocating_to_earlier_shipment():
189
187
OrderLine (sku = 'sku1' , quantity = 10 ),
190
188
OrderLine (sku = 'sku2' , quantity = 10 ),
191
189
]
192
- shipment1 = Shipment ('shipment1' , eta = date .today (), lines = [
193
- Line ( sku = 'sku1' , quantity = 1000 ) ,
194
- Line ( sku = 'sku2' , quantity = 1000 ) ,
195
- ] )
190
+ shipment1 = Shipment ('shipment1' , eta = date .today (), lines = {
191
+ 'sku1' : 1000 ,
192
+ 'sku2' : 1000 ,
193
+ } )
196
194
tomorrow = date .today () + timedelta (days = 1 )
197
- shipment2 = Shipment ('shipment2' , eta = tomorrow , lines = [
198
- Line ( sku = 'sku1' , quantity = 1000 ) ,
199
- Line ( sku = 'sku2' , quantity = 1000 ) ,
200
- ] )
195
+ shipment2 = Shipment ('shipment2' , eta = tomorrow , lines = {
196
+ 'sku1' : 1000 ,
197
+ 'sku2' : 1000 ,
198
+ } )
201
199
stock = []
202
200
203
201
allocate (order , stock , shipments = [shipment2 , shipment1 ])
@@ -212,19 +210,19 @@ def test_prefer_allocating_to_earlier_even_if_multiple_shipments():
212
210
OrderLine (sku = 'sku2' , quantity = 10 ),
213
211
OrderLine (sku = 'sku3' , quantity = 10 ),
214
212
]
215
- shipment1 = Shipment (id = 'shipment1' , eta = date .today (), lines = [
216
- Line ( sku = 'sku1' , quantity = 1000 ) ,
217
- ] )
213
+ shipment1 = Shipment (id = 'shipment1' , eta = date .today (), lines = {
214
+ 'sku1' : 1000 ,
215
+ } )
218
216
tomorrow = date .today () + timedelta (days = 1 )
219
- shipment2 = Shipment (id = 'shipment2' , eta = tomorrow , lines = [
220
- Line ( sku = 'sku2' , quantity = 1000 ) ,
221
- Line ( sku = 'sku3' , quantity = 1000 ) ,
222
- ] )
217
+ shipment2 = Shipment (id = 'shipment2' , eta = tomorrow , lines = {
218
+ 'sku2' : 1000 ,
219
+ 'sku3' : 1000 ,
220
+ } )
223
221
later = tomorrow + timedelta (days = 1 )
224
- shipment3 = Shipment (id = 'shipment3' , eta = later , lines = [
225
- Line ( sku = 'sku2' , quantity = 1000 ) ,
226
- Line ( sku = 'sku3' , quantity = 1000 ) ,
227
- ] )
222
+ shipment3 = Shipment (id = 'shipment3' , eta = later , lines = {
223
+ 'sku2' : 1000 ,
224
+ 'sku3' : 1000 ,
225
+ } )
228
226
stock = []
229
227
230
228
allocate (order , stock , shipments = [shipment3 , shipment2 , shipment1 ])
@@ -244,9 +242,9 @@ def test_cannot_allocate_if_insufficent_quantity_in_stock():
244
242
245
243
def test_cannot_allocate_if_insufficent_quantity_in_shipment ():
246
244
order = [OrderLine (sku = 'a-sku' , quantity = 10 )]
247
- shipment = Shipment (id = 'shipment-id' , eta = date .today (), lines = [
248
- Line ( sku = 'a-sku' , quantity = 5 ) ,
249
- ] )
245
+ shipment = Shipment (id = 'shipment-id' , eta = date .today (), lines = {
246
+ 'a-sku' : 5 ,
247
+ } )
250
248
251
249
allocate (order , stock = [], shipments = [shipment ])
252
250
0 commit comments