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
""" After running the manual reconciliation wizard and making full reconciliation, we need to run this method to create
            potentially an exchange rate entry that will balance the remaining amount_residual_currency (possibly several aml).
            This ensure that all aml in the full reconciliation are reconciled (amount_residual = amount_residual_currency = 0).
        """
        total_amount_currency = 0
        currency = False
        aml_to_balance_currency = self.env['account.move.line']
        aml_id = False
        partial_rec_id = False
        maxdate = None
        for aml in self:
            if aml.amount_residual_currency:
                aml_to_balance_currency |= aml
            maxdate = max(aml.date, maxdate)
            if not currency and aml.currency_id:
                currency = aml.currency_id
            if aml.currency_id and aml.currency_id == currency:
                total_amount_currency += aml.amount_currency
        if currency and aml_to_balance_currency:
            aml = aml_to_balance_currency[0]
            #eve
            partial_rec = aml.credit and aml.matched_debit_ids[0] or aml.matched_credit_ids[0]
            aml_id, partial_rec_id = partial_rec.with_context(skip_full_reconcile_check=True).create_exchange_rate_entry(aml_to_balance_currency, 0.0, total_amount_currency, currency, maxdate)
        return aml_id, partial_rec_id
    @api.multi
    def remove_move_reconcile(self):