From a8319e3ce57faebe30654a7fe3f376d7950ddb42 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Bidoul?= Date: Wed, 14 Aug 2024 11:18:09 +0200 Subject: [PATCH] [FIX] account_payment_order: use payment_reference if present for out payments When a payment reference (field `payment_reference`) is provided on the vendor bill, it should be used in priority over the vendor bill number (field `ref`). One reason is that the `ref` field is different for each invoice of the same supplier (it is used in Odoo's standard duplicate warning), but the payment reference maybe the same for all payments to the same supplier. For instance some suppliers request that the customer id is used on the payment communication and it is the same on all their invoices. Another reason is that some supplier use a structured payment communication scheme, and that one only makes sense in the payment_reference field. --- account_payment_order/models/account_move.py | 2 +- .../tests/test_payment_order_outbound.py | 21 ++++++++++++++----- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/account_payment_order/models/account_move.py b/account_payment_order/models/account_move.py index 9ce61841d..b061a8912 100644 --- a/account_payment_order/models/account_move.py +++ b/account_payment_order/models/account_move.py @@ -52,7 +52,7 @@ class AccountMove(models.Model): communication = self.payment_reference or self.ref or self.name if self.is_invoice(): if self.is_purchase_document(): - communication = self.ref or self.payment_reference + communication = self.payment_reference or self.ref else: communication = self.payment_reference or self.name return communication or "" diff --git a/account_payment_order/tests/test_payment_order_outbound.py b/account_payment_order/tests/test_payment_order_outbound.py index e52e36a71..62f55680e 100644 --- a/account_payment_order/tests/test_payment_order_outbound.py +++ b/account_payment_order/tests/test_payment_order_outbound.py @@ -304,10 +304,13 @@ class TestPaymentOrderOutbound(TestPaymentOrderOutboundBase): ) def test_invoice_communication_02(self): - self.invoice.payment_reference = "R1234" self.assertEqual( "F1242", self.invoice._get_payment_order_communication_direct() ) + self.invoice.payment_reference = "R1234" + self.assertEqual( + "R1234", self.invoice._get_payment_order_communication_direct() + ) def test_invoice_communication_03(self): self.invoice.ref = False @@ -331,6 +334,13 @@ class TestPaymentOrderOutbound(TestPaymentOrderOutboundBase): self.invoice._get_payment_order_communication_full(), ) + def test_supplier_invoice_payment_reference(self): + self.invoice.payment_reference = "+++F1234+++" + self.invoice.action_post() + self.assertEqual( + "+++F1234+++", self.invoice._get_payment_order_communication_full() + ) + def test_manual_line_and_manual_date(self): # Create payment order outbound_order = self.env["account.payment.order"].create( @@ -433,7 +443,7 @@ class TestPaymentOrderOutbound(TestPaymentOrderOutboundBase): self.invoice.payment_reference = "F/1234" self.invoice.action_post() self.assertEqual( - "F1242", self.invoice._get_payment_order_communication_direct() + "F/1234", self.invoice._get_payment_order_communication_direct() ) self.refund = self._create_supplier_refund(self.invoice) with Form(self.refund) as refund_form: @@ -443,7 +453,9 @@ class TestPaymentOrderOutbound(TestPaymentOrderOutboundBase): line_form.price_unit = 75.0 self.refund.action_post() - self.assertEqual("R1234", self.refund._get_payment_order_communication_direct()) + self.assertEqual( + "FR/1234", self.refund._get_payment_order_communication_direct() + ) # The user add the outstanding payment to the invoice invoice_line = self.invoice.line_ids.filtered( @@ -465,8 +477,7 @@ class TestPaymentOrderOutbound(TestPaymentOrderOutboundBase): self.assertEqual(len(payment_order.payment_line_ids), 1) - self.assertEqual("F1242 R1234", payment_order.payment_line_ids.communication) - self.assertNotIn("FR/1234", payment_order.payment_line_ids.communication) + self.assertEqual("F/1234 FR/1234", payment_order.payment_line_ids.communication) def test_supplier_manual_refund(self): """