Merge PR #918 into 14.0

Signed-off-by pedrobaeza
This commit is contained in:
OCA-git-bot
2022-04-14 14:59:13 +00:00
5 changed files with 105 additions and 6 deletions

View File

@@ -48,9 +48,10 @@ class AccountMoveLine(models.Model):
else:
ml.partner_bank_id = ml.partner_bank_id
def _prepare_payment_line_vals(self, payment_order):
self.ensure_one()
assert payment_order, "Missing payment order"
def _get_communication(self):
"""
Retrieve the communication string for the payment order
"""
aplo = self.env["account.payment.line"]
# default values for communication_type and communication
communication_type = "normal"
@@ -66,10 +67,23 @@ 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 = [
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
def _prepare_payment_line_vals(self, payment_order):
self.ensure_one()
communication_type, communication = self._get_communication()
if self.currency_id:
currency_id = self.currency_id.id
amount_currency = self.amount_residual_currency

View File

@@ -11,6 +11,8 @@
* Angel Moya <angel.moya@domatix.com>
* Jose María Alzaga <jose.alzaga@aselcis.com>
* Meyomesse Gilles <meyomesse.gilles@gmail.com>
* Denis Roussel <denis.roussel@acsone.eu>
* `DynApps <https://www.dynapps.be>`_:
* Raf Ven <raf.ven@dynapps.be>

View File

@@ -1,10 +1,12 @@
# Copyright 2019 ACSONE SA/NV
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo.tests.common import tagged
from odoo.addons.account.tests.common import AccountTestInvoicingCommon
@tagged("post_install", "-at_install")
class TestAccountPayment(AccountTestInvoicingCommon):
@classmethod
def setUpClass(cls, chart_template_ref=None):

View File

@@ -6,7 +6,7 @@
from datetime import date, timedelta
from odoo.exceptions import UserError, ValidationError
from odoo.tests.common import Form
from odoo.tests.common import Form, tagged
from odoo.addons.account.tests.common import AccountTestInvoicingCommon
@@ -77,6 +77,7 @@ class TestPaymentOrderInboundBase(AccountTestInvoicingCommon):
return invoice_form.save()
@tagged("post_install", "-at_install")
class TestPaymentOrderInbound(TestPaymentOrderInboundBase):
def test_constrains_type(self):
with self.assertRaises(ValidationError):

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, tagged
from odoo.addons.account.tests.common import AccountTestInvoicingCommon
@@ -85,7 +86,22 @@ 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
@tagged("post_install", "-at_install")
class TestPaymentOrderOutbound(TestPaymentOrderOutboundBase):
def test_creation_due_date(self):
self.mode.variable_journal_ids = self.bank_journal
@@ -261,3 +277,67 @@ 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)
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)