Skip to content

[FIX] purchase_stock_ux: fix received qty on exchange returns#341

Open
jcadhoc wants to merge 1 commit into
ingadhoc:19.0from
adhoc-dev:19.0-t-65271-jc
Open

[FIX] purchase_stock_ux: fix received qty on exchange returns#341
jcadhoc wants to merge 1 commit into
ingadhoc:19.0from
adhoc-dev:19.0-t-65271-jc

Conversation

@jcadhoc

@jcadhoc jcadhoc commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

Problem

When doing an exchange return ("devolución para cambio") on a purchase receipt, the received quantity ends up higher than the ordered quantity (e.g. 14 received against 10 ordered).

Exchange return moves have to_refund=False, so the return move does not reduce qty_received, while the replacement receipt adds it again. purchase_stock_ux had no notion of exchange moves, so the two never netted out.

Fix

Mirror the approach already shipping in sale_stock_ux for qty_delivered:

  • Add an is_exchange_move flag on stock.move (and keep it out of move merging).
  • Override stock.return.picking to tag exchange moves with the flag (and block exchange + "to refund" together), so it works even without sale_stock_ux installed.
  • In _compute_qty_received, after the base computation, subtract incoming exchange moves (the replacement receipt) and add back outgoing ones, leaving the exchange neutral on the received qty.

The "Returned" column stays at 0 for exchanges on purpose: an exchange is not a refund-return; the correction belongs in qty_received.

Test

Added test_exchange_return.py reproducing the flow: receive 10 → exchange-return 4 → receive replacement 4, asserting qty_received == 10 (was 14).

Task #65271.

Exchange returns ('devolución para cambio') have to_refund=False, so the
return move did not reduce qty_received while the replacement receipt added
it again, leaving qty_received above the ordered qty (e.g. 14 vs 10).

Mirror the sale_stock_ux approach: tag exchange moves with is_exchange_move
and net them out in _compute_qty_received (subtract incoming exchange moves,
add back outgoing ones). Also add the stock.return.picking override so the
flag is set even without sale_stock_ux installed.
@roboadhoc

Copy link
Copy Markdown
Contributor

Pull request status dashboard

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants