Skip to Content
Menu
This question has been flagged
1 Reply
1246 Views

Currently we have a problem generating the invoice of many sales orders at once, in operation we have a customer who requires an invoice for the set of thousands of sales orders (per month they can be between 2,000-8,000) and always appears a time out error when generating it. Is there any limitation in the number of lines on the invoice or some way to solve this problem to carry out the operation? Sales orders can have between 1 and 5 lines, so we’re talking about around 40,000 lines in a single invoice. Any ideas?

Avatar
Discard
Best Answer

Hello,

This issue is quite common when attempting to generate a single invoice with a very large number of lines (e.g. 40,000+). Odoo is not optimized out-of-the-box to handle invoices of such scale due to performance limitations at both the ORM and database level. Here's some insight and recommendations:

⚠️ Why You're Seeing a Timeout

  • Odoo tries to compute taxes, totals, and validations for each line item.
  • Account move line creation, reconciliation, and posting all happen in one transaction.
  • The HTTP timeout or even PostgreSQL query performance can become a bottleneck.
  • The browser and backend server memory/CPU usage spikes significantly for such a massive invoice.

🛠 Possible Solutions

✅ 1. Batch Processing

Split the sales orders into multiple invoices, grouped logically (e.g. weekly or by SO tags).

  • This reduces load per invoice and helps avoid timeouts.
  • You can then group the invoices under a single customer statement or use a custom PDF merge (if needed for reporting).

✅ 2. Asynchronous Processing (Queue Job)

Use the queue_job module (OCA) or similar to run invoice generation as a background job, which:

  • Runs outside the HTTP request-response cycle.
  • Avoids timeouts and uses worker processes.
  • Allows monitoring of job completion.

✅ 3. Optimize Backend Performance

  • Increase server limits: request timeout, workers, and memory limits.
  • Use PostgreSQL indexing and query tuning.
  • If you're using Python loop + ORM, consider using cr.execute() for bulk inserts.

✅ 4. Invoice Consolidation Logic

Instead of one invoice with all lines, build a custom summary logic:

  • Group similar lines (e.g. same product/tax) together.
  • One line can represent multiple sales via quantity/description like “Service X (covered from SO001 to SO999)”.

✅ 5. Custom PDF Reporting

Generate one invoice per batch, but merge them only in the PDF output as a single report for the client — if that's the main goal.

❌ Things to Avoid

  • Don't try to increase timeout arbitrarily — it can cause server instability.
  • Avoid running this operation on production without testing on a staging environment first.

Avatar
Discard
Related Posts Replies Views Activity
2
Dec 23
2549
6
Mar 22
8911
2
Jun 25
8940
1
Jan 25
1400
3
May 24
3908