8000 [IMP] accounting: reports groupby non-stored fields · odoo/documentation@e4502a1 · GitHub
[go: up one dir, main page]

Skip to content

Commit e4502a1

Browse files
Megaaaaaadade-odoo
authored andcommitted
[IMP] accounting: reports groupby non-stored fields
In 18.0, [this commit](odoo/enterprise@3fcf1ae) added the ability to group by fields that are non stored. This commit adds documentation about how to use the feature. task-4698321
1 parent ac6af9f commit e4502a1

File tree

5 files changed

+125
-79
lines changed

5 files changed

+125
-79
lines changed

content/applications/finance/accounting/reporting/customize.rst

Lines changed: 125 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,21 @@ Custom reports
33
==============
44

55
Odoo comes with a powerful and easy-to-use reporting framework. The engine allows you to create new
6-
reports, such as **tax reports**, or **balance sheets** and **income statements** with **specific
7-
groupings** and **layouts**.
6+
reports, such as tax reports, balance sheets, and income statements with specific groupings and
7+
layouts.
88

99
.. important::
10-
Activate the :ref:`developer mode <developer-mode>` to access the accounting report creation
11-
interface.
10+
Activate the :ref:`developer mode <developer-mode>` to access the accounting report
11+
configuration.
1212

13-
To create a new report, go to :menuselection:`Accounting --> Configuration --> Management:
14-
Accounting Reports`. From here, you can either create a :ref:`root report <customize-reports/root>`
15-
or a :ref:`variant <customize-reports/variants>`.
13+
To create a new report, go to :menuselection:`Accounting --> Configuration --> Accounting Reports`.
14+
From here, create either a :ref:`root report <customize-reports/root>` or a :ref:`variant
15+
<customize-reports/variants>`.
1616

17-
.. image:: customize/engine-accounting-reports.png
18-
:align: center
19-
:alt: Accounting reports engine.
17+
.. tip::
18+
- Consider saving modified reports as report variants to keep their root reports intact.
19+
- To access an existing report's management interface from the report itself, click on the
20+
:icon:`fa-cogs` :guilabel:`(gears)` icon.
2021

2122
.. _customize-reports/root:
2223

@@ -31,18 +32,14 @@ report itself.
3132
A tax report for Belgium and the US would both use the same generic version as a base and adapt
3233
it for their domestic regulations.
3334

34-
When creating a new root report, you need to create a **menu item** for it. To do so, open the
35-
report and then, on that same report, click on :menuselection:`Action --> Create Menu Item`. Refresh
36-
the page; the report is now available under :menuselection:`Accounting --> Reporting`.
35+
Creating a menu item is required to access a new root report. To do so, open the report's
36+
configuration, click :guilabel:`Action`, :guilabel:`Create Menu Item`, and refresh the page. The
37+
report is now available under :menuselection:`Accounting --> Reporting`.
3738

3839
.. note::
3940
Cases that require creating a new root report are rare, such as when a country's tax authorities
4041
require a new and specific type of report.
4142

42-
.. image:: customize/engine-create-menu-item.png
43-
:align: center
44-
:alt: Create Menu Item button.
45-
4643
.. _customize-reports/variants:
4744

4845
Variants
@@ -52,50 +49,47 @@ Variants are country-specific versions of root reports and, therefore, always re
5249
report. To create a variant, select a generic (root) report in the :guilabel:`Root Report` field
5350
when creating a new report.
5451

55-
When a root report is opened from one of the accounting app's main menus, all its variants are
56-
displayed in the variant selector in the top right corner of the view.
52+
When a root report is opened from the Accounting app's :guilabel:`Reporting` menu, all of its
53+
variants are displayed in the report variant selector in the top right corner of the view.
5754

5855
.. example::
59-
In the following image, :guilabel:`VAT Report (BE)` is the variant of the root :guilabel:`Generic
60-
Tax report`.
56+
:guilabel:`VAT Report (BE)` is a variant of the root :guilabel:`Generic Tax report`.
6157

6258
.. image:: customize/engine-variant.png
63-
:align: center
6459
:alt: Report variant selection.
6560

6661
Lines
6762
=====
6863

69-
After having created a report (either root or variant), you need to fill it with lines. You can
70-
either create a new one by clicking on :guilabel:`Add a line`, or modify an existing line by
71-
clicking on it. All lines *require* a :guilabel:`Name`, and can have an optional additional
72-
:guilabel:`Code` (of your choice) if you wish to use their value in formulas.
64+
After creating a report (either root or variant), the next step is to fill it with lines. To create
65+
a new line, click on :guilabel:`Add a line`. To modify an existing line, click on the line itself
66+
and edit the popup. All lines require a :guilabel:`Name` and can have an optional :guilabel:`Code`
67+
which allows using the line's value in formulas.
7368

7469
.. image:: customize/engine-lines-options.png
75-
:align: center
7670
:alt: Engine lines options.
7771

7872
Expressions
7973
===========
8074

8175
Each line can contain one or multiple **expressions**. Expressions can be seen as **sub-variables**
82-
needed by a report line. To create an expression, click on :guilabel:`Add a line` *within* a line
83-
report.
76+
needed by a report line. To create an expression, click on :guilabel:`Add a line` *within* a line's
77+
popup.
8478

85-
When creating an expression, you must attribute a :guilabel:`label` used to refer to that
86-
expression. Therefore, it has to be **unique** among the expressions of each line. Both a
87-
:guilabel:`Computation Engine` and a :guilabel:`Formula` must also be indicated. The **engine**
88-
defines how your **formula(s)** and **subformula(s)** are interpreted. It is possible to mix
89-
expressions using different computation engines under the same line if you need to.
79+
When creating an expression, you must enter a :guilabel:`label` used to refer to that expression.
80+
The label must be unique among the expressions of each report line. Both the :guilabel:`Computation
81+
Engine` and the :guilabel:`Formula` fields must also be completed. The **computation engine**
82+
defines how the **formula(s)** and **subformula(s)** are interpreted. It is possible to mix
83+
expressions using different computation engines under the same line if needed.
9084

9185
.. note::
9286
Depending on the engine, :guilabel:`subformulas` may also be required.
9387

94-
'Odoo Domain' engine
95-
--------------------
88+
Odoo Domain computation engine
89+
------------------------------
9690

97-
With this engine, a formula is interpreted as an :ref:`Odoo domain <reference/orm/domains>`
98-
targeting `account.move.line` objects.
91+
When using the :guilabel:`Odoo Domain` computation engine, a formula is interpreted as an :ref:`Odoo
92+
domain <reference/orm/domains>` targeting `account.move.line` objects.
9993

10094
The subformula allows you to define how the move lines matching the domain are used to compute the
10195
value of the expression:
@@ -112,39 +106,39 @@ value of the expression:
112106
Otherwise, it is `0`.
113107

114108
`count_rows`
115-
The result is the number of sub-lines of this expression. If the parent line has a group-by
116-
value, this will correspond to the number of distinct grouping keys in the matched move lines.
117-
Otherwise, it will be the number of matched move lines.
109+
The result is the number of sub-lines of this expression. If the parent line has a :ref`group-by
110+
<customize-reports/lines-group-by>` value, this will correspond to the number of distinct
111+
grouping keys in the matched move lines. Otherwise, it will be the number of matched move lines.
118112

119-
You can also put a `-` sign at the beginning of the subformula to **reverse** the sign of the
120-
result.
113+
.. tip::
114+
To **reverse** the sign of the result, put a `-` sign at the beginning of the subformula.
121115

122116
.. image:: customize/engine-expressions.png
123-
:align: center
124117
:alt: Expression line within a line report
125118

126-
'Tax Tags' engine
127-
-----------------
119+
Tax Tags computation engine
120+
---------------------------
128121

129-
A formula made for this engine consists of a name used to match tax tags. If such tags do not exist
130-
when creating the expression, they will be created.
122+
When using the :guilabel:`Tax Tags` computation engine, the contents of the :guilabel:`Formula`
123+
field are matched to tax tags. If such tags do not exist when creating the expression, they will be
124+
created.
131125

132126
When evaluating the expression, the expression computation can roughly be expressed as: **(amount of
133127
the move lines with** `+` **tag)** `-` **(amount of the move lines with** `-` **tag)**.
134128

135129
.. example::
136-
If the formula is `tag_name`, the engine matches tax tags `+tag_name` and `-tag_name`, creating
137-
them if necessary. To exemplify further: two tags are matched by the formula. If the formula
138-
is `A`, it will require (and create, if needed) tags `+A` and `-A`.
130+
If the :guilabel:`Formula` is set to `tag_name`, the engine matches tax tags `+tag_name` and
131+
`-tag_name`, creating them if necessary. To exemplify further: two tags are matched by the
132+
formula. If the formula is `A`, it will require (and create, if needed) tags `+A` and `-A`.
139133

140-
'Aggregate Other Formulas' engine
141-
---------------------------------
134+
Aggregate Other Formulas computation engine
135+
-------------------------------------------
142136

143-
Use this engine when you need to perform arithmetic operations on the amounts obtained for other
144-
expressions. Formulas here are composed of references to expressions separated by one of the four
145-
basic arithmetic operators (addition `+`, subtraction `-`, division `/`, and multiplication `*`). To
146-
refer to an expression, type in its parent line's **code** followed by a period `.` and the
147-
expression's **label** (ex. **code.label**).
137+
The :guilabel:`Aggregate Other Formulas` computation engine performs arithmetic operations on the
138+
amounts obtained from other expressions. Formulas here are composed of references to expressions
139+
separated by one of the four basic arithmetic operators (addition `+`, subtraction `-`, division
140+
`/`, and multiplication `*`). To refer to an expression, type in its parent line's **code** followed
141+
by a period `.` and the expression's **label** (ex. **code.label**).
148142

149143
**Subformulas** can be one of the following:
150144

@@ -175,11 +169,11 @@ that currency.
175169

176170
You can also use the `cross_report` subformula to match an expression found in another report.
177171

178-
'Prefix of Account Codes' engine
179-
--------------------------------
172+
Prefix of Account Codes computation engine
173+
------------------------------------------
180174

181-
This engine is used to match amounts made on accounts using the prefixes of these accounts' codes as
182-
variables in an arithmetic expression.
175+
The :guilabel:`Prefix of Account Codes` computation engine is used to match amounts made on accounts
176+
using the prefixes of these accounts' codes as variables in an arithmetic expression.
183177

184178
.. example::
185179
| `21`
@@ -226,9 +220,9 @@ accounts, where the same prefix might be used for different purposes across comp
226220

227221
.. example::
228222
| `tag(25)`
229-
| This formula matches accounts whose associated tags contain the one with id *25*.
223+
| This formula matches accounts whose associated tags contain the one with ID *25*.
230224
231-
If the tag you reference is defined in a data file, an xmlid can be used instead of the id.
225+
If the tag you reference is defined in a data file, an XMLID can be used instead of the ID.
232226

233227
.. example::
234228
| `tag(my_module.my_tag)`
@@ -255,14 +249,13 @@ Prefix exclusion also works with tags.
255249
| This formula matches accounts with the tag *my_module.my_tag* and a code not starting with
256250
`10`.
257251
252+
External Value computation engine
253+
---------------------------------
258254

259-
'External Value' engine
260-
-----------------------
261-
262-
The 'external value' engine is used to refer to **manual** and **carryover values**. Those values
263-
are not stored using `account.move.line`, but with `account.report.external.value`. Each of these
264-
objects directly points to the expression it impacts, so very little needs to be done about their
265-
selection here.
255+
The :guilabel:`External Value` computation engine is used to refer to **manual** and **carryover
256+
values**. Those values are not stored using `account.move.line`, but with
257+
`account.report.external.value`. Each of these objects directly points to the expression it impacts,
258+
so very little needs to be done about their selection here.
266259

267260
**Formulas** can be one of the following:
268261

@@ -288,15 +281,16 @@ Both subformulas can be mixed by separating them with a `;`.
288281

289282
.. example::
290283
| `editable;rounding=2`
291-
| is a correct subformula mixing both behaviors.
284+
| This subformula shows the correct way to mix both behaviors.
292285
293-
'Custom Python Function' engine
294-
-------------------------------
286+
Custom Python Function computation engine
287+
-----------------------------------------
295288

296-
This engine is a means for developers to introduce custom computation of expressions on a
297-
case-by-case basis. The formula is the name of a **python function** to call, and the subformula is
298-
a **key** to fetch in the **dictionary** returned by this function. Use it only if you are making a
299-
custom module of your own.
289+
The :guilabel:`Custom Python Function` computation engine is a means for developers to introduce
290+
custom computation of expressions on a case-by-case basis. The :guilabel:`Formula` is the name of a
291+
**python function** to call, and the :guilabel:`Subformula` is a **key** to fetch in the
292+
**dictionary** returned by this function. Use this computation engine only if making a custom
293+
module.
300294

301295
Columns
302296
=======
@@ -308,8 +302,60 @@ field, then nothing is displayed for it in this column. If multiple columns are
308302
use different **expression** labels.
309303

310304
.. image:: customize/engine-columns.png
311-
:align: center
312305
:alt: Columns of report.
313306

314307
When using the **period comparison** feature found under the :guilabel:`Options` tab of an
315308
accounting report, all columns are repeated in and for each period.
309+
310+
.. _customize-reports/lines-group-by:
311+
312+
Line grouping
313+
=============
314+
315+
Once the report is filled with lines, the lines can be grouped. To do so, choose which field to
316+
group by. Any field can be used, even if it does not exist in the journal item model yet.
317+
318+
.. important::
319+
The field must be on the journal item model, be non-stored, and be related to the model and field
320+
you want to group by (i.e., related to the res.country model and the
321+
partner_id.commercial_partner_id.country_id field) in order to group by the country of the
322+
commercial partner.
323+
324+
.. note::
325+
Grouping lines requires the report to have explicit report lines that can be edited. The deferred
326+
reports, for example, do not support grouping lines as they use dynamic lines that are generated.
327+
328+
Create a new field on journal item
329+
----------------------------------
330+
331+
To create a non-stored related field in the journal item model, first go to
332+
:menuselection:`Accounting --> Journal Items`, and click the :icon:`fa-bug` :guilabel:`(bug)` icon,
333+
then click :guilabel:`Fields`. Click :guilabel:`New` to create a new field, and complete the
334+
following fields:
335+
336+
- :guilabel:`Field Name`: the technical name of the field
337+
- :guilabel:`Field Label`: the displayed label of the field
338+
- :guilabel:`Field Type`: :guilabel:`one2many`, :guilabel:`many2many`, or :guilabel:`many2one`
339+
- :guilabel:`Readonly`: while not strictly necessary, it is recommended to use readonly fields for
340+
grouping lines
341+
- :guilabel:`Stored`: leave this field unchecked as only non-stored fields can be used to group
342+
lines
343+
- :guilabel:`Related Model`: the model of the original field to group by
344+
- :guilabel:`Related Field Definition`: the technical path to the field you want to group by
345+
346+
.. example::
347+
To group by the country of the commercial partner, set the related field definition to
348+
`partner_id.commercial_partner_id.country_id`.
349+
350+
Group lines
351+
-----------
352+
353+
To group lines, go to the :guilabel:`Lines` tab of the desired report, click on the line you want to
354+
group, and edit the :guilabel:`Group by` field. Enter the technical name (:guilabel:`Field Name`) of
355+
the field to use as the grouping key.
356+
357+
.. tip::
358+
To find a list of all the model's fields and their technical names, go to
359+
:menuselection:`Accounting --> Journal Items`, and click the :icon:`fa-bug` :guilabel:`(bug)`
360+
icon, then click :guilabel:`Fields`. The technical name of each field is listed in the
361+
:guilabel:`Field Name` column.
Loading
Loading

0 commit comments

Comments
 (0)
0