forked from OCA/stock-logistics-warehouse
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_stock_location.py
More file actions
315 lines (299 loc) · 11.6 KB
/
test_stock_location.py
File metadata and controls
315 lines (299 loc) · 11.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
# Copyright 2020 ACSONE SA/NV
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo.tests.common import Form, TransactionCase
class TestStockLocation(TransactionCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.env = cls.env(context=dict(cls.env.context, tracking_disable=True))
cls.StockLocation = cls.env["stock.location"]
cls.StockLocation._parent_store_compute()
cls.loc_lvl = cls.env.ref("stock.stock_location_locations")
cls.loc_lvl_1 = cls.StockLocation.create(
{"name": "level_1", "location_id": cls.loc_lvl.id}
)
cls.loc_lvl_1_1 = cls.StockLocation.create(
{"name": "level_1_1", "location_id": cls.loc_lvl_1.id}
)
cls.loc_lvl_1_1_1 = cls.StockLocation.create(
{"name": "level_1_1_1", "location_id": cls.loc_lvl_1_1.id}
)
cls.loc_lvl_1_1_2 = cls.StockLocation.create(
{"name": "level_1_1_1", "location_id": cls.loc_lvl_1_1.id}
)
cls.default_product_restriction = "any"
# products
Product = cls.env["product.product"]
cls.uom_unit = cls.env.ref("uom.product_uom_unit")
cls.product_1 = Product.create(
{"name": "Wood", "type": "product", "uom_id": cls.uom_unit.id}
)
cls.product_2 = Product.create(
{"name": "Stone", "type": "product", "uom_id": cls.uom_unit.id}
)
# quants
StockQuant = cls.env["stock.quant"]
cls.quant_1_lvl_1_1_1 = StockQuant.create(
{
"product_id": cls.product_1.id,
"location_id": cls.loc_lvl_1_1_1.id,
"quantity": 10.0,
"owner_id": cls.env.user.id,
}
)
cls.quant_2_lvl_1_1_1 = StockQuant.create(
{
"product_id": cls.product_2.id,
"location_id": cls.loc_lvl_1_1_1.id,
"quantity": 10.0,
"owner_id": cls.env.user.id,
}
)
cls.quant_1_lvl_1_1_2 = StockQuant.create(
{
"product_id": cls.product_1.id,
"location_id": cls.loc_lvl_1_1_2.id,
"quantity": 10.0,
"owner_id": cls.env.user.id,
}
)
cls.quant_2_lvl_1_1_2 = StockQuant.create(
{
"product_id": cls.product_2.id,
"location_id": cls.loc_lvl_1_1_2.id,
"quantity": 10.0,
"owner_id": cls.env.user.id,
}
)
def test_00(self):
"""
Data:
A 3 depths location hierarchy without
specific_product_restriction
Test Case:
1. Specify a specific_product_restriction at root level
Expected result:
The value at each level must modified.
"""
self.loc_lvl_1.specific_product_restriction = "same"
children = self.loc_lvl_1.child_ids
def check_field(locs, name):
for loc in locs:
self.assertEqual(
name,
loc.product_restriction,
"Wrong product restriction on loc %s" % loc.name,
)
check_field(loc.child_ids, name)
check_field(children, "same")
def test_01(self):
"""
Data:
A 3 depths location hierarchy without
specific_product_restriction
Test Case:
1. Specify a specific_product_restriction at level_1_1
Expected result:
The value at root level and level 1 is the default
The value at level_1_1 and level_1_1_1 is the new one
"""
self.loc_lvl_1_1.specific_product_restriction = "same"
self.loc_lvl_1_1.flush_recordset()
self.assertEqual(
self.default_product_restriction,
self.loc_lvl.product_restriction,
)
self.assertEqual(
self.default_product_restriction,
self.loc_lvl_1.product_restriction,
)
self.assertEqual("same", self.loc_lvl_1_1.product_restriction)
self.assertEqual("same", self.loc_lvl_1_1_1.product_restriction)
def test_02(self):
"""
Data:
Location level_1_1_1 with 2 different products no restriction
Location level_1_1_2 with 2 different products no restriction
Test Case:
1. Search location child of loc_lvl with restriction violation
2. Search location child of loc_lvl without restriction violation
Expected result:
1. No result
2. All child location are returned
"""
self.loc_lvl_1_1_1.product_restriction = "any"
self.loc_lvl_1_1_2.product_restriction = "any"
# has violation
res = self.StockLocation.search(
[
("id", "child_of", self.loc_lvl.id),
("has_restriction_violation", "=", True),
]
)
self.assertFalse(res)
res = self.StockLocation.search(
[
("id", "child_of", self.loc_lvl.id),
("has_restriction_violation", "!=", False),
]
)
self.assertFalse(res)
# without violation
res = self.StockLocation.search(
[
("id", "child_of", self.loc_lvl.id),
("has_restriction_violation", "=", False),
]
)
self.assertIn(self.loc_lvl_1_1_1, res)
self.assertIn(self.loc_lvl_1_1_2, res)
res = self.StockLocation.search(
[
("id", "child_of", self.loc_lvl.id),
("has_restriction_violation", "!=", True),
]
)
self.assertIn(self.loc_lvl_1_1_1, res)
self.assertIn(self.loc_lvl_1_1_2, res)
def test_03(self):
"""
Data:
* Location level_1_1_1 with 2 different products no restriction
* Location level_1_1_2 with 2 different products
with restriction same
Test Case:
1. Search location child of loc_lvl with restriction violation
2. Search location child of loc_lvl without restriction violation
3. Set restriction 'same' on location level_1_1_1
4. Search location child of loc_lvl with restriction violation
Expected result:
1. result = level_1_1_2
2. level_1_1_2 is not into result but level_1_1_1 is
4. result = level_1_1_2 and level_1_1_1
"""
self.loc_lvl_1_1_1.product_restriction = "any"
self.loc_lvl_1_1_2.product_restriction = "same"
(self.loc_lvl_1_1_1 | self.loc_lvl_1_1_2).flush_recordset()
# 1
res = self.StockLocation.search(
[
("id", "child_of", self.loc_lvl.id),
("has_restriction_violation", "=", True),
]
)
self.assertEqual(self.loc_lvl_1_1_2, res)
res = self.StockLocation.search(
[
("id", "child_of", self.loc_lvl.id),
("has_restriction_violation", "!=", False),
]
)
self.assertEqual(self.loc_lvl_1_1_2, res)
# 2
res = self.StockLocation.search(
[
("id", "child_of", self.loc_lvl.id),
("has_restriction_violation", "=", False),
]
)
self.assertIn(self.loc_lvl_1_1_1, res)
self.assertNotIn(self.loc_lvl_1_1_2, res)
res = self.StockLocation.search(
[
("id", "child_of", self.loc_lvl.id),
("has_restriction_violation", "!=", True),
]
)
self.assertIn(self.loc_lvl_1_1_1, res)
self.assertNotIn(self.loc_lvl_1_1_2, res)
# 3
self.loc_lvl_1_1_1.product_restriction = "same"
self.loc_lvl_1_1_2.product_restriction = "same"
(self.loc_lvl_1_1_1 | self.loc_lvl_1_1_2).flush_recordset()
# 4
res = self.StockLocation.search(
[
("id", "child_of", self.loc_lvl.id),
("has_restriction_violation", "=", True),
]
)
self.assertEqual(self.loc_lvl_1_1_2 | self.loc_lvl_1_1_1, res)
res = self.StockLocation.search(
[
("id", "child_of", self.loc_lvl.id),
("has_restriction_violation", "!=", False),
]
)
self.assertEqual(self.loc_lvl_1_1_2 | self.loc_lvl_1_1_1, res)
def test_04(self):
"""
Data:
* Location level_1_1_1 with 2 different products no restriction
Test Case:
1. Check restriction message
3. Set restriction 'same' on location level_1_1_1
4. Check restriction message
Expected result:
1. No restriction message
3. Retriction message
"""
self.loc_lvl_1_1_1.product_restriction = "any"
self.loc_lvl_1_1_1.flush_recordset()
self.assertFalse(self.loc_lvl_1_1_1.has_restriction_violation)
self.assertFalse(self.loc_lvl_1_1_1.restriction_violation_message)
self.loc_lvl_1_1_1.product_restriction = "same"
self.loc_lvl_1_1_1.flush_recordset()
self.assertTrue(self.loc_lvl_1_1_1.has_restriction_violation)
self.assertTrue(self.loc_lvl_1_1_1.restriction_violation_message)
def test_05(self):
# Check location creation
with Form(self.StockLocation) as location_form:
location_form.name = "Test"
def test_zero_quant(self):
"""
Data:
* Location level_1_1_1 with 2 different products no restriction
Test Case:
1. Check restriction message
2. Change product 1 quant to 0.0
3. Set restriction 'same' on location level_1_1_1
4. Check restriction message
Expected result:
1. No restriction message
"""
self.loc_lvl_1_1_1.product_restriction = "any"
self.assertFalse(self.loc_lvl_1_1_1.has_restriction_violation)
self.assertFalse(self.loc_lvl_1_1_1.restriction_violation_message)
self.quant_1_lvl_1_1_1.inventory_quantity = 0.0
self.quant_1_lvl_1_1_1._apply_inventory()
self.loc_lvl_1_1_1.product_restriction = "same"
self.assertFalse(self.loc_lvl_1_1_1.has_restriction_violation)
self.assertFalse(self.loc_lvl_1_1_1.restriction_violation_message)
def test_check_product(self):
"""
Data:
* Location level_1_1_1 with 2 different products no restriction
Test Case:
1. Check restriction message
2. Change product 1 quant to 0.0
3. Set restriction 'same' on location level_1_1_1
4. Check restriction message
Expected result:
1. No restriction message
"""
self.loc_lvl_1_1_1.product_restriction = "any"
self.assertFalse(self.loc_lvl_1_1_1.has_restriction_violation)
self.assertFalse(self.loc_lvl_1_1_1.restriction_violation_message)
self.quant_1_lvl_1_1_1.inventory_quantity = 0.0
self.quant_1_lvl_1_1_1._apply_inventory()
self.loc_lvl_1_1_1.product_restriction = "same"
self.assertFalse(self.loc_lvl_1_1_1.has_restriction_violation)
self.assertFalse(self.loc_lvl_1_1_1.restriction_violation_message)
# Check for product_2
self.assertFalse(
self.loc_lvl_1_1_1._check_has_location_product_restriction(self.product_2)
)
# Check for product_1
self.assertTrue(
self.loc_lvl_1_1_1._check_has_location_product_restriction(self.product_1)
)