[14.0][FIX] account_payment_order: Don't duplicate communication reference

This commit is contained in:
Denis Roussel
2022-04-22 14:14:53 +02:00
parent e346c66e4b
commit c4e2f64334
2 changed files with 44 additions and 21 deletions

View File

@@ -48,6 +48,40 @@ class AccountMoveLine(models.Model):
else:
ml.partner_bank_id = ml.partner_bank_id
def _get_linked_move_communication(self):
"""
This will collect the references from referral moves:
- Reversal moves
- Partial payments
"""
self.ensure_one()
references = []
# Build a recordset to gather moves from which references have already
# taken in order to avoid duplicates
reference_moves = self.env["account.move"].browse()
# If we have credit note(s) - reversal_move_id is a one2many
if self.move_id.reversal_move_id:
references.extend(
[
move.payment_reference or move.ref
for move in self.move_id.reversal_move_id
if move.payment_reference or move.ref
]
)
reference_moves |= self.move_id.reversal_move_id
# Retrieve partial payments - e.g.: manual credit notes
for (
_,
_,
payment_move_line,
) in self.move_id._get_reconciled_invoices_partials():
payment_move = payment_move_line.move_id
if payment_move not in reference_moves and (
payment_move.payment_reference or payment_move.ref
):
references.append(payment_move.payment_reference or payment_move.ref)
return references
def _get_communication(self):
"""
Retrieve the communication string for the payment order
@@ -58,7 +92,6 @@ class AccountMoveLine(models.Model):
communication = self.ref or self.name
# change these default values if move line is linked to an invoice
if self.move_id.is_invoice():
references = []
if (self.move_id.reference_type or "none") != "none":
communication = self.move_id.ref
ref2comm_type = aplo.invoice_reference_type2communication_type()
@@ -72,26 +105,7 @@ class AccountMoveLine(models.Model):
elif "out" in self.move_id.move_type:
# Force to only put invoice number here
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.extend(
[
move.payment_reference or move.ref
for move in self.move_id.reversal_move_id
if move.payment_reference or move.ref
]
)
# Retrieve partial payments - e.g.: manual credit notes
for (
_,
_,
payment_move_line,
) in self.move_id._get_reconciled_invoices_partials():
payment_move = payment_move_line.move_id
if payment_move.payment_reference or payment_move.ref:
references.append(
payment_move.payment_reference or payment_move.ref
)
references = self._get_linked_move_communication()
if references:
communication += " " + " ".join(references)
return communication_type, communication

View File

@@ -353,6 +353,15 @@ class TestPaymentOrderOutbound(TestPaymentOrderOutboundBase):
self.refund.action_post()
# The user add the outstanding payment to the invoice
invoice_line = self.invoice.line_ids.filtered(
lambda line: line.account_internal_type == "payable"
)
refund_line = self.refund.line_ids.filtered(
lambda line: line.account_internal_type == "payable"
)
(invoice_line | refund_line).reconcile()
self.env["account.invoice.payment.line.multi"].with_context(
active_model="account.move", active_ids=self.invoice.ids
).create({}).run()