TRP Account Reports Cached
Most "slow accounting reports" in Odoo get slow because they keep asking Postgres questions like: "Scan a huge ``account_move_line`` table, apply a bunch of filters/domains, then **GROUP BY* account/date/company/journal/state and compute sums/counts."*" Doing that over and over (and for multiple report lines) is expensive. This module implements caching in account reports by making access faster for workload that is dominated by scanning + grouping huge account_move_line data. A PostgreSQL materialized view stores precomputed aggregates, so the report query can read a much smaller, already-grouped dataset instead of repeatedly aggregating millions of journal items. That's exactly the classic use-case where MVs improve read performance.
Usage
Once the module is installed:
1.) Turn ON the global "Cached Reports" switch:
- Go to Accounting app → Configuration → Settings (or Settings → Accounting depending on your DB/menu layout)
- Search for "Cached" / "Enable Cached Reports"
- Enable it and Save.This should set your ir.config_parameter key trp_account_reports.cache_reports_enabled=True (your code uses that gate).
2.) Open a report and enable "use cache" (per-report option):
- Go to Accounting → Reporting → Balance Sheet and/or Accounting → Reporting → Trial Balance
- Open the report's Options/Filters panel
- Enable your checkbox (the one that maps to options["trp_cache_report"])
- Run the report / refresh the report
- What to check:
- Results should look normal (same totals as non-cached mode).
3.) Prove the delta trigger works (UI-level):
- Keep the report open in one tab (cached option ON).
- In another tab: create a Journal Entry inside the same date range:
- Accounting → Accounting → Journal Entries → New
- Add 2 lines (e.g., Expense debit 100, Revenue credit 100)
- Post it
- Return to the report and refresh/recompute.
Expected:
- The report should reflect the change immediately (that's your "delta table + union view" doing its job).
4.) Prove the snapshot refresh works (run the cron manually)
- With developer mode still enabled, go to: Settings → Technical → Automation → Scheduled Actions
- Search for your cron (likely something like "Save report snapshot" / the record calling account.report.cron_save_report_snapshot)
- Open it and click Run Manually (button name can vary slightly, but it's there in the scheduled action form).
- Reload the report again.
Expected: - The report is still correct.
NB: In the tools folder inside the module, you will see a python script generate_aml_load.py which you can use on a demo database to generate account moves quickly and simulate the report cache functionality. To add the account move lines automatically, execute the command in your terminal as shown on snippet below:
python3 generate_aml_load.py \ --config /{path_to_your_odoo_config_file}/odoo.conf --db {demo_db_name} \ --aml-target {no_of_acc_moves} # e.g 1500000 --lines-per-move 40 \ --batch-moves 200 \ --accounts-sample 1000 \ --journals-sample 2 \ --date {Date e.g 2025-12-31} \ --date-span-days 365 \ --ref-prefix {your_prefix_name}
Please log in to comment on this module