diff --git a/addons/account/wizard/account_validate_account_move.py b/addons/account/wizard/account_validate_account_move.py index 2c676d520eb..3be48a2b36e 100644 --- a/addons/account/wizard/account_validate_account_move.py +++ b/addons/account/wizard/account_validate_account_move.py @@ -9,10 +9,15 @@ class ValidateAccountMove(models.TransientModel): force_post = fields.Boolean(string="Force", help="Entries in the future are set to be auto-posted by default. Check this checkbox to post them now.") def validate_move(self): - context = dict(self._context or {}) - moves = self.env['account.move'].browse(context.get('active_ids')) - move_to_post = moves.filtered(lambda m: m.state == 'draft') - if not move_to_post: + if self._context.get('active_model') == 'account.move': + domain = [('id', 'in', self._context.get('active_ids', [])), ('state', '=', 'draft')] + elif self._context.get('active_model') == 'account.journal': + domain = [('journal_id', '=', self._context.get('active_id')), ('state', '=', 'draft')] + else: + raise UserError(_("Missing 'active_model' in context.")) + + 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.')) - move_to_post._post(not self.force_post) + moves._post(not self.force_post) return {'type': 'ir.actions.act_window_close'}