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
if not self.ids:
            return True
        prec = self.env['decimal.precision'].precision_get('Account')
        self._cr.execute("""\
            SELECT      move_id
            FROM        account_move_line
            WHERE       move_id in %s
            GROUP BY    move_id
            HAVING      abs(sum(debit) - sum(credit)) > %s
            """, (tuple(self.ids), 10 ** (-max(5, prec))))
        if len(self._cr.fetchall()) != 0:
            raise UserError(_("Cannot create unbalanced journal entry."))
        return True
    
    def _reconcile_reversed_pair(self, move, reversed_move):
        amls_to_reconcile = move.line_ids + reversed_move.line_ids
        accounts_reconcilable = amls_to_reconcile.mapped('account_id').filtered(lambda a: a.reconcile)
        for account in accounts_reconcilable:
            amls_for_account = amls_to_reconcile.filtered(lambda l: l.account_id.id == account.id)
            amls_for_account.reconcile()
            amls_to_reconcile = amls_to_reconcile - amls_for_account
    @api.multi
    def reverse_moves(self, date=None, journal_id=None):