Skip to content

[17.0][FIX] purchase_order_general_discount: prevent overriding manual line discounts#3037

Draft
atgalvez08 wants to merge 1 commit intoOCA:17.0from
BinhexTeam:17.0-fix-purchase_order_general_discount
Draft

[17.0][FIX] purchase_order_general_discount: prevent overriding manual line discounts#3037
atgalvez08 wants to merge 1 commit intoOCA:17.0from
BinhexTeam:17.0-fix-purchase_order_general_discount

Conversation

@atgalvez08
Copy link
Copy Markdown

@atgalvez08 atgalvez08 commented Apr 29, 2026

@BinhexTeam

Problem

When modifying discounts on purchase order lines, the onchange defined in
purchase_order_general_discount is triggered due to the dependency on
order_line.

This causes the general discount to be reapplied automatically,
overriding any manual changes performed by the user.

Root cause

The onchange decorator includes order_line:

@api.onchange("general_discount", "order_line")

This causes the method to be triggered on any modification of order lines.

Solution

Restrict the onchange trigger to general_discount only.

Result

  • Changing general discount applies to all lines ✔
  • Manual edits on line discounts are preserved ✔
  • No unintended overwrites occur ✔

Tests

A new test has been added to ensure that manual overrides on line discounts
are not lost after editing.

Notes

This issue becomes especially visible when using modules such as
purchase_triple_discount, but can affect any module that modifies
line-level discounts.

…iscounts

The onchange method was triggered on both `general_discount` and `order_line`,
causing manual modifications on purchase order lines to be overridden by
the general discount.

This patch restricts the onchange trigger to `general_discount` only,
ensuring that manual edits on line discounts are preserved.

A new test has been added to ensure that manual overrides are not lost.
@OCA-git-bot OCA-git-bot added series:17.0 mod:purchase_order_general_discount Module purchase_order_general_discount labels Apr 29, 2026
@atgalvez08 atgalvez08 marked this pull request as ready for review April 29, 2026 07:46
Copy link
Copy Markdown

@rrebollo rrebollo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given the nature of the issue you’re facing, especially since it also involves interaction with another module that affects discounts—but without an explicit hard dependency between them—it may be worth revisiting whether removing that field as an onchange trigger is actually justified.

We should verify the legitimacy of that trigger in the first place, because the addon documentation explicitly mentions peaceful coexistence with the triple discount module. That suggests compatibility was at least an intended design goal.

From a first look, the fix being proposed feels somewhat aggressive. A more conservative approach might be preferable before altering trigger behavior globally.

For example, it could be worth exploring whether the onchange can selectively ignore or filter purchase order lines in the scenarios where recalculation should not happen, instead of removing the trigger entirely. That would reduce regression risk and better preserve expected behavior for existing users.
https://github.com/OCA/purchase-workflow/blob/18.0/purchase_order_general_discount/README.rst#configuration

@atgalvez08 atgalvez08 marked this pull request as draft April 30, 2026 10:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

mod:purchase_order_general_discount Module purchase_order_general_discount series:17.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants