From 8797228698997ec29f66194a5db87eff4a7c7a3a Mon Sep 17 00:00:00 2001 From: Jordi Ballester Alomar Date: Fri, 28 Jun 2024 18:59:54 +0200 Subject: [PATCH] [FIX] account_banking_ach_discount: Only generate write-off if there's an amout to write-off and a write-off account --- .../models/account_payment_line.py | 29 ++++++++++++++----- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/account_banking_ach_discount/models/account_payment_line.py b/account_banking_ach_discount/models/account_payment_line.py index dc7eb29f..62c3f5c8 100644 --- a/account_banking_ach_discount/models/account_payment_line.py +++ b/account_banking_ach_discount/models/account_payment_line.py @@ -1,6 +1,8 @@ # Copyright (C) 2019 Open Source Integrators # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -from odoo import models +from odoo import _, models +from odoo.exceptions import UserError +from odoo.tools.float_utils import float_is_zero class AccountPaymentOrder(models.Model): @@ -16,11 +18,22 @@ def _prepare_account_payment_vals(self): payment_difference = self.payment_difference if self.payment_type == "outbound": payment_difference *= -1 - write_off_line_vals = { - "account_id": self.writeoff_account_id.id, - "name": note, - "amount_currency": payment_difference, - "balance": payment_difference, - } - values["write_off_line_vals"] = [write_off_line_vals] + if not float_is_zero( + payment_difference, precision_digits=self.currency_id.decimal_places + ): + if not self.writeoff_account_id: + raise UserError( + _( + "A payment difference was found, " + "but you need to indicicate a corresponding " + "writeoff account." + ) + ) + write_off_line_vals = { + "account_id": self.writeoff_account_id.id, + "name": note, + "amount_currency": payment_difference, + "balance": payment_difference, + } + values["write_off_line_vals"] = [write_off_line_vals] return values