odoo/odoo#265452

Created by fw-bot
Merged at 54294f5f86d2b4b8233e8caccdf67a1db1f19179

Statuses:

label
odoo-dev:saas-19.3-saas-18.3-opw-5479900-subcontracting_location-qucol-527900-fw
head
00f2eae1fa2a82088a31accec074ea3f11e325d4
merged
15 hours ago by Quentin Colla (qucol)
odoo/odoo
saas-18.3 #245905
saas-18.4 #264386
19.0 #264798
saas-19.1 #265071
saas-19.2 #265259
saas-19.3 #265452
master #265627 missing r+

[FIX] mrp_subcontracting: use correct location for return for exchange

Issue

When making a request for quotation for a subcontracted product and returning the delivery "for exchange", the new incoming delivery does not have the correct destination. Instead of having the stock of the user, the destination of the new incoming delivery is the same as its source: the subcontracting location.

<img width="1254" height="257" alt="5479900" src="https://github.com/user-attachments/assets/c7e6d392-8328-4a03-a71e-466e768f448b" />

Steps to reproduce

  1. Install MRP Subcontracting (mrp_subcontracting) and Purchase (purchase)
  2. In Settings, enable Subcontracting
  3. Create a Product P and a subcontracting BoM with Subcontractor S
  4. Create a Request for Quotation
    • Vendor: Subcontractor S
    • Product: Product P (any quantity > 0)
  5. Confirm the RFQ, receive the PO, validate the picking
  6. On the validated picking, click Return, set the quantity of products to return, and click Return for Exchange
    • This creates two new pickings, one to return the product(s) we received, and one to receive new products
  7. Validate the two new pickings
  8. In Inventory > Reporting > Moves History, the very last stock.move.line has the same location in the From (location_id) and the To (location_dest_id) columns

Cause

The location_dest_id of the new stock.move is updated in StockReturnPickingLine._prepare_move_default_values.

https://github.com/odoo/odoo/blob/fb534f1eadcb8ef74e2ee6fd5b68872dddb978e3/addons/mrp_subcontracting/wizard/stock_picking_return.py#L20-L25

The condition added by 5404b426aac9 sets the destination of all returned subcontracted moves to the subcontractor location. This is incorrect when using "return for exchange", as in this case, the return move is directed towards the user's stock. In fact, when using "return for exchange", the following pickings are created:

id name return_id
1 WH/IN/00001 Initial RFQ delivery
2 WH/OUT/00001 1 Return of the initial RFQ delivery
3 WH/IN/00002 2 New products delivery to replace the initial delivery. The stock.move.line of this stock.picking has a wrong location_dest_id

Fix

In the context of return for exchanges, the returned item must be directed to the Subcontracting Location while the new item must be directed to the Stock. In the _prepare_move_default_values, we should only set the location_dest_it to the subcontractor location for outgoing pickings.

opw-5479900

Forward-Port-Of: #265071
Forward-Port-Of: #245905