From 1d57f3b335c9ec19c7e1947adacdbcd37d73acf3 Mon Sep 17 00:00:00 2001 From: Pablo Montenegro Date: Fri, 1 Mar 2024 08:56:21 -0300 Subject: [PATCH] [FIX] account: resequence journal with payment sequence set to False Resequencing entries that come from payment and non payment raise a UserError, even if the journal has `payment_sequence` set to False Steps to reproduce: 1) Go to "Accounting / Configuration / Accounting / Journals" and create a new journal with type "Bank" and "Dedicated Payment Sequence" in False. 2) Create a "Bank Statement Line" in the journal created in step "1". 3) Create and confirm a customer payment using the journal created in step "1". 4) Go to "Accounting / Accounting / Journals / Journal Entries". Select journal entries created on step "2" and "3" and then click on Action --> Resequence. Then a User Error is being show "The sequences of this journal are different for Payments and non-Payments but you selected some of both types." it is not correct as the journal created on step "1" has the field "Dedicated Payment Sequence" set to "False". opw-3763500 closes odoo/odoo#159003 X-original-commit: 11d71cf1b244174c12c0094eb2f0f072894aecc6 Signed-off-by: Brice Bartoletti (bib) Signed-off-by: Guillaume Vanleynseele (guva) --- addons/account/tests/test_sequence_mixin.py | 20 ++++++++++++++++++++ addons/account/wizard/account_resequence.py | 5 ++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/addons/account/tests/test_sequence_mixin.py b/addons/account/tests/test_sequence_mixin.py index 2f642d91973..558946378e7 100644 --- a/addons/account/tests/test_sequence_mixin.py +++ b/addons/account/tests/test_sequence_mixin.py @@ -639,6 +639,26 @@ class TestSequenceMixin(TestSequenceMixinCommon): for move in payments.move_id: self.assertRecordValues(move.line_ids, [{'move_name': move.name}] * len(move.line_ids)) + def test_resequence_payment_and_non_payment_without_payment_sequence(self): + """Resequence wizard could be open for different move type if the payment sequence is set to False on the journal.""" + journal = self.company_data['default_journal_bank'].copy({'payment_sequence': False}) + bsl = self.env['account.bank.statement.line'].create({'name': 'test', 'amount': 100, 'journal_id': journal.id}) + payment = self.env['account.payment'].create({ + 'payment_type': 'inbound', + 'partner_id': self.partner_a.id, + 'amount': 100, + 'journal_id': journal.id, + }) + + payment.action_post() + wizard = Form(self.env['account.resequence.wizard'].with_context( + active_ids=(payment.move_id + bsl.move_id).ids, + active_model='account.move'), + ) + + wizard.save().resequence() + self.assertTrue(wizard) + @tagged('post_install', '-at_install') class TestSequenceMixinDeletion(TestSequenceMixinCommon): diff --git a/addons/account/wizard/account_resequence.py b/addons/account/wizard/account_resequence.py index 417cbd3dfe2..737ffc7f11c 100644 --- a/addons/account/wizard/account_resequence.py +++ b/addons/account/wizard/account_resequence.py @@ -40,7 +40,10 @@ class ReSequenceWizard(models.TransientModel): ): raise UserError(_('The sequences of this journal are different for Invoices and Refunds but you selected some of both types.')) is_payment = set(active_move_ids.mapped(lambda x: bool(x.payment_id))) - if len(is_payment) > 1: + if ( + active_move_ids.journal_id.payment_sequence + and len(is_payment) > 1 + ): raise UserError(_('The sequences of this journal are different for Payments and non-Payments but you selected some of both types.')) values['move_ids'] = [(6, 0, active_move_ids.ids)] return values