From 718ffc6fccdf50ebb16fb4c6afb74b76b272e742 Mon Sep 17 00:00:00 2001 From: majouda Date: Tue, 9 Apr 2024 17:47:30 -0400 Subject: [PATCH 1/3] TA#64546 [FIX] account_payment_term_discount: Difference in rounding --- account_payment_term_discount/models/account_move.py | 6 +++++- .../wizard/account_payment_register.py | 9 +++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/account_payment_term_discount/models/account_move.py b/account_payment_term_discount/models/account_move.py index 28a12722c2d8..427ff1f96b1e 100644 --- a/account_payment_term_discount/models/account_move.py +++ b/account_payment_term_discount/models/account_move.py @@ -3,6 +3,7 @@ from dateutil.relativedelta import relativedelta from odoo import api, fields, models +from odoo.tools import float_round class AccountMove(models.Model): @@ -43,7 +44,10 @@ def _compute_discount_amt(self): ) ) if discount_information[0] > 0.0: - invoice.discount_amt = abs(round(discount_information[0], 2)) + rounding = invoice.currency_id.rounding + invoice.discount_amt = abs( + float_round(discount_information[0], rounding) + ) # If discount taken make disc amt to 0 as disc is no more valid if invoice.discount_taken != 0: invoice.discount_amt = 0 diff --git a/account_payment_term_discount/wizard/account_payment_register.py b/account_payment_term_discount/wizard/account_payment_register.py index f46fac68785a..0257d101e02f 100644 --- a/account_payment_term_discount/wizard/account_payment_register.py +++ b/account_payment_term_discount/wizard/account_payment_register.py @@ -4,6 +4,7 @@ from odoo import _, api, fields, models from odoo.exceptions import UserError +from odoo.tools import float_round class AccountPaymentRegister(models.TransientModel): @@ -45,7 +46,8 @@ def onchange_payment_amount(self): payment_date = fields.Date.from_string(self.payment_date) discount_amt = self.invoice_id.discount_amt - payment_difference = self.payment_difference + rounding = self.invoice_id.currency_id.rounding + payment_difference = float_round(self.payment_difference, rounding) self.payment_difference = 0.0 if payment_date <= till_discount_date: @@ -103,9 +105,12 @@ 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(payment.payment_difference), + "discount_taken": abs( + float_round(payment.payment_difference, rounding) + ), "discount_amt": 0, } ) From 0f34f5cd807d751e2775d15153928218d1052921 Mon Sep 17 00:00:00 2001 From: majouda Date: Mon, 7 Oct 2024 10:35:49 -0400 Subject: [PATCH 2/3] TA#64546 [FIX] account_payment_term_discount: correct rounding --- account_payment_term_discount/models/account_move.py | 6 +----- .../models/account_payment_term.py | 4 ++-- .../wizard/account_payment_register.py | 10 ++-------- 3 files changed, 5 insertions(+), 15 deletions(-) diff --git a/account_payment_term_discount/models/account_move.py b/account_payment_term_discount/models/account_move.py index 427ff1f96b1e..a81bde465c37 100644 --- a/account_payment_term_discount/models/account_move.py +++ b/account_payment_term_discount/models/account_move.py @@ -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): @@ -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 diff --git a/account_payment_term_discount/models/account_payment_term.py b/account_payment_term_discount/models/account_payment_term.py index 8f88656c32a6..0d4989f74b55 100644 --- a/account_payment_term_discount/models/account_payment_term.py +++ b/account_payment_term_discount/models/account_payment_term.py @@ -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: @@ -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) diff --git a/account_payment_term_discount/wizard/account_payment_register.py b/account_payment_term_discount/wizard/account_payment_register.py index 0257d101e02f..b30af988e919 100644 --- a/account_payment_term_discount/wizard/account_payment_register.py +++ b/account_payment_term_discount/wizard/account_payment_register.py @@ -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): @@ -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: @@ -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, } ) From 10d96e0f61983c913740389e40afd781fe3b0346 Mon Sep 17 00:00:00 2001 From: "Lanto R." <124650562+lanto-razafindrabe@users.noreply.github.com> Date: Mon, 2 Dec 2024 15:41:31 +0300 Subject: [PATCH 3/3] TA#70253 [14.0][IMP] account_payment_term_discount : multi-company discount account --- account_payment_term_discount/models/account_payment_term.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/account_payment_term_discount/models/account_payment_term.py b/account_payment_term_discount/models/account_payment_term.py index 0d4989f74b55..419394dfa7e3 100644 --- a/account_payment_term_discount/models/account_payment_term.py +++ b/account_payment_term_discount/models/account_payment_term.py @@ -87,11 +87,15 @@ class AccountPaymentTermLine(models.Model): discount_income_account_id = fields.Many2one( "account.account", string="Discount on Purchases Account", + ondelete="restrict", + company_dependent=True, help="This account will be used to post the discount on purchases.", ) discount_expense_account_id = fields.Many2one( "account.account", string="Discount on Sales Account", + ondelete="restrict", + company_dependent=True, help="This account will be used to post the discount on sales.", )