On the Spanish VAT Book report we need to determine if an invoice is a credit note or not.
For now, we compute the type of sequence used for each invoice to be able to determine if it’s a credit note or not.
We started to find performance regression when running this report, when the number of invoice lines is large (we have 300.000 lines and 2500 invoices on a single Fiscalyear).
Some sample timmings some timmings:
- When the credit_note computation is reading all the lines the report it takes more than 5 minutes.
- When the credit does not read all the lines (see code above), the report take just 5 seconds.
Here is the code I used to avoid reading the lines.
@property def es_vat_book_type(self): # Avoid reading the lines if self.total_amount < 0: return 'R0' if not self.party_tax_identifier: return 'F2' return 'F1'
I’m not sure why the credit not computation needs to read all the lines.
So I’m wondering how we can improve such reports performance.