Skip to content

Commit

Permalink
[IMP] sale_order_general_discount: Add context in tests to prevent po…
Browse files Browse the repository at this point in the history
…tential related errors in other addons.
  • Loading branch information
carlos-lopez-tecnativa committed Jan 9, 2025
1 parent 31536b6 commit 58dcdfe
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
7 changes: 7 additions & 0 deletions sale_order_general_discount/models/sale_order_line.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Copyright 2018 Tecnativa - Sergio Teruel
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import api, fields, models
from odoo.tools import config


class SaleOrderLine(models.Model):
Expand All @@ -15,6 +16,12 @@ class SaleOrderLine(models.Model):
@api.depends("order_id", "order_id.general_discount")
def _compute_discount(self):
res = super()._compute_discount()
test_condition = not config["test_enable"] or (
config["test_enable"]
and self.env.context.get("test_sale_order_general_discount")
)
if not test_condition:
return res
for line in self:
# We check the value of general_discount on origin too to cover
# the case where a discount was set to a value != 0 and then
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ class TestSaleOrderLineInput(TransactionCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.env = cls.env(
context=dict(cls.env.context, test_sale_order_general_discount=True)
)
cls.partner = cls.env["res.partner"].create(
{"name": "Test", "sale_discount": 10.0}
)
Expand Down

0 comments on commit 58dcdfe

Please sign in to comment.