diff --git a/contract/models/abstract_contract_line.py b/contract/models/abstract_contract_line.py index ba84f6f2995..8d89858ad70 100644 --- a/contract/models/abstract_contract_line.py +++ b/contract/models/abstract_contract_line.py @@ -217,12 +217,18 @@ def _inverse_price_unit(self): for line in self.filtered(lambda x: not x.automatic_price): line.specific_price = line.price_unit + def _compute_price_subtotal_helper(self): + self.ensure_one() + subtotal = self.quantity * self.price_unit + discount = self.discount / 100 + subtotal *= 1 - discount + return subtotal + @api.depends("quantity", "price_unit", "discount") def _compute_price_subtotal(self): for line in self: - subtotal = line.quantity * line.price_unit - discount = line.discount / 100 - subtotal *= 1 - discount + subtotal = line._compute_price_subtotal_helper() + if line.contract_id.pricelist_id: cur = line.contract_id.pricelist_id.currency_id line.price_subtotal = cur.round(subtotal) diff --git a/contract_fixed_discount/models/contract_line.py b/contract_fixed_discount/models/contract_line.py index 7a1573de6ce..2ce445fc932 100644 --- a/contract_fixed_discount/models/contract_line.py +++ b/contract_fixed_discount/models/contract_line.py @@ -33,22 +33,18 @@ def _check_only_one_discount(self): _("You can only set one type of discount per line.") ) + def _compute_price_subtotal_helper(self): + self.ensure_one() + if self.discount: + return super()._compute_price_subtotal_helper() + elif self.discount_fixed: + subtotal = self.quantity * self.price_unit + subtotal -= self.discount_fixed + return subtotal + @api.depends("quantity", "price_unit", "discount", "discount_fixed") def _compute_price_subtotal(self): - for line in self: - subtotal = line.quantity * line.price_unit - - if line.discount: - discount = line.discount / 100 - subtotal *= 1 - discount - elif line.discount_fixed: - subtotal -= line.discount_fixed - - if line.contract_id.pricelist_id: - cur = line.contract_id.pricelist_id.currency_id - line.price_subtotal = cur.round(subtotal) - else: - line.price_subtotal = subtotal + super()._compute_price_subtotal() class ContractLine(models.Model):