Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[FIX] stock: recompute move state
Before this commit, a move can be 'assigned' even if it has no reserved
quantity.

How to reproduce:
    - For a tracked product, add some quantities for a LN/SN. Create an
      another LN/SN with no quantity;
    - Create a delivery for this product;
    - Confirm it and check availability;
    - On the move line, change the SN/LN for the one without quantity.
    --> The move has no reserved quantity but is still marked as
        `assigned`.

task-2171546

closes #44141

X-original-commit: d5e70fa
Signed-off-by: Simon Lejeune (sle) <sle@openerp.com>
Co-authored-by: sle-odoo <sle@odoo.com>
  • Loading branch information
svs-odoo and sle-odoo committed Jan 28, 2020
1 parent 1ccabe5 commit f7193e8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
6 changes: 6 additions & 0 deletions addons/stock/models/stock_move_line.py
Expand Up @@ -238,6 +238,7 @@ def write(self, vals):
if 'product_id' in vals and any(vals.get('state', ml.state) != 'draft' and vals['product_id'] != ml.product_id.id for ml in self):
raise UserError(_("Changing the product is only allowed in 'Draft' state."))

moves_to_recompute_state = self.env['stock.move']
Quant = self.env['stock.quant']
precision = self.env['decimal.precision'].precision_get('Product Unit of Measure')
# We forbid to change the reserved quantity in the interace, but it is needed in the
Expand Down Expand Up @@ -296,6 +297,7 @@ def write(self, vals):
pass
if new_product_qty != ml.product_qty:
new_product_uom_qty = ml.product_id.uom_id._compute_quantity(new_product_qty, ml.product_uom_id, rounding_method='HALF-UP')
moves_to_recompute_state |= ml.move_id
ml.with_context(bypass_reservation_update=True).product_uom_qty = new_product_uom_qty

# When editing a done move line, the reserved availability of a potential chained move is impacted. Take care of running again `_action_assign` on the concerned moves.
Expand Down Expand Up @@ -361,6 +363,10 @@ def write(self, vals):
move.product_uom_qty = move.quantity_done
next_moves._do_unreserve()
next_moves._action_assign()

if moves_to_recompute_state:
moves_to_recompute_state._recompute_state()

return res

def unlink(self):
Expand Down
2 changes: 2 additions & 0 deletions addons/stock/tests/test_move.py
Expand Up @@ -2610,12 +2610,14 @@ def test_edit_reserved_move_line_6(self):
move1._action_confirm()
move1._action_assign()

self.assertEqual(move1.move_line_ids.state, 'assigned')
self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, shelf1_location), 0.0)
self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, shelf2_location), 0.0)
self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location), 0.0)

move1.move_line_ids.location_id = shelf2_location.id

self.assertEqual(move1.move_line_ids.state, 'confirmed')
self.assertEqual(move1.reserved_availability, 0.0)
self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location), 1.0)
self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, shelf1_location), 1.0)
Expand Down

0 comments on commit f7193e8

Please sign in to comment.