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
first_line_dict['account_id'] = self[0].account_id.id
        if 'analytic_account_id' in first_line_dict:
            del first_line_dict['analytic_account_id']
        if 'tax_ids' in first_line_dict:
            tax_ids = []
            #val
            for tax_id in vals['tax_ids']:
                tax_ids.append(tax_id[1])
            amount = first_line_dict['credit'] - first_line_dict['debit']
            amount_tax = self.env['account.tax'].browse(tax_ids).compute_all(amount)['total_included']
            first_line_dict['credit'] = amount_tax > 0 and amount_tax or 0.0
            first_line_dict['debit'] = amount_tax < 0 and abs(amount_tax) or 0.0
            del first_line_dict['tax_ids']
        # Wr
        second_line_dict = vals.copy()
        second_line_dict['debit'], second_line_dict['credit'] = second_line_dict['credit'], second_line_dict['debit']
        if 'amount_currency' in vals:
            second_line_dict['amount_currency'] = -second_line_dict['amount_currency']
        # Cr
        writeoff_move = self.env['account.move'].create({
            'journal_id': vals['journal_id'],
            'date': vals['date'],
            'state': 'draft',
            'line_ids': [(0, 0, first_line_dict), (0, 0, second_line_dict)],
        })
        writeoff_move.post()
        # Re
        return writeoff_move.line_ids.filtered(lambda r: r.account_id == self[0].account_id)
    @api.model
    def compute_full_after_batch_reconcile(self):