Merge PR #1142 into 14.0

Signed-off-by pedrobaeza
This commit is contained in:
OCA-git-bot
2023-09-22 14:16:47 +00:00
7 changed files with 96 additions and 23 deletions

View File

@@ -27,6 +27,7 @@
"wizard/account_payment_line_create_view.xml",
"wizard/account_invoice_payment_line_multi_view.xml",
"views/account_payment_mode.xml",
"views/account_payment_views.xml",
"views/account_payment_order.xml",
"views/account_payment_line.xml",
"views/account_move_line.xml",

View File

@@ -39,6 +39,31 @@ class AccountMove(models.Model):
payment_mode = move.payment_mode_id
move.payment_order_ok = payment_mode.payment_order_ok
def _get_payment_order_communication(self):
"""
Retrieve the communication string for the payment order
"""
communication = self.payment_reference or self.ref or self.name or ""
if self.is_invoice():
if (self.reference_type or "none") != "none":
communication = self.ref
elif self.is_purchase_document():
communication = self.ref or self.payment_reference
else:
communication = self.payment_reference or self.name
# If we have credit note(s) - reversal_move_id is a one2many
if self.reversal_move_id:
references = []
references.extend(
[
move._get_payment_order_communication()
for move in self.reversal_move_id
if move.payment_reference or move.ref
]
)
communication += " " + " ".join(references)
return communication
def _prepare_new_payment_order(self, payment_mode=None):
self.ensure_one()
if payment_mode is None:

View File

@@ -53,16 +53,7 @@ class AccountMoveLine(models.Model):
# 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
reference_moves |= self.move_id.reversal_move_id
# Retrieve partial payments - e.g.: manual credit notes
for (
_,
@@ -73,7 +64,7 @@ class AccountMoveLine(models.Model):
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)
references.append(payment_move._get_payment_order_communication())
return references
def _get_communication(self):
@@ -83,22 +74,14 @@ class AccountMoveLine(models.Model):
aplo = self.env["account.payment.line"]
# default values for communication_type and communication
communication_type = "normal"
communication = self.ref or self.name or ""
communication = self.move_id._get_payment_order_communication()
# change these default values if move line is linked to an invoice
if self.move_id.is_invoice():
if (self.move_id.reference_type or "none") != "none":
communication = self.move_id.ref
ref2comm_type = aplo.invoice_reference_type2communication_type()
communication_type = ref2comm_type[self.move_id.reference_type]
else:
if (
self.move_id.move_type in ("in_invoice", "in_refund")
and 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.payment_reference or self.move_id.name
# Add references to communication from lines move
references = self._get_linked_move_communication()
if references:
communication += " " + " ".join(references)

View File

@@ -90,6 +90,19 @@ class TestPaymentOrderInbound(TestPaymentOrderInboundBase):
with self.assertRaises(ValidationError):
self.inbound_order.date_scheduled = date.today() - timedelta(days=1)
def test_invoice_communication_01(self):
self.assertEqual(
self.invoice.name, self.invoice._get_payment_order_communication()
)
self.invoice.ref = "R1234"
self.assertEqual(
self.invoice.name, self.invoice._get_payment_order_communication()
)
def test_invoice_communication_02(self):
self.invoice.payment_reference = "R1234"
self.assertEqual("R1234", self.invoice._get_payment_order_communication())
def test_creation(self):
payment_order = self.inbound_order
self.assertEqual(len(payment_order.ids), 1)

View File

@@ -251,6 +251,15 @@ class TestPaymentOrderOutbound(TestPaymentOrderOutboundBase):
with self.assertRaises(ValidationError):
outbound_order.date_scheduled = date.today() - timedelta(days=2)
def test_invoice_communication_01(self):
self.assertEqual("F1242", self.invoice._get_payment_order_communication())
self.invoice.ref = "F1243"
self.assertEqual("F1243", self.invoice._get_payment_order_communication())
def test_invoice_communication_02(self):
self.invoice.payment_reference = "R1234"
self.assertEqual("F1242", self.invoice._get_payment_order_communication())
def test_manual_line_and_manual_date(self):
# Create payment order
outbound_order = self.env["account.payment.order"].create(
@@ -319,7 +328,9 @@ class TestPaymentOrderOutbound(TestPaymentOrderOutboundBase):
"""
# Open both invoices
self.invoice.action_post()
self.assertEqual("F1242", self.invoice._get_payment_order_communication())
self.invoice_02.action_post()
self.assertEqual("F1243", self.invoice_02._get_payment_order_communication())
# Add to payment order using the wizard
self.env["account.invoice.payment.line.multi"].with_context(
@@ -371,6 +382,7 @@ class TestPaymentOrderOutbound(TestPaymentOrderOutboundBase):
and the credit note one
"""
self.invoice.action_post()
self.assertEqual("F1242", self.invoice._get_payment_order_communication())
self.refund = self._create_supplier_refund(self.invoice)
with Form(self.refund) as refund_form:
refund_form.ref = "R1234"
@@ -378,6 +390,7 @@ class TestPaymentOrderOutbound(TestPaymentOrderOutboundBase):
line_form.price_unit = 75.0
self.refund.action_post()
self.assertEqual("R1234", self.refund._get_payment_order_communication())
self.env["account.invoice.payment.line.multi"].with_context(
active_model="account.move", active_ids=self.invoice.ids
@@ -404,13 +417,16 @@ class TestPaymentOrderOutbound(TestPaymentOrderOutboundBase):
"""
self.invoice.payment_reference = "F/1234"
self.invoice.action_post()
self.assertEqual("F1242", self.invoice._get_payment_order_communication())
self.refund = self._create_supplier_refund(self.invoice)
with Form(self.refund) as refund_form:
refund_form.ref = "R1234"
refund_form.payment_reference = "FR/1234"
with refund_form.invoice_line_ids.edit(0) as line_form:
line_form.price_unit = 75.0
self.refund.action_post()
self.assertEqual("R1234", self.refund._get_payment_order_communication())
# The user add the outstanding payment to the invoice
invoice_line = self.invoice.line_ids.filtered(
@@ -432,7 +448,8 @@ class TestPaymentOrderOutbound(TestPaymentOrderOutboundBase):
self.assertEqual(len(payment_order.payment_line_ids), 1)
self.assertEqual("F/1234 R1234", payment_order.payment_line_ids.communication)
self.assertEqual("F1242 R1234", payment_order.payment_line_ids.communication)
self.assertNotIn("FR/1234", payment_order.payment_line_ids.communication)
def test_supplier_manual_refund(self):
"""
@@ -445,11 +462,13 @@ class TestPaymentOrderOutbound(TestPaymentOrderOutboundBase):
and the credit note one
"""
self.invoice.action_post()
self.assertEqual("F1242", self.invoice._get_payment_order_communication())
self.refund = self._create_supplier_refund(self.invoice, manual=True)
with Form(self.refund) as refund_form:
refund_form.ref = "R1234"
self.refund.action_post()
self.assertEqual("R1234", self.refund._get_payment_order_communication())
(self.invoice.line_ids + self.refund.line_ids).filtered(
lambda line: line.account_internal_type == "payable"

View File

@@ -126,7 +126,12 @@
string="Payment Transactions"
attrs="{'invisible': [('state', 'in', ('draft', 'cancel'))]}"
>
<field name="payment_ids" edit="0" create="0" />
<field
name="payment_ids"
edit="0"
create="0"
context="{'tree_view_ref': 'account_payment_order.view_account_payment_tree_payment_order'}"
/>
</page>
</notebook>
</sheet>

View File

@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<record id="view_account_payment_tree_payment_order" model="ir.ui.view">
<field name="name">account.payment.tree</field>
<field name="model">account.payment</field>
<field name="mode">primary</field>
<field name="inherit_id" ref="account.view_account_payment_tree" />
<field name="arch" type="xml">
<field name="name" position="after">
<field name="payment_reference" />
</field>
</field>
</record>
<record id="view_account_payment_form" model="ir.ui.view">
<field name="name">account.payment.form</field>
<field name="model">account.payment</field>
<field name="inherit_id" ref="account.view_account_payment_form" />
<field name="arch" type="xml">
<field name="ref" position="after">
<field
name="payment_reference"
attrs="{'invisible': [('payment_reference', '=', False)]}"
/>
</field>
</field>
</record>
</odoo>