Skip to content

Commit

Permalink
TA#64546 [FIX] account_payment_term_discount: correct rounding
Browse files Browse the repository at this point in the history
  • Loading branch information
majouda committed Oct 7, 2024
1 parent 718ffc6 commit 0f34f5c
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 15 deletions.
6 changes: 1 addition & 5 deletions account_payment_term_discount/models/account_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from dateutil.relativedelta import relativedelta

from odoo import api, fields, models
from odoo.tools import float_round


class AccountMove(models.Model):
Expand Down Expand Up @@ -44,10 +43,7 @@ def _compute_discount_amt(self):
)
)
if discount_information[0] > 0.0:
rounding = invoice.currency_id.rounding
invoice.discount_amt = abs(
float_round(discount_information[0], rounding)
)
invoice.discount_amt = abs(discount_information[0])
# If discount taken make disc amt to 0 as disc is no more valid
if invoice.discount_taken != 0:
invoice.discount_amt = 0
Expand Down
4 changes: 2 additions & 2 deletions account_payment_term_discount/models/account_payment_term.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def _get_payment_term_discount(self, invoice=None, payment_date=None, amount=0.0
)

if line.discount and payment_date <= till_discount_date:
payment_discount = round((amount * line.discount) / 100.0, 2)
payment_discount = (amount * line.discount) / 100.0
if invoice.move_type in ("out_invoice", "in_refund"):
discount_account_id = line.discount_expense_account_id.id
else:
Expand Down Expand Up @@ -99,4 +99,4 @@ class AccountPaymentTermLine(models.Model):
def OnchangeDiscount(self):
if not self.discount:
return {}
self.value_amount = round(1 - (self.discount / 100.0), 2)
self.value_amount = 1 - (self.discount / 100.0)

Check warning on line 102 in account_payment_term_discount/models/account_payment_term.py

View check run for this annotation

Codecov / codecov/patch

account_payment_term_discount/models/account_payment_term.py#L102

Added line #L102 was not covered by tests
10 changes: 2 additions & 8 deletions account_payment_term_discount/wizard/account_payment_register.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

from odoo import _, api, fields, models
from odoo.exceptions import UserError
from odoo.tools import float_round


class AccountPaymentRegister(models.TransientModel):
Expand Down Expand Up @@ -45,9 +44,7 @@ def onchange_payment_amount(self):
)
payment_date = fields.Date.from_string(self.payment_date)
discount_amt = self.invoice_id.discount_amt

rounding = self.invoice_id.currency_id.rounding
payment_difference = float_round(self.payment_difference, rounding)
payment_difference = self.payment_difference
self.payment_difference = 0.0

if payment_date <= till_discount_date:
Expand Down Expand Up @@ -105,12 +102,9 @@ def action_create_payments(self):
res = super().action_create_payments()
for payment in self:
if payment.payment_difference_handling == "reconcile":
rounding = payment.invoice_id.currency_id.rounding
payment.invoice_id.write(
{
"discount_taken": abs(
float_round(payment.payment_difference, rounding)
),
"discount_taken": abs(payment.payment_difference),
"discount_amt": 0,
}
)
Expand Down

0 comments on commit 0f34f5c

Please sign in to comment.