[FIX] stock: reserved quantity on return of return

1. Activate receipt in 2 steps
2. Make a PO of 10
3. Receive 8 (pick 1), backorder
4. Receive 2 (pick 2)
5. Unreserve the internal transfer (pick 3)
6. Go to pick 2, return 2 (pick 4)
   => product is sent back to the supplier
7. Go to pick 4, return 2 (pick 5)
   => product is received from the supplier
8. Go to pick 3, check availability

Only 8 units are reserved instead of 10.

It happens because pick 5 (return of the return) is not linked to the
pick 3 (internal transfer).

We use a similar approach for `move_dest_to_link` than the one used for
`move_orig_to_link`.

Closes #52459

opw-2271838

closes odoo/odoo#53506

X-original-commit: c96339dd94ffe1e9c5103814062455c79d93a273
Signed-off-by: Nicolas Martinelli (nim) <nim@odoo.com>
This commit is contained in:
Nicolas Martinelli
2020-06-23 12:41:15 +00:00
parent 8b49908f8c
commit 536759644e
@@ -149,6 +149,14 @@ class ReturnPicking(models.TransientModel):
.mapped('move_dest_ids').filtered(lambda m: m.state not in ('cancel'))\
.mapped('move_orig_ids').filtered(lambda m: m.state not in ('cancel'))
move_dest_to_link = return_line.move_id.move_orig_ids.mapped('returned_move_ids')
# link to children of originally returned moves, if any. Note that the use of
# 'return_line.move_id.move_orig_ids.returned_move_ids.move_orig_ids.move_dest_ids'
# instead of 'return_line.move_id.move_orig_ids.move_dest_ids' prevents linking a
# return directly to the destination moves of its parents. However, the return of
# the return will be linked to the destination moves.
move_dest_to_link |= return_line.move_id.move_orig_ids.mapped('returned_move_ids')\
.mapped('move_orig_ids').filtered(lambda m: m.state not in ('cancel'))\
.mapped('move_dest_ids').filtered(lambda m: m.state not in ('cancel'))
vals['move_orig_ids'] = [(4, m.id) for m in move_orig_to_link]
vals['move_dest_ids'] = [(4, m.id) for m in move_dest_to_link]
r.write(vals)