From 8a99e5f587d129c23b175678543c5ef2b3339728 Mon Sep 17 00:00:00 2001 From: "Nicolas (vin)" Date: Tue, 8 Sep 2020 08:03:17 +0000 Subject: [PATCH] [FIX] account: make post all entries works again in move list Recent changes to make post all entries works from the dashboard broke it when used from the move list. This commit will fix that and make sure it works in both situation closes odoo/odoo#57249 closes odoo/odoo#57352 X-original-commit: fcadd448741d354c44a17a89819c95c7b124a3b7 Signed-off-by: Laurent Smet Signed-off-by: Nicolas Viseur --- .../wizard/account_validate_account_move.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) 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'}