'Compute the sum of the residual of invoices, expressed in the payment currency'

def _compute_total_invoices_amount(self):

    payment_currency = (self.currency_id or self.journal_id.currency_id or self.journal_id.company_id.currency_id or self.env.user.company_id.currency_id)
    invoices = self._get_invoices()
    if all(((inv.currency_id == payment_currency) for inv in invoices)):
        total = sum(invoices.mapped('residual_signed'))
    else:
        total = 0
        for inv in invoices:
            if (inv.company_currency_id != payment_currency):
                total += inv.company_currency_id.with_context(date=self.payment_date).compute(inv.residual_company_signed, payment_currency)
            else:
                total += inv.residual_company_signed
    return abs(total)
