From 5440bede828154b45469c5107e764361106c4905 Mon Sep 17 00:00:00 2001 From: guva-odoo Date: Wed, 31 Jan 2024 10:39:07 +0000 Subject: [PATCH] [FIX] account: account validate move wizard with force post Force post does not work in the validate account move wizard. Steps: - Create a move in the future and set it to be auto post - On the list view, select the move and select action "post entries" - On the wizard, check "force" and validate -> UserError "This move is configured to be auto-posted ..." closes odoo/odoo#152396 X-original-commit: f85f3bcc026882b2a088fcd46ca8e6dc59d6f2f0 Signed-off-by: Brice Bartoletti (bib) Signed-off-by: Guillaume Vanleynseele (guva) --- addons/account/tests/test_account_move_entry.py | 9 +++++++++ addons/account/wizard/account_validate_account_move.py | 2 ++ 2 files changed, 11 insertions(+) diff --git a/addons/account/tests/test_account_move_entry.py b/addons/account/tests/test_account_move_entry.py index fb3b8d6e7ad..c1ffc620a12 100644 --- a/addons/account/tests/test_account_move_entry.py +++ b/addons/account/tests/test_account_move_entry.py @@ -1160,3 +1160,12 @@ class TestAccountMove(AccountTestInvoicingCommon): with self.assertRaisesRegex(UserError, 'not balanced'), self.env.cr.savepoint(): stealer_move.write({'line_ids': [Command.link(honest_move.line_ids[0].id)]}) + + def test_validate_move_wizard_with_auto_post_entry(self): + """ Test that the wizard to validate a move with auto_post is working fine. """ + self.test_move.date = fields.Date.today() + relativedelta(months=3) + self.test_move.auto_post = 'at_date' + wizard = self.env['validate.account.move'].with_context(active_model='account.move', active_ids=self.test_move.ids).create({}) + wizard.force_post = True + wizard.validate_move() + self.assertTrue(self.test_move.state == 'posted') diff --git a/addons/account/wizard/account_validate_account_move.py b/addons/account/wizard/account_validate_account_move.py index 3be48a2b36e..30b49dc3cfd 100644 --- a/addons/account/wizard/account_validate_account_move.py +++ b/addons/account/wizard/account_validate_account_move.py @@ -19,5 +19,7 @@ class ValidateAccountMove(models.TransientModel): moves = self.env['account.move'].search(domain).filtered('line_ids') if not moves: raise UserError(_('There are no journal items in the draft state to post.')) + if self.force_post: + moves.auto_post = 'no' moves._post(not self.force_post) return {'type': 'ir.actions.act_window_close'}