Skip to content

Commit

Permalink
account_invoice_pricelist: Use setter for triple discount
Browse files Browse the repository at this point in the history
  • Loading branch information
grindtildeath authored and yvaucher committed Sep 30, 2024
1 parent b6d8fdc commit d762ff9
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions account_invoice_pricelist/models/account_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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"

Check warning on line 132 in account_invoice_pricelist/models/account_move.py

View check run for this annotation

Codecov / codecov/patch

account_invoice_pricelist/models/account_move.py#L132

Added line #L132 was not covered by tests
else:
fname = "discount"
self.with_context(check_move_validity=False)[fname] = amount

0 comments on commit d762ff9

Please sign in to comment.