diff --git a/account_payment_order/models/account_move_line.py b/account_payment_order/models/account_move_line.py index 0f9fadd3b..0638c4ddc 100644 --- a/account_payment_order/models/account_move_line.py +++ b/account_payment_order/models/account_move_line.py @@ -67,15 +67,17 @@ class AccountMoveLine(models.Model): self.move_id.move_type in ("in_invoice", "in_refund") and self.move_id.ref ): - communication = self.move_id.ref + communication = self.move_id.payment_reference or self.move_id.ref elif "out" in self.move_id.move_type: # Force to only put invoice number here - communication = self.move_id.name + communication = self.move_id.payment_reference or self.move_id.name # If we have credit note(s) - reversal_move_id is a one2many if self.move_id.reversal_move_id: - references = self.move_id.reversal_move_id.filtered( - lambda r: r.ref - ).mapped("ref") + references = [ + move.payment_reference or move.ref + for move in self.move_id.reversal_move_id + if move.payment_reference or move.ref + ] communication += " " + " ".join(references) return communication_type, communication diff --git a/account_payment_order/tests/test_payment_order_outbound.py b/account_payment_order/tests/test_payment_order_outbound.py index 2e2ab8d7d..e751985c7 100644 --- a/account_payment_order/tests/test_payment_order_outbound.py +++ b/account_payment_order/tests/test_payment_order_outbound.py @@ -307,3 +307,36 @@ class TestPaymentOrderOutbound(TestPaymentOrderOutboundBase): self.assertEqual(len(payment_order.payment_line_ids), 1) self.assertEqual("F1242 R1234", payment_order.payment_line_ids.communication) + + def test_supplier_refund_reference(self): + """ + Confirm the supplier invoice + Set a payment referece + Create a credit note based on that one with an inferior amount + Confirm the credit note + Create the payment order + The communication should be a combination of the invoice payment reference + and the credit note one + """ + self.invoice.payment_reference = "F/1234" + self.invoice.action_post() + self.refund = self._create_supplier_refund(self.invoice) + with Form(self.refund) as refund_form: + refund_form.ref = "R1234" + with refund_form.invoice_line_ids.edit(0) as line_form: + line_form.price_unit = 75.0 + + self.refund.action_post() + + self.env["account.invoice.payment.line.multi"].with_context( + active_model="account.move", active_ids=self.invoice.ids + ).create({}).run() + + payment_order = self.env["account.payment.order"].search(self.domain) + self.assertEqual(len(payment_order), 1) + + payment_order.write({"journal_id": self.bank_journal.id}) + + self.assertEqual(len(payment_order.payment_line_ids), 1) + + self.assertEqual("F/1234 R1234", payment_order.payment_line_ids.communication)