Skip to content

Commit

Permalink
[DOC] document custom fields in accounting expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
sbidoul committed Nov 11, 2024
1 parent 9b56994 commit 2ce56f2
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 20 deletions.
34 changes: 20 additions & 14 deletions docs/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -169,15 +169,19 @@ Building your KPI
Expressions can be any valid python expressions.

The following special elements are recognized in the expressions to compute accounting
data: {bal|crd|deb}{pieu}[account selector][journal items domain].

* bal, crd, deb: balance, debit, credit.
* p, i, e: respectively variation over the period, initial balance, ending balance
* The account selector is a like expression on the account code (eg 70%, etc).
data: ``{bal|crd|deb|pbal|nbal|fld}{pieu}(.fieldname)?[account selector][journal items domain]``.

* ``bal``, ``crd``, ``deb``: balance, debit, credit.
* ``pbal``, ``nbal``: positive and negative balances only
* ``fld``: custom numerical field
* ``p``, ``i``, ``e``: respectively variation over the period, initial balance, ending balance
* .fieldname: when ``fld`` is used, the field name to use (eg ``fldp.quantity``).
* The account selector is a like expression on the account code (eg ``[70%]``, etc),
or a domain over accounts (eg ``[("tag_ids.name", "=", "mytag")]``).
* The journal items domain is an Odoo domain filter on journal items.
* balu[]: (u for unallocated) is a special expression that shows the unallocated
* ``balu[]``: (u for unallocated) is a special expression that shows the unallocated
profit/loss of previous fiscal years.
* Expression can also involve other KPI and query results by name (eg kpi1 + kpi2).
* Expression can also involve other KPI and query results by name (eg ``kpi1 + kpi2``).

Additionally following variables are available in the evaluation context:

Expand All @@ -188,16 +192,18 @@ Additionally following variables are available in the evaluation context:

Examples
********
* bal[70]: variation of the balance of account 70 over the period (it is the same as balp[70].
* bali[70,60]: initial balance of accounts 70 and 60.
* bale[1%]: balance of accounts starting with 1 at end of period.
* crdp[40%]: sum of all credits on accounts starting with 40 during the period.
* debp[55%][('journal_id.code', '=', 'BNK1')]: sum of all debits on accounts 55 and
* ``bal[70]``: variation of the balance of account 70 over the period (it is the same as balp[70].
* ``bali[70,60]``: initial balance of accounts 70 and 60.
* ``bale[1%]``: balance of accounts starting with 1 at end of period.
* ``crdp[40%]``: sum of all credits on accounts starting with 40 during the period.
* ``debp[55%][('journal_id.code', '=', 'BNK1')]``: sum of all debits on accounts 55 and
journal BNK1 during the period.
* balp[('user_type_id', '=', ref('account.data_account_type_receivable').id)][]:
* ``balp[('user_type_id', '=', ref('account.data_account_type_receivable').id)][]``:
variation of the balance of all receivable accounts over the period.
* balp[][('tax_line_id.tag_ids', '=', ref('l10n_be.tax_tag_56').id)]: balance of move
* ``balp[][('tax_line_id.tag_ids', '=', ref('l10n_be.tax_tag_56').id)]``: balance of move
lines related to tax grid 56.
* ``fldp.quantity[60%]``: sum of the quantity field of all move lines on accounts starting
with 60.

Expansion of Account Detail
---------------------------
Expand Down
7 changes: 5 additions & 2 deletions mis_builder/models/aep.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,14 @@ def _is_domain(s):
class AccountingExpressionProcessor:
"""Processor for accounting expressions.
Expressions of the form <field><mode>[accounts][optional move line domain]
Expressions of the form
<field><mode>(.fieldname)?[accounts][optional move line domain]
are supported, where:
* field is bal, crd, deb, pbal (positive balances only),
nbal (negative balance only)
nbal (negative balance only), fld (custom field)
* mode is i (initial balance), e (ending balance),
p (moves over period)
* .fieldname is used only with fldp and specifies the field name to sum
* there is also a special u mode (unallocated P&L) which computes
the sum from the beginning until the beginning of the fiscal year
of the period; it is only meaningful for P&L accounts
Expand All @@ -45,6 +47,7 @@ class AccountingExpressionProcessor:
over the period (it is the same as balp[70]);
* bali[70,60]: balance of accounts 70 and 60 at the start of period;
* bale[1%]: balance of accounts starting with 1 at end of period.
* fldp.quantity[60%]: sum of the quantity field of moves on accounts 60
How to use:
* repeatedly invoke parse_expr() for each expression containing
Expand Down
13 changes: 9 additions & 4 deletions mis_builder/views/mis_report.xml
Original file line number Diff line number Diff line change
Expand Up @@ -170,19 +170,24 @@
<p
> The following special elements are recognized in the expressions
to compute accounting data: <code
>{bal|crd|deb|pbal|nbal}{pieu}[account
>{bal|crd|deb|pbal|nbal|fld}{pieu}(.fieldname)[account
selector][journal items domain]</code>. </p>
<ul>
<li>
<code>bal</code>, <code>crd</code>, <code
>deb</code>, <code>
pbal</code>, <code
>nbal</code> : balance, debit, credit,
positive balance, negative balance. </li>
pbal</code>, <code>nbal</code>, <code
>fld</code> : balance, debit, credit,
positive balance, negative balance,
other numerical field. </li>
<li>
<code>p</code>, <code>i</code>, <code
>e</code> : respectively variation over the period,
initial balance, ending balance </li>
<li>when <code
>fld</code> is used : a field name specifier
must be provided (e.g. <code
>fldp.quantity</code></li>
<li> The <b
>account selector</b> is a like expression on the
account code (eg <code
Expand Down

0 comments on commit 2ce56f2

Please sign in to comment.