Skip to content
Snippets Groups Projects
Commit e5321896 authored by Nicolas Martinelli's avatar Nicolas Martinelli
Browse files

[FIX] stock: merge quants when unpacking


1. Create a new location of type internal in WH/Test
2. Create a new product P with availability of 100.0 in WH/Stock
3. Create a new transfer from WH/Stock to WH/Test with 50.0 units of P,
   Put in Pack and Validate
4. Create a new transfer from WH/Test to WH/Stock/Shelf 1 using the
   previous package, Validate and Unpack
5. Repeat steps from 3 and 4
6. Create a new transfer from WH/Stock/Shelf 1 to Customer with 100.0 units of P
7. Review stock quant from the location WH/Stock/Shelf 1

2 quants of the same product in the location WH/Stock/Shelf 1: one
negative with -50.0 and another positive with 50.0

The step 4 creates 2 quants of 50.0 units, which are reserved at step 6.
However, when validating the transfer 100.0 units are taken from one of
the quants.

To prevent this situation, we run the quant vacuum process after
unpacking. This will merge the 2 quants of 50.0 and prevent any future
negative quant creation. We also clean zero quants, although this is not
mandatory to fix our use case.

Closes #53535
opw-2283707

closes odoo/odoo#54431

X-original-commit: f7168311
Signed-off-by: default avatarNicolas Martinelli (nim) <nim@odoo.com>
parent 05dc6679
No related branches found
No related tags found
No related merge requests found
......@@ -712,6 +712,11 @@ class QuantPackage(models.Model):
move_line_to_modify.write({'package_id': False})
package.mapped('quant_ids').sudo().write({'package_id': False})
# Quant clean-up, mostly to avoid multiple quants of the same product. For example, unpack
# 2 packages of 50, then reserve 100 => a quant of -50 is created at transfer validation.
self.env['stock.quant']._merge_quants()
self.env['stock.quant']._unlink_zero_quants()
def action_view_picking(self):
action = self.env.ref('stock.action_picking_tree_all').read()[0]
domain = ['|', ('result_package_id', 'in', self.ids), ('package_id', 'in', self.ids)]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment