From b7e7383d9a3df6e052cd3702625708615fc093fb Mon Sep 17 00:00:00 2001 From: Ethan Hildick Date: Tue, 25 Jul 2023 17:03:16 +0200 Subject: [PATCH] [FIX] account_payment_order: incorrect inbound partial reconciliations - Also added float_compare to avoid possible rounding issues --- account_payment_order/models/account_payment_order.py | 11 ++++++++++- .../tests/test_payment_order_inbound.py | 4 ++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/account_payment_order/models/account_payment_order.py b/account_payment_order/models/account_payment_order.py index 9d11408fc..6380eb048 100644 --- a/account_payment_order/models/account_payment_order.py +++ b/account_payment_order/models/account_payment_order.py @@ -8,6 +8,7 @@ import base64 from odoo import _, api, fields, models from odoo.exceptions import UserError, ValidationError +from odoo.tools import float_compare class AccountPaymentOrder(models.Model): @@ -433,7 +434,15 @@ class AccountPaymentOrder(models.Model): for line in payment.payment_line_ids: if not line.move_line_id: continue - if line.amount_currency != -line.move_line_id.amount_residual_currency: + sign = -1 if payment.payment_order_id.payment_type == "outbound" else 1 + if ( + float_compare( + line.amount_currency, + (line.move_line_id.amount_residual_currency * sign), + precision_rounding=line.move_line_id.currency_id.rounding, + ) + != 0 + ): if line.move_line_id.amount_residual_currency < 0: debit_move_id = payment_move_line_id.id credit_move_id = line.move_line_id.id diff --git a/account_payment_order/tests/test_payment_order_inbound.py b/account_payment_order/tests/test_payment_order_inbound.py index 3903665f5..b6d730bc5 100644 --- a/account_payment_order/tests/test_payment_order_inbound.py +++ b/account_payment_order/tests/test_payment_order_inbound.py @@ -111,6 +111,10 @@ class TestPaymentOrderInbound(TestPaymentOrderInboundBase): self.assertEqual(payment_order.state, "uploaded") with self.assertRaises(UserError): payment_order.unlink() + matching_number = ( + payment_order.payment_ids.payment_line_ids.move_line_id.matching_number + ) + self.assertTrue(matching_number and matching_number != "P") payment_order.action_uploaded_cancel() self.assertEqual(payment_order.state, "cancel")