Hello everyone, 

why this line is inside the loop?

https://github.com/odoo/odoo/blob/132c7e75e57321c77aac9250a2587c74c5da7857/addons/account/models/account_move.py#L1364

We were removing 100k~ account.move.line records for testing purposes. It took ages. So we do some little investigation and saw this, we took out from the loop the process duration became minutes from hours.

Regards from Projet
for move in self:
            if not move.journal_id.update_posted:
                raise UserError(_('You cannot modify a posted entry of this journal.\nFirst you should set the journal to allow cancelling entries.'))
        if self.ids:
            self.check_access_rights('write')
            self.check_access_rule('write')
            self._check_lock_date()
            self._cr.execute('UPDATE account_move '\
                       'SET state=%s '\
                       'WHERE id IN %s', ('draft', tuple(self.ids),))
            self.invalidate_cache()
        return True
    @api.multi
    def unlink(self):