Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion purchase_order_general_discount/models/purchase_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def _get_general_discount_field(self):
discount_field = self.company_id.purchase_general_discount_field
return discount_field or "discount"

@api.onchange("general_discount", "order_line")
@api.onchange("general_discount")
def onchange_general_discount(self):
discount_field = self._get_general_discount_field()
self.mapped("order_line").update({discount_field: self.general_discount})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,29 @@ def test_03_get_view_set_default_line_discount_value(self):
order_form.general_discount = 10
with order_form.order_line.edit(0) as line_form:
self.assertEqual(line_form.discount, 10)

def test_04_manual_line_discount_not_overwritten(self):
"""Ensure manual line discount is not overridden by general discount onchange.
Scenario:
- Apply a general discount → it propagates to all lines.
- Modify the discount manually on a line.
- Ensure the manual value is preserved.
This validates that the onchange is no longer triggered on order_line changes.
"""
company = self.order.company_id
company.purchase_general_discount_field = "discount"
po_form_view_xmlid = "purchase_order_general_discount.purchase_order_form"
with Form(self.order, po_form_view_xmlid) as order_form:
# Step 1: Apply global discount
order_form.general_discount = 10
# Step 2: Manually override line discount
with order_form.order_line.edit(0) as line_form:
line_form.discount = 20
# Step 3: Re-open line and verify value is preserved
with order_form.order_line.edit(0) as line_form:
self.assertEqual(
line_form.discount,
20,
"Manual discount should not be overridden by general "
"discount onchange",
)
Loading