From 528ae9a74c94aa4a0a834fcee4de492d1dd64757 Mon Sep 17 00:00:00 2001 From: Akim Juillerat Date: Fri, 28 Jun 2024 16:37:43 +0200 Subject: [PATCH] account_invoice_pricelist: Use setter for triple discount --- account_invoice_pricelist/models/account_move.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/account_invoice_pricelist/models/account_move.py b/account_invoice_pricelist/models/account_move.py index b2f63e3302b..227a33b1cdd 100644 --- a/account_invoice_pricelist/models/account_move.py +++ b/account_invoice_pricelist/models/account_move.py @@ -104,7 +104,7 @@ def _get_price_with_pricelist(self): self.tax_ids, self.company_id, ) - self.with_context(check_move_validity=False).discount = 0.0 + self._set_discount(0.0) return price_unit else: rule_id = self.env["product.pricelist.item"].browse(rule_id) @@ -124,7 +124,13 @@ def _get_price_with_pricelist(self): target_currency=self.currency_id, ) price_unit = max(base_price, final_price) - self.with_context( - check_move_validity=False - ).discount = self._calculate_discount(base_price, final_price) + self._set_discount(self._calculate_discount(base_price, final_price)) return price_unit + + def _set_discount(self, amount): + if self.env["account.move.line"]._fields.get("discount1", False): + # OCA/account_invoice_triple_discount is installed + fname = "discount1" + else: + fname = "discount" + self.with_context(check_move_validity=False)[fname] = amount