[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) <bib@odoo.com>
Signed-off-by: Guillaume Vanleynseele (guva) <guva@odoo.com>
This commit is contained in:
guva-odoo
2024-02-02 09:18:47 +00:00
parent 5f41ddc49e
commit 5440bede82
2 changed files with 11 additions and 0 deletions
@@ -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')
@@ -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'}