Skip to content

Commit

Permalink
split method to compute price_subtotal
Browse files Browse the repository at this point in the history
  • Loading branch information
damdam-s committed Oct 20, 2023
1 parent 09ac786 commit da59763
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 17 deletions.
12 changes: 9 additions & 3 deletions contract/models/abstract_contract_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
24 changes: 10 additions & 14 deletions contract_fixed_discount/models/contract_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
subtotal = 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):
Expand Down

0 comments on commit da59763

Please sign in to comment.