Dynamic reports
A dynamic report is a tree of lines with one column per value and period: a stock position by location and product,
a sales analysis by customer, a balance sheet. The reporting addon (depends on base and web) holds the report
records, resolves the options (dates, comparison, companies, unfolded lines, order), computes the lines and answers the
drill-down behind a line or a cell. Every read runs as the caller, in the call’s read transaction; nothing is cached
between calls.
A report names a provider. The generic provider reporting.definition reads the report’s lines, columns and
expressions from data, so most reports need no Rust. An addon whose report cannot be written as data (an aged balance,
a ledger) registers a native provider.
A native provider that applies the resolved search to its result can declare
ProviderSpec::server_search(). Its normalized filter metadata includes server_search: true.
PDF and XLSX exports use the provider’s results and still apply hide-zero. Providers without the
capability keep display-label filtering.
A report declared by data
Section titled “A report declared by data”<record id="report_stock" model="reporting.report"> <field name="name">Stock Position</field> <field name="date_mode">single</field> <field name="date_default">today</field> <field name="totals_below" eval="True"/></record><record id="report_stock_qty" model="reporting.report.column"> <field name="report_id" ref="report_stock"/> <field name="name">On Hand</field> <field name="label">qty</field> <field name="sortable" eval="True"/></record><record id="report_stock_line" model="reporting.report.line"> <field name="report_id" ref="report_stock"/> <field name="name">Stock</field> <field name="code">STOCK</field> <field name="groupby">location_id, product_id</field></record><record id="report_stock_line_qty" model="reporting.report.expression"> <field name="line_id" ref="report_stock_line"/> <field name="label">qty</field> <field name="model">stock.quant</field> <field name="field">quantity</field> <field name="domain">[["location_id.usage", "=", "internal"]]</field></record>Report (reporting.report): date_mode (range or single), date_default (today in single mode only,
this_month, last_month, this_quarter, last_quarter, this_year, last_year), comparison, multi_company,
unfold_all, hide_zero (never, optional, by_default), search_bar, totals_below (a total line after the
children of an unfolded line) and load_more_limit (children per page, from 10 to the setting
reporting.max_load_more_limit).
Columns (reporting.report.column): label (the expression label the cells show; lower-case, unique in the
report), kind (monetary, decimal, integer, percent), scale (0 to 12 decimals; monetary cells use the
company currency’s; every selected company must have the same currency for a monetary column), sortable, blank_if_zero, and rollup: none with a rollup_field shows the cell only on lines
grouped by that field (quantities of different units are never added up).
Lines (reporting.report.line): code (upper-case, unique in the report), parent_id, sequence, groupby
(direct many2one, char, selection or integer fields of the expression’s model, outermost first, at most
reporting.max_unfold_depth), foldable (foldable, always_unfolded, never_unfolded), hide_if_zero (the line
and its children are left out when all their cells are zero) and optional (left out, and named in hidden_lines,
for a caller who may not read its records). A line has child lines or a group-by, not both. Give each parent a sequence that puts it before its children. For equal sequences the lower record id comes first. Editing the sequence of either record rechecks the report.
Expressions (reporting.report.expression), one per label of a line:
aggregate: the sum offield(the record count when empty) overmodelanddomain(a JSON domain), read withread_groupas the caller. Withdate_field, the period applies:strict_rangekeeps the records of the period,from_beginningeverything up to its end (a position), andbefore_periodeverything strictly before its start (an opening balance).before_periodrequires a date field and a range with a start; single-date execution is refused. When the model has acompany_id, the selected companies apply too, with records of no company. Unfolding groups by the nextgroupbyfield with the parent keys in the domain. The aggregate expressions of a grouped line share their model, domain and date field, but may use different date scopes. Keys come from the union of all scopes and comparison periods; missing contributions are zero. Each cell and remaining-page sum retains its own scope, including drill-down. Sorting a grouped line with mixed date scopes is refused; leave its columns non-sortable.formula:+ - * /, parentheses and numbers overCODE.label(another line),label(the same line, evaluated per group key on grouped lines, which may use only their own labels) andsum_children(the same label of the direct child lines).zero_divisioniserror(the default) orempty.
Every save of a definition record checks the whole report; a formula cycle is refused naming its members, an unknown reference when the report is used (a data file may create it in a later record).
When changing a line’s report_id, move a complete parent/child subtree in one write. Both the source and
destination hierarchies are checked in the same transaction. A child left under a parent in another report
refuses the move. Concurrent edits to the source or destination can require a transaction retry.
A report declared by a native provider
Section titled “A report declared by a native provider”use erp_addon_reporting::definition::ReportDef;use erp_addon_reporting::line::{DrillTarget, ExpandPage, Expansion, LineId};use erp_addon_reporting::options::Options;use erp_addon_reporting::provider::{ProviderSpec, ReportCx, ReportProvider};use erp_sdk::serde_json::Value as Json;use erp_sdk::{BoxFuture, prelude::*};
pub struct AgedBalance;const SPEC: ProviderSpec = ProviderSpec::new("account.aged_balance", 1);
impl ReportProvider for AgedBalance { fn spec(&self) -> &ProviderSpec { &SPEC } fn init_options<'a>(&'a self, cx: &'a mut ReportCx<'_>, report: &'a ReportDef, options: &'a mut Options, strict: bool) -> BoxFuture<'a, Result<()>> { // check and default its own keys in options.provider; refuse an unknown one Box::pin(async move { Ok(()) }) } fn lines<'a>(&'a self, cx: &'a mut ReportCx<'_>, report: &'a ReportDef, options: &'a Options) -> BoxFuture<'a, Result<Expansion>> { todo!() } fn expand<'a>(&'a self, cx: &'a mut ReportCx<'_>, report: &'a ReportDef, options: &'a Options, line: &'a LineId, page: ExpandPage) -> BoxFuture<'a, Result<Expansion>> { todo!() } fn drill<'a>(&'a self, cx: &'a mut ReportCx<'_>, report: &'a ReportDef, options: &'a Options, line: &'a LineId, target: &'a DrillTarget) -> BoxFuture<'a, Result<Json>> { todo!() }}
erp_addon_reporting::provider_declarations!(AgedBalance);The report record names it with <field name="provider">account.aged_balance</field>. The registration counts only in
a database where the declaring addon is installed; an unknown name is refused by name, and two installed addons with
one provider name fail every lookup naming both.
cx.env()andcx.tx()are the caller’s environment and transaction. There is no elevated environment: a provider reads as the caller.linesreturns the top-level lines; the runtime unfolds the lines the options ask for by callingexpandwith the first page, adds the total lines, and refuses an answer overreporting.max_screen_lines(never a cut tree).expandchecks the line id against its report before any query (the segments of a line id come from the browser), returns one page ofpage.limitchildren frompage.offsetand, when more exist, a load-more line last.drillreturns an action result that the web client’s action check admits (a window on a record, or a list with a domain).
All four are methods of reporting.report with read effect:
| Method | Arguments | Answer |
|---|---|---|
erp_report_options | report, previous (options, false or null) | name, options (previous values kept where they still apply), filters |
erp_report_lines | options | options, lines, hidden_lines, computed_at |
erp_report_expand | options, line_id, offset | lines (one page, then the unfolded lines below) |
erp_report_drill | options, line_id, target ({"item": "open"} or {"cell": n}) | an action |
For a first opening, send an empty previous object or the supported false or null shorthand. Pass the returned options object to subsequent calls with its null dates and boolean flags intact. A literal boolean in a date field is rejected.
erp_report_lines and the others refuse an unknown option key or a value the report does not offer; options are
report, companies (among the caller’s allowed companies), date (mode, preset, from, to), comparison
(mode: none, previous_period, same_last_year, custom; periods up to reporting.max_comparison_periods;
order), unfold_all, unfolded (line ids), hide_zero, search (at most 256 characters), provider and
order (column, direction). Each line has id, parent, name, level, kind (section, group, detail,
total, more), unfoldable, unfolded, cells (each with kind, value as a decimal string at its scale,
currency and zero), caret, and for a load-more line remaining and next_offset.
The optional cell boolean drillable describes whether the provider offers a record-list action for
that amount. The definition provider declares it for each cell. Formulas, generated totals and page
markers, and blank amounts declare false. An absent value preserves the legacy behavior for other
providers. Access is checked independently when the action is requested. See ADR 0264.
The screen
Section titled “The screen”The report screen is the client action reporting.report (ADR 0234): addons/reporting/static/src/ registers it
with registerClientAction, and the action’s params name the report ({"report": <id>}; the validator refuses
any other key and a report the caller cannot read). A menu for your own report is one record and one menu item:
<record id="my_report_action" model="ir.actions.client"> <field name="name">My report</field> <field name="tag">reporting.report</field> <field name="params" eval="{'report': ref('my_report')}"/></record><menuitem id="my_report_menu" name="My report" parent="my_app.reports_menu" action="my_report_action"/>The screen asks the four calls above and nothing else. It sends the options it received back whole, so a provider’s
own provider options and any new shared option pass through without client code. What it shows follows the
answers: the filter bar offers only what filters says the report supports, the column heads come from
options.columns and options.column_groups, a cell’s kind, value, scale and zero decide how it is
written, and caret lists the menu items of a line (open is the only one the definition provider makes). A
provider that adds a caret item gets a menu entry with that name and the screen calls erp_report_drill with
{"item": name}. PDF, XLSX and Print post {report, options, format} to POST /erp/reporting/export, and the
server recomputes the file; the screen never posts rows.
The behavior of the screen, case by case, is in docs/design/REPORTING.UI-matrix.md. The browser pieces an addon
screen of this kind can use are exported from @erpforall/client: saveFile (offer a blob as a download) and icon;
RpcClient.postFile takes the download route and the expected content type.
Export to PDF and XLSX
Section titled “Export to PDF and XLSX”The screen’s PDF and XLSX buttons call one route, POST /erp/reporting/export. No JSON-2 method returns bytes, so
this is a download route like the pivot’s (/erp/pivot/export): a browser session (no bearer credentials), a same-origin
fetch, Content-Type: application/json, and a body bounded by reporting.export_max_request_bytes (over it: 413
naming the setting).
Request body, exactly these three keys (any other key, such as rows or lines, is refused with 422; the browser
never posts rows):
{"report": 12, "options": {"date": {"preset": "this_month"}, "unfold_all": true, "hide_zero": true, "search": "desk"}, "format": "pdf"}report: thereporting.reportid;options.reportmay be left out (a different id there is refused).options: the screen’s options, aserp_report_linestakes them (the same strict checks).format:"pdf"or"xlsx".
The server recomputes the lines as the caller. Each unfolded parent starts with one page of
load_more_limit children. The optional loaded_pages object maps an unfolded parent’s canonical
line ID to a positive integer counting additional pages. Normalization returns {} by default.
The server follows each continuation returned by the provider, including under nested parents.
A provider ends a nonfinal page with the parent’s More marker and an advancing next_offset.
A final page has no marker. If fewer pages remain after the data changes, replay stops there.
The sum of all additional page counts times the page size must fit reporting.max_screen_lines. When a report returns loaded_pages, opening a group or requesting another page submits all open groups to erp_report_lines. The screen updates its rows and saved options together after the server accepts them.
Any remaining More marker becomes a row reading “N more”. Hide zero and the search text are applied as the screen applies them: a line stays when it or a line below it
is non-zero (text counts as zero); a search keeps the lines whose name contains the text (any case), their ancestors
and their descendants; a load-more line follows its parent. The export counts the rows it would write: over
reporting.export_max_rows it is a Validation error naming that setting, never a truncated file (larger reports will get
durable export jobs in a later release). The unfold step is bounded by the same setting.
Answer, 200:
| Header | Value |
|---|---|
Content-Type | application/pdf, or application/vnd.openxmlformats-officedocument.spreadsheetml.sheet |
Content-Disposition | attachment with the report name as file name (.pdf or .xlsx) |
Cache-Control | private, no-store |
X-Content-Type-Options | nosniff |
Refusals: 401 no session or a bearer credential; 403 a foreign origin or a cross-site fetch, and the ordinary
Access refusal when the caller may not read the report or a model behind a line; 405 for another method; 413 a
body over the bound; 415 another content type; 422 a bad request or options, or a report over the row bound.
503 names a server composed without the export.
- PDF. A4, with a header built from the company of the options (its first selected company): logo, name and
address, then the report title, the period of each column group and the print time (UTC), then one table whose
header repeats on every page. Six or more data columns across all column groups print landscape; five or fewer
portrait. Numbers show at their cell’s scale, without a thousands separator (the user’s number format is not
applied yet). The node’s report runtime lays the document out (
report_job::layout), so a server without a render worker answersUser(“Printing is not available”). - XLSX. One sheet: a period row (merged over each column group’s columns), a column-name row, then one row per
line with the name indented by its level, bold for sections and totals, numbers stored as numbers with their
decimals. A second sheet, “Options”, lists the options used (nested keys joined with a dot) and the optional lines
the caller may not read. Text is always a string cell: a name starting with
=,+,-,@, a tab or a carriage return carries the quote-prefix flag and no cell of the file is a formula.
A native provider needs nothing: the export reads the same lines it returns to the screen. To build a file in Rust
use reporting::export::prepare (it parses the same body) and Prepared::xlsx or Prepared::document.
Settings
Section titled “Settings”Declared in the block “Dynamic reports” of the Settings page, each with a default, a floor and a hard bound:
| Setting | Default | Range |
|---|---|---|
reporting.max_load_more_limit | 2000 | 10 to 2000 |
reporting.max_unfold_depth | 8 | 2 to 16 |
reporting.max_screen_lines | 10000 | 500 to 50000 |
reporting.max_comparison_periods | 12 | 1 to 16 |
reporting.export_max_rows | 50000 | 100 to 500000 |
reporting.export_max_request_bytes | 1048576 | 16384 to 16777216 |
Access
Section titled “Access”Internal users read the report records; administrators create and change them. A report’s numbers are read with the
caller’s rights: a record rule narrows every line, group and drill-down list, and a line over a model or field the
caller may not read is an Access refusal, never a zero, unless the line is optional.
Accounting example
Section titled “Accounting example”The data-only account_reporting addon depends on account and reporting.
Its Posted Journal Activity definition groups account.move.line by journal and account with one company per
result. All three expressions share the posted, accountable, statutory-journal domain and the accounting date.
Debit and credit sum the booked monetary fields, including their stored storno sign. The count expression
has no field and counts matching items. The menu uses the accounting read-only group and the shared report
provider checks the caller’s access to the journal items on each read and drill-down.
The Account Movements definition in the same addon groups by account_id,move_id. Its three aggregate
expressions sum debit, credit and the signed booked balance over the same strict period,
company and posted statutory domain. This keeps each net-change cell drillable to its source items.
Version 1.1.0 adds this report. Upgrade an installed account_reporting to load its definition and menu.
Current balances and protected native measures
Section titled “Current balances and protected native measures”For a report over current balances, set reporting.report.current_only with date_mode = single, date_default = today and comparison = false. Opening saved options resets the cutoff to today. A lines, expand, drill or export request using a different cutoff fails validation. Clients read filters.current_only from the options response to display the fixed date.
On a definition column, groups controls which users receive the column. Use rollup = none with rollup_field = product_id for measures that can only be meaningfully summed within a product. Register a native measure with expression_function_declarations!(QUANT_VALUE, "stock_account.quant_value", quant_value, quant_domain). Its value callback receives the caller’s domain, grouping and normalized options. Its drill-domain callback supplies the same extra eligibility restrictions as the calculation. Both callbacks must enforce their own privileged-read boundary. The Inventory example lives in addons/stock_account/src/report_value.rs.
Ledger Trial Balance is installed by account_reporting 1.2 and uses reporting 1.1’s date scopes.
Its definition is account_reporting.report_ledger_trial_balance: opening balance/before_period,
period debit and credit/strict_range, closing balance/from_beginning, grouped by account_id.
The source predicate is posted items with an account in the statutory journal set (no journal group).
It carries raw ledger balances of every account, including P&L; it never generates fiscal allocations.
Definitions remain editable through the existing reporting models, subject to their access controls.
Native General Ledger (account_reporting 1.5)
Section titled “Native General Ledger (account_reporting 1.5)”account_reporting.general_ledger implements one-company chronological transaction detail. Compose
erp_addon_account_reporting::ADDON and independently require
erp_addon_account_reporting::schema::MANIFEST; the CLI’s central native addon registry does both.
The manifest is installed through the normal module system and declares the additive source epoch
function/triggers. No business logic is added to the core reporting definition engine.
The provider uses caller-scoped _read_group for opening and prefix sums, then read_rows for a bounded
page ordered by date, id. Every amount drill repeats its scope; native transaction form actions validate
source membership first. Cell::date(Date) supplies the existing ISO-date wire cell. reporting 1.2 admits date/text
column kinds for native providers; the numeric definition provider refuses them. Operators edit labels,
column sequence and page size on report records, subject to the shared report bounds. Protocol labels
and structural line codes are not operator settings; invalid configurations fail explicitly.
Options include a SHA-256 provider.epoch freshness token bound to source/access generations and
principal/company/date/context scope. It authorizes nothing. Calls compare it before and after data reads;
both comparisons see the request snapshot. A later request rejects an outdated token. Explicit Refresh and scope changes obtain fresh options. The append-only named generation uses commit visibility and rolls
back with the posting transaction, avoiding a shared-row UPDATE lock. Invalidation is deliberately global
and may follow drafts or another company’s writes. See the PerRequest contract in ADR 0243.
account_reporting 1.9.0 adds optional fiscal opening. In erp_report_options, set
previous.provider.fiscal_opening to true and choose an inclusive range inside one company fiscal year.
Use the normalized options, including the server-derived provider.fiscal_year_start and the refreshed
provider.epoch, for lines, expand, drill and export. An absent or false flag selects raw opening.
The opt-in captions use the protected GL_FISCAL, OPENING_FISCAL, CLOSING_FISCAL and UNALLOCATED
line records. Keep the raw line codes and common column labels. See ADR 0263 for the fiscal opening contract.
Native expression functions receive the remaining source-domain complement for a More cell, with all cumulatively loaded keys excluded, including a null key when already loaded. This preserves the function’s own expression, period and parent scope. Compute and round that remaining total directly: a separately rounded whole minus a separately rounded prefix can disagree with the real remainder. Ordinary declarative aggregates, formulas, source-record counts and remaining-group counts keep their existing semantics.
Guarded Balance Sheet (account_reporting 1.6)
Section titled “Guarded Balance Sheet (account_reporting 1.6)”account_reporting.balance_sheet delegates amount calculation, grouping and drills to the existing
DefinitionProvider. Its caller-scoped preflight uses ordinary ORM any predicates to detect visible
ordinary/off-balance items in the same posted statutory entry, within the company and as-of period on
both sides. It never uses the bypassing relation operator or a global source SQL scan. It checks before
and after each lines/expansion/drill execution. The report remains PerRequest; no immutable release or
fiscal allocation is implied.
A delegating native provider can reuse definition::check_page_parent for every saved loaded-page
parent to retain the definition engine’s path, remaining group and unfolded-ancestor checks. Do this in
init_options; changing a provider name must not drop parent validation on paged exports. Balance Sheet
retains numeric definition columns. The version1.6 migration replaces only the builtin default provider,
leaving editable labels, amounts and identities intact. See ADR0248 in the source repository.
Historical Partner Ledger source filter
Section titled “Historical Partner Ledger source filter”Upgrading Accounting to 1.7 and Accounting Reports to 1.8 binds the built-in Partner Ledger to account_reporting.partner_ledger. The options response names the active provider in filters.provider. Only the accounting Partner Ledger uses the built-in reconciliation control and requires a boolean options.provider.unreconciled. Other providers retain their own option names and types. Reuse the full normalized options object when refreshing, unfolding, drilling or exporting. When enabled, the provider narrows every aggregate domain to items open on the main end date, under the reader’s journal-item rules. It retains booked columns. Comparisons, foreign-currency items, incomplete history and ambiguous historical replacements return a validation error. The global setting reporting.max_filter_source_rows limits candidates per request before any totals are served. Existing report bindings customized to a different provider are preserved.
The report screen keeps resolved filters available when loading the first set of rows fails. When the provider declares filters.server_search, the screen sends each search to the provider. Product Stock Position uses this option so internal references can match independently of the displayed row name.