Skip to content

Commit 53fbe77

Browse files
committed
[IMP] stock_available_location_orderpoint: Improve tests for sublocations
1 parent 5edd572 commit 53fbe77

File tree

4 files changed

+115
-6
lines changed

4 files changed

+115
-6
lines changed

stock_available_location_orderpoint/models/product_product.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ def _compute_available_quantities_dict(self):
7171
for product in self:
7272
qties_replenished_for_location = {product: 0.0}
7373
for orderpoint in orderpoints:
74+
# As we compute global quantities for the product, pass
75+
# always 0 to the already replenished quantity
7476
qty_to_replenish = orderpoint._get_qty_to_replenish(
7577
product,
7678
qties_on_locations,

stock_available_location_orderpoint/readme/ROADMAP.rst

Whitespace-only changes.

stock_available_location_orderpoint/tests/test_available_location_orderpoint.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,11 @@ def test_available_on_one_shelf_location(self):
139139
move = self._create_outgoing_move(1)
140140
self.assertEqual(move.state, "confirmed")
141141
self.product.invalidate_recordset()
142+
# The quantity to replenish is equal to the total of replenishment locations
143+
# quantity as they are in shelf parents path.
142144
self.assertEqual(
143-
7.0, self.product.with_context(location=self.shelf.id).quantity_to_replenish
145+
17.0,
146+
self.product.with_context(location=self.shelf.id).quantity_to_replenish,
144147
)
145148

146149
def test_available_on_one_stock_location_with_shelf(self):
@@ -204,16 +207,17 @@ def test_available_on_one_stock_location_with_shelf(self):
204207

205208
# Check the replenishment value for shelf location only
206209
self.assertEqual(
207-
5.0, self.product.with_context(location=self.shelf.id).quantity_to_replenish
210+
15.0,
211+
self.product.with_context(location=self.shelf.id).quantity_to_replenish,
208212
)
209213

210214
# We are not in shelf location context
211-
product = self.product.search([("quantity_to_replenish", "=", 5.0)])
212-
self.assertFalse(self.product.id in product.ids)
215+
product = self.product.search([("quantity_to_replenish", "=", 15.0)])
216+
self.assertTrue(self.product.id in product.ids)
213217

214218
# We are in shelf location context
215219
product = self.product.with_context(location=self.shelf.id).search(
216-
[("quantity_to_replenish", "=", 5.0)]
220+
[("quantity_to_replenish", "=", 15.0)]
217221
)
218222
self.assertTrue(self.product.id in product.ids)
219223

stock_available_location_orderpoint/tests/test_available_location_orderpoint_template.py

Lines changed: 104 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,11 +329,114 @@ def test_available_on_one_stock_location_with_shelf(self):
329329

330330
# We are in shelf context
331331
self.template.invalidate_recordset()
332+
self.template.product_variant_ids.invalidate_recordset()
333+
self.template.with_context(
334+
location=self.shelf.id
335+
)._compute_available_quantities_dict()
336+
self.assertEqual(
337+
15.0,
338+
self.template.with_context(location=self.shelf.id).quantity_to_replenish,
339+
)
332340
templates = self.template.with_context(location=self.shelf.id).search(
333-
[("quantity_to_replenish", "=", 5.0)]
341+
[("quantity_to_replenish", "=", 15.0)]
334342
)
335343
self.assertTrue(self.template.id in templates.ids)
336344

345+
def test_available_on_different_sublocation(self):
346+
"""
347+
Remove the existing orderpoints
348+
349+
Create a location structure like:
350+
- Stock
351+
- Area 1
352+
- Shelf 1
353+
- Area 2
354+
- Shelf 2
355+
356+
Create orderpoints for both areas.
357+
358+
Create ougoing moves for both shelves:
359+
- Shelf 1: 12.0
360+
- Shelf 2: 2.0
361+
362+
Global quantity to replenish should be 8.0
363+
364+
Quantity for Shelf 1 should be 6.0
365+
366+
"""
367+
# Archive orderpoints
368+
self.env["stock.location.orderpoint"].search([]).write({"active": False})
369+
370+
self.area_1 = self.env["stock.location"].create(
371+
{
372+
"name": "Area 1",
373+
"location_id": self.location_dest.id,
374+
"usage": "view",
375+
}
376+
)
377+
378+
self.shelf_1 = self.env["stock.location"].create(
379+
{"name": "Shelf 1", "location_id": self.area_1.id}
380+
)
381+
382+
self.area_2 = self.env["stock.location"].create(
383+
{
384+
"name": "Area 2",
385+
"location_id": self.location_dest.id,
386+
"usage": "view",
387+
}
388+
)
389+
390+
self.shelf_2 = self.env["stock.location"].create(
391+
{"name": "Shelf 1", "location_id": self.area_2.id}
392+
)
393+
394+
# Create an orderpoint by shelf
395+
self.location_dest = self.area_1
396+
(
397+
self.orderpoint_shelf_1,
398+
self.location_src_shelf_1,
399+
) = self._create_orderpoint_complete("Area 1 Replenishment", trigger="manual")
400+
401+
self.location_dest = self.area_2
402+
(
403+
self.orderpoint_shelf_2,
404+
self.location_src_shelf_2,
405+
) = self._create_orderpoint_complete("Area 2 Replenishment", trigger="manual")
406+
407+
# Set stock on replenishment locations
408+
self.env["stock.quant"].with_context(inventory_mode=True).create(
409+
{
410+
"inventory_quantity": 6.0,
411+
"location_id": self.location_src_shelf_1.id,
412+
"product_id": self.product.id,
413+
}
414+
)._apply_inventory()
415+
self.env["stock.quant"].with_context(inventory_mode=True).create(
416+
{
417+
"inventory_quantity": 4.0,
418+
"location_id": self.location_src_shelf_2.id,
419+
"product_id": self.product.id,
420+
}
421+
)._apply_inventory()
422+
423+
self.location_dest = self.shelf_1
424+
move = self._create_outgoing_move(12)
425+
self.assertEqual(move.state, "confirmed")
426+
427+
self.location_dest = self.shelf_2
428+
move = self._create_outgoing_move(2)
429+
self.assertEqual(move.state, "confirmed")
430+
431+
self.template.invalidate_recordset()
432+
self.assertEqual(8.0, self.template.quantity_to_replenish)
433+
434+
self.template.invalidate_recordset()
435+
self.assertEqual(
436+
6.0,
437+
self.template.with_context(location=self.shelf_1.id).quantity_to_replenish,
438+
)
439+
337440
def test_action(self):
338441
action = self.template.action_open_replenishments()
339442
self.assertIn(

0 commit comments

Comments
 (0)