[14.0][IMP] account_payment_order: Use the 'payment_reference' field if filled in

This commit is contained in:
Denis Roussel
2022-04-14 13:40:43 +02:00
parent 919928e98f
commit 18495aaf03
2 changed files with 40 additions and 5 deletions

View File

@@ -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

View File

@@ -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)