[14.0][IMP] account_payment_order: Improve normal communication if there is a credit note

If there is a credit note that partially cancel an invoice, the payment communication
should be the combination of the invoice reference and the credit note one.
This commit is contained in:
Denis Roussel
2022-04-14 11:16:37 +02:00
parent da8e2da5bb
commit becc8ac426
2 changed files with 52 additions and 0 deletions

View File

@@ -71,6 +71,12 @@ class AccountMoveLine(models.Model):
elif "out" in self.move_id.move_type:
# Force to only put invoice number here
communication = 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")
communication += " " + " ".join(references)
return communication_type, communication
def _prepare_payment_line_vals(self, payment_order):

View File

@@ -6,6 +6,7 @@ from datetime import date, datetime, timedelta
from odoo import fields
from odoo.exceptions import UserError, ValidationError
from odoo.tests.common import Form
from odoo.addons.account.tests.common import AccountTestInvoicingCommon
@@ -85,6 +86,20 @@ class TestPaymentOrderOutboundBase(AccountTestInvoicingCommon):
return invoice
def _create_supplier_refund(self, move):
wizard = (
self.env["account.move.reversal"]
.with_context(active_model="account.move", active_ids=move.ids)
.create(
{
"date_mode": "custom",
"refund_method": "refund",
}
)
)
wizard.reverse_moves()
return wizard.new_move_ids
class TestPaymentOrderOutbound(TestPaymentOrderOutboundBase):
def test_creation_due_date(self):
@@ -261,3 +276,34 @@ class TestPaymentOrderOutbound(TestPaymentOrderOutboundBase):
self.assertEqual(
outbound_order.payment_line_ids[1].bank_line_id.date, date.today()
)
def test_supplier_refund(self):
"""
Confirm the supplier invoice
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 reference
and the credit note one
"""
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("F1242 R1234", payment_order.payment_line_ids.communication)