We might be missing an index on the move and account column of account.invoice
In the get_lines_to_pay
getter there is a join between the invoices and the account move lines using the invoice's move and the line's move and the invoice's account and the line's move.
We might want to add an index on those.