diff --git a/account_invoice_pricelist/models/account_move.py b/account_invoice_pricelist/models/account_move.py index 8b4ce031fbc..37ea1de88ee 100644 --- a/account_invoice_pricelist/models/account_move.py +++ b/account_invoice_pricelist/models/account_move.py @@ -103,7 +103,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) @@ -123,7 +123,13 @@ def _get_price_with_pricelist(self): 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