Skip to content

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

Closed
fw-bot wants to merge 1 commit into
odoo:saas-19.3from
odoo-dev:saas-19.3-saas-18.3-opw-5479900-subcontracting_location-qucol-527900-fw
Closed

[FIX] mrp_subcontracting: use correct location for return for exchange#265452
fw-bot wants to merge 1 commit into
odoo:saas-19.3from
odoo-dev:saas-19.3-saas-18.3-opw-5479900-subcontracting_location-qucol-527900-fw

Conversation

@fw-bot
Copy link
Copy Markdown
Contributor

@fw-bot fw-bot commented May 20, 2026

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.

5479900

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.

def _prepare_move_default_values(self, new_picking):
vals = super()._prepare_move_default_values(new_picking)
if self.move_id.is_subcontract:
vals['location_dest_id'] = new_picking.partner_id.with_company(new_picking.company_id).property_stock_subcontractor.id
vals['is_subcontract'] = False
return vals

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

@robodoo
Copy link
Copy Markdown
Contributor

robodoo commented May 20, 2026

Pull request status dashboard

@robodoo robodoo added forwardport This PR was created by @fw-bot conflict There was an error while creating this forward-port PR labels May 20, 2026
@fw-bot
Copy link
Copy Markdown
Contributor Author

fw-bot commented May 20, 2026

@qucol-odoo cherrypicking of pull request #245905 failed.

stdout:

Auto-merging addons/mrp_subcontracting/tests/test_subcontracting.py
CONFLICT (modify/delete): addons/mrp_subcontracting/wizard/stock_picking_return.py deleted in 059228bfafef3de0d5d7994507dffc59e573c8a8 and modified in 6ce664fa22cfd9c6d4105c17dca31f59c4b384ed.  Version 6ce664fa22cfd9c6d4105c17dca31f59c4b384ed of addons/mrp_subcontracting/wizard/stock_picking_return.py left in tree.

Either perform the forward-port manually (and push to this branch, proceeding as usual) or close this PR (maybe?).

:shipit: you can use git-fw to re-do the forward-port for you locally.

⚠️ after resolving this conflict, you will need to merge it via @robodoo.

More info at https://github.com/odoo/odoo/wiki/Mergebot#forward-port

## 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.

## 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 odoo@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

X-original-commit: d6e742c
@qucol-odoo qucol-odoo force-pushed the saas-19.3-saas-18.3-opw-5479900-subcontracting_location-qucol-527900-fw branch from 1142f64 to 00f2eae Compare May 20, 2026 12:21
@qucol-odoo
Copy link
Copy Markdown
Contributor

Only merging the test, as the fix is no longer required in 19.3 because the exchange move has is_subcontract set to False. If this ever changes, the same fix from the original PR can be applied.

@robodoo r+

robodoo pushed a commit that referenced this pull request May 20, 2026
## 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.

## 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

closes #265452

X-original-commit: d6e742c
Signed-off-by: Quentin Colla (qucol) <qucol@odoo.com>
@robodoo robodoo closed this May 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

conflict There was an error while creating this forward-port PR forwardport This PR was created by @fw-bot

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants