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
addons/account/models/account_move.py
(self + writeoff_lines).reconcile()
        else:
            self.reconcile()
    
    # Re
    
    def _get_pair_to_reconcile(self):
        #fie
        field = self[0].account_id.currency_id and 'amount_residual_currency' or 'amount_residual'
        rounding = self[0].company_id.currency_id.rounding
        if self[0].currency_id and all([x.amount_currency and x.currency_id == self[0].currency_id for x in self]):
            #or 
            field = 'amount_residual_currency'
            rounding = self[0].currency_id.rounding
        if self._context.get('skip_full_reconcile_check') == 'amount_currency_excluded':
            field = 'amount_residual'
        elif self._context.get('skip_full_reconcile_check') == 'amount_currency_only':
            field = 'amount_residual_currency'
        #tar
        sorted_moves = sorted(self, key=lambda a: a.date_maturity or a.date)
        debit = credit = False
        for aml in sorted_moves:
            if credit and debit:
                break
            if float_compare(aml[field], 0, precision_rounding=rounding) == 1 and not debit:
                debit = aml
            elif float_compare(aml[field], 0, precision_rounding=rounding) == -1 and not credit:
                credit = aml
        return debit, credit
    def auto_reconcile_lines(self):