odoo/odoo#162721

Created by fw-bot
label
odoo-dev:master-17.0-opw-3777615-huvw-1ijx-fw
head
950e293f2aeb535e71298882c34382b2b8d9d2ab
target
master
merged
4 weeks ago by Hubert Van De Walle
forward-port of
odoo/odoo#162425 DETACHED (Head updated from c2fe49c579b496206512cc1e548b12191bc4e579 to 950e293f2aeb535e71298882c34382b2b8d9d2ab)

[FW][FIX] stock: prevent opening SM when picking is dirty

Steps to reproduce
==================

- Create two new storable products tracked by USN
- Create a new RFQ with one of the created product
- Confirm the order
- Open the receipt
- Add a new line with the other product
- Click on the open move button in the new line
- Add a new SN
- Save & close

=> Cannot read properties of undefined (reading 'resId')

Cause of the issue
==================

When calling openRecord, if the record is dirty, it is saved before proceeding.

After saving, we call super.openRecord with the old record. Since that record is no longer linked to the root record (the stock.picking), when we try to save it, it won't match an existing id.

Solution
========

If the record is new, we don't save as there would be no way of knowing which of the returned line would come from this one.

If we are opening an existing record, we find the new datapoint by matching it's ID.

opw-3777615

Forward-Port-Of: odoo/odoo#162645
Forward-Port-Of: odoo/odoo#162425