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
for line in self:
            line.balance = line.debit - line.credit
    @api.model
    def _get_currency(self):
        currency = False
        context = self._context or {}
        if context.get('default_journal_id', False):
            currency = self.env['account.journal'].browse(context['default_journal_id']).currency_id
        return currency
    @api.model
    def _get_journal(self):
        """ Return journal based on the journal type """
        context = dict(self._context or {})
        journal_id = context.get('journal_id', False)
        if journal_id:
            return journal_id
        journal_type = context.get('journal_type', False)
        if journal_type:
            recs = self.env['account.journal'].search([('type', '=', journal_type)])
            if not recs:
                action = self.env.ref('account.action_account_journal_form')
                msg = _("""Cannot find any account journal of "%s" type for this company, You should create one.\n Please go to Journal Configuration""") % journal_type.replace('_', ' ').title()
                raise RedirectWarning(msg, action.id, _('Go to the configuration panel'))
            journal_id = recs[0].id
        return journal_id
    @api.depends('debit', 'credit', 'move_id.matched_percentage', 'move_id.journal_id')
    def _compute_cash_basis(self):