summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgteboul <gute@odoo.com>2025-01-28 08:51:49 +0100
committergteboul <gute@odoo.com>2025-02-05 01:04:12 +0000
commit6aaa32c30b9f2cd5df19a1f285064b410599a803 (patch)
tree4e1f0b8d85780cfb57c880aeab76695bffc32765
parent1f03bcff8782b21efa2e5c4d0404d7fe96859fc2 (diff)
[FIX] account: correct payment resequence
- Configure an outstanding receipt account (e.g., Bank) for the Bank journal. - Create an invoice and process the payment. When attempting to resequence the journal entry corresponding to the `account.payment`, the journal entry is renamed, but the `account.payment` record is not updated accordingly. https://github.com/odoo/odoo/commit/01b87f1230beac0568f4e3b1b76e547909506892 made the journal entry optional for payments, which broke the resequence. opw-4437481 closes odoo/odoo#195382 Signed-off-by: William André (wan) <wan@odoo.com>
-rw-r--r--addons/account/models/account_payment.py2
-rw-r--r--addons/account/tests/test_account_payment.py34
2 files changed, 35 insertions, 1 deletions
diff --git a/addons/account/models/account_payment.py b/addons/account/models/account_payment.py
index dc5a15b1c87..3cfa6e95286 100644
--- a/addons/account/models/account_payment.py
+++ b/addons/account/models/account_payment.py
@@ -370,7 +370,7 @@ class AccountPayment(models.Model):
@api.depends('move_id.name', 'state')
def _compute_name(self):
for payment in self:
- if payment.id and not payment.name and payment.state in ('in_process', 'paid'):
+ if payment.id and (not payment.name or payment.move_id and payment.name != payment.move_id.name) and payment.state in ('in_process', 'paid'):
payment.name = (
payment.move_id.name
or self.env['ir.sequence'].with_company(payment.company_id).next_by_code(
diff --git a/addons/account/tests/test_account_payment.py b/addons/account/tests/test_account_payment.py
index 943e4c62d3c..e9258630251 100644
--- a/addons/account/tests/test_account_payment.py
+++ b/addons/account/tests/test_account_payment.py
@@ -684,3 +684,37 @@ class TestAccountPayment(AccountTestInvoicingCommon):
create_statement_line_and_reconcile(payment=payment, amount=invoice.amount_total / 2)
payment = register_payment(invoice, line_without_outstanding, invoice.amount_total / 2)
create_statement_line_and_reconcile(invoice=invoice, amount=invoice.amount_total / 2)
+
+ def test_resequence_change_payment_name(self):
+ """
+ Test that when resequencing the journal entry corresponding to a payment, the payment is also renamed
+ """
+ invoice = self.env['account.move'].create([{
+ 'move_type': 'out_invoice',
+ 'partner_id': self.partner_a.id,
+ 'date': '2024-01-01',
+ 'invoice_line_ids': [Command.create({
+ 'name': 'test',
+ 'quantity': 1,
+ 'price_unit': 100.0,
+ })],
+ }])
+ invoice.action_post()
+
+ payment = self.env['account.payment.register']\
+ .with_context(active_model='account.move', active_ids=invoice.ids)\
+ .create({})\
+ ._create_payments()
+
+ payment.action_post()
+
+ wizard = self.env['account.resequence.wizard'].with_context({
+ 'active_ids': payment.move_id.ids,
+ 'active_model': 'account.move',
+ }).create({
+ 'first_name': 'PBNK1/2025/00002',
+ })
+ wizard.resequence()
+
+ self.assertEqual(payment.move_id.name, 'PBNK1/2025/00002')
+ self.assertEqual(payment.name, 'PBNK1/2025/00002')