[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 <smetl@users.noreply.github.com>
Signed-off-by: Nicolas Viseur <vin-odoo@users.noreply.github.com>
This commit is contained in:
Nicolas (vin)
2020-09-09 12:32:49 +00:00
parent 87e5255d9e
commit 8a99e5f587
@@ -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'}