自定义报告

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

重要

Activate the developer mode to access the accounting report configuration.

To create a new report, go to Accounting ‣ Configuration ‣ Accounting Reports. From here, create either a root report or a variant.

小技巧

  • Consider saving modified reports as report variants to keep their root reports intact.

  • To access an existing report’s management interface from the report itself, click on the (gears) icon.

根报告

根报告可被视为通用的、中立的会计报告。它们是建立本地会计版本的模型。如果一个报告没有根报告,那么它本身就被视为根报告。

Example

比利时和美国的税务报告都将以相同的通用版本为基础,并根据其本地法规进行调整。

Creating a menu item is required to access a new root report. To do so, open the report’s configuration, click Action, Create Menu Item, and refresh the page. The report is now available under Accounting ‣ Reporting.

注解

需要创建新的根报告的情况很少见,例如当一个国家/地区的税务机构要求一种新的特定类型的报告时。

变体

变体是根报告的特定国家/地区版本,因此总是引用根报告。要创建变体,请在创建新报告时在 根报告 字段中选择通用(根)报告。

When a root report is opened from the Accounting app’s Reporting menu, all of its variants are displayed in the report variant selector in the top right corner of the view.

Example

VAT Report (BE) is a variant of the root Generic Tax report.

报告变体选择。

After creating a report (either root or variant), the next step is to fill it with lines. To create a new line, click on Add a line. To modify an existing line, click on the line itself and edit the popup. All lines require a Name and can have an optional Code which allows using the line’s value in formulas.

引擎行选项。

表达式

Each line can contain one or multiple expressions. Expressions can be seen as sub-variables needed by a report line. To create an expression, click on Add a line within a line’s popup.

When creating an expression, you must enter a Label used to refer to that expression. The label must be unique among the expressions of each report line. Both the Computation Engine and the Formula fields must also be completed. The computation engine defines how the formula(s) and subformula(s) are interpreted. It is possible to mix expressions using different computation engines under the same line if needed.

注解

根据引擎的不同,可能还需要 子公式

Odoo Domain computation engine

When using the Odoo Domain computation engine, a formula is interpreted as an Odoo domain targeting account.move.line objects.

子公式允许您定义如何使用与域匹配的移动行来计算表达式的值:

总额

结果是匹配移动线路的所有余额之和。

sum_if_pos

如果结果为正数,则为匹配移动行的所有余额之和。否则,结果为`0`。

sum_if_neg

如果结果为负数,传回所有相符分录资料行的余额之和。否则,传回 0

count_rows

The result is the number of sub-lines of this expression. If the parent line has a group-by value, this will correspond to the number of distinct grouping keys in the matched move lines. Otherwise, it will be the number of matched move lines.

小技巧

To reverse the sign of the result, put a - sign at the beginning of the subformula.

资料行报告中的表达式资料行

Tax Tags computation engine

When using the Tax Tags computation engine, the contents of the Formula field are matched to tax tags. If such tags do not exist when creating the expression, they will be created.

在评估表达式时,表达式计算可大致表示为:(带有 + 标记的分录资料行数目)**`-` **(带有 - 标记的分录资料行数目)

Example

If the Formula is set to tag_name, the engine matches tax tags +tag_name and -tag_name, creating them if necessary. To exemplify further: two tags are matched by the formula. If the formula is A, it will require (and create, if needed) tags +A and -A.

Aggregate Other Formulas computation engine

The Aggregate Other Formulas computation engine performs arithmetic operations on the amounts obtained from other expressions. Formulas here are composed of references to expressions separated by one of the four basic arithmetic operators (addition +, subtraction -, division /, and multiplication *). To refer to an expression, type in its parent line’s code followed by a period . and the expression’s label (ex. code.label).

**子公式**可以是以下其中之一:

if_above(CUR(amount))

只有当算术表达式的值大于所提供的界限时,才会返回该值。否则,结果将是 0

if_below(CUR(amount))

只有当算术表达式的值小于所提供的界限时,才会返回该值。否则,结果将为 0

if_between(CUR1(amount1), CUR2(amount2))

只有当算术表达式的值严格位于所提供的界限之间时,才会返回该值。否则,将返回最接近的界限。

if_other_expr_above(LINE_CODE.EXPRESSION_LABEL, CUR(amount))

只有当所提供的行代码和表达式标签所表示的表达式值大于所提供的界限时,才会返回算术表达式的值。否则,结果将为 0

if_other_expr_below(LINE_CODE.EXPRESSION_LABEL, CUR(amount))

只有当所提供的行代码和表达式标签所表示的表达式值小于所提供的界限时,才会返回算术表达式的值。否则,结果将为 0

CUR 是大写的货币代码,amount 是以该货币表示的绑定金额。

您还可以使用 cross_report 子公式来匹配另一份报告中的表达式。

Prefix of Account Codes computation engine

The Prefix of Account Codes computation engine is used to match amounts made on accounts using the prefixes of these accounts’ codes as variables in an arithmetic expression.

Example

21
算术表达式也可以是一个前缀,如此处。

Example

21 + 10 - 5
该公式将代码以 2110 开头的账户内的分录资料行数额相加,然后减去代码以 `5`开头的账户内的分录资料行数额。

也可以忽略选定的子前缀。

Example

21 + 10\(101, 102) - 5\(57)
该公式的运作方式与上一示例相同,但不会考虑前缀 10110257

您可以使用后缀 `C`(贷) 和 `D`(借) 对**贷记和借记**进行“子筛选”。在这种情况下,只有账户的前缀匹配,且该账户内的分录资料行的总余额为**贷记/借记**时,才会考虑该账户。

Example

账户 210001 余额为 -42,账户 210002 余额为 25。公式 21D 只与账户 210002 匹配,因此返回 25。210001 不匹配,因为其余额为*贷方*。

前缀排除可与`C`和`D`后缀混合使用。

Example

21D + 10\(101, 102)C - 5\(57)
该公式会将代码字首为 21 的分录资料行金额(*如果*金额属借方,即 D)以及字首为 10 的分录资料行金额(*如果*金额属贷方,即 C)相加,但不会考虑字首 101102 的账户,然后减去字首为 5 的账户的金额,但不会考虑字首 57 的账户。

要匹配前缀中的字母 CD,但不将其用作后缀,请使用空排除项 ()

Example

21D\()
该公式匹配以`21D`开头的账户,不论其余额正负。

除了使用代码前缀来包含账户外,还可以用**账户标记**来匹配它们。举例来说,如果你所在的国家没有标准化的会计科目表,那么相同的前缀在不同的公司可能会有不同的用途,这个方法就特别有用。

Example

tag(25)
This formula matches accounts whose associated tags contain the one with ID 25.

If the tag you reference is defined in a data file, an XMLID can be used instead of the ID.

Example

tag(my_module.my_tag)
该公式匹配的账户,其关联标记包括 my_module.my_tag 所表示的标记。

您还可以将算术表达式与标记一起使用,也可以将其与前缀选择相结合。

Example

tag(my_module.my_tag) + tag(42) + 10
标记为 my_module.my_tag 的账户余额将与 ID 为 42 的标记所链接的账户余额以及代码前缀为`10`的账户余额相加。

后缀 CD 的使用方法与标签相同。

Example

tag(my_module.my_tag)C
该公式可匹配带有 my_module.my_tag 标记和贷方余额的账户。

前缀排除也适用于标签。

Example

tag(my_module.my_tag)\(10)
该公式匹配标记为 my_module.my_tag 和代码不是以 10 开头的账户。

External Value computation engine

The External Value computation engine is used to refer to manual and carryover values. Those values are not stored using account.move.line, but with account.report.external.value. Each of these objects directly points to the expression it impacts, so very little needs to be done about their selection here.

**公式**可以是以下之一:

总额

如果结果必须是该周期内所有外部值的总和。

most_recent

如果结果必须是该周期内最新外部值的值。

此外,**子公式**有两种使用方法:

舍入=X

X 替换为数字,表示将金额四舍五入到小数点后 X 位。

可编辑

表示可以手动编辑该表达式,从而在报告中显示一个图标,允许用户执行该操作。

注解

手动值在报告中当前选择的 date_to 处创建。

这两个子公式可以混合使用,方法是用 ; 分隔。

Example

editable;rounding=2
This subformula shows the correct way to mix both behaviors.

Custom Python Function computation engine

The Custom Python Function computation engine is a means for developers to introduce custom computation of expressions on a case-by-case basis. The Formula is the name of a python function to call, and the Subformula is a key to fetch in the dictionary returned by this function. Use this computation engine only if making a custom module.

报表可显示的列数**无限**。每列会从**资料行**上宣告的**表达式**获取数值。该列的 expression_label 字段给出了显示其值的表达式的标签。如果资料行在某字段中没有**表达式**,该行在此列的位置便不会显示任何内容。如果需要多个列,必须使用不同的**表达式**标签。

报告栏。

在会计报告的 选项 分页选用**期间比较**功能时,所有列都会在每个期间内,为每个期间重复显示。

Line grouping

Non-standard grouping is possible by adding or using existing fields on the Journal Item model, provided that the fields are related and non-stored.

注解

Grouping lines requires the report to have explicit report lines that can be edited. The deferred reports, for example, do not support grouping lines as they use dynamic lines that are generated.

Create a new field on journal item

To create a non-stored, related field in the Journal Item model, first go to Accounting ‣ Journal Items, and click the (bug) icon, then click Fields. Click New to create a new field, and complete the following fields:

  • Field Name: a technical name for the field

  • Field Label: the label to be displayed for the field

  • Field Type: the type of field that this related field should point to

  • Stored: Leave this field unchecked as only non-stored fields can be used to group lines.

  • Related Model: If the field type is one2many, many2many, or many2one, select the model of the original field to group by.

  • Related Field Definition: the technical path to the field you want to group by

    Example

    To group by the sales team of the commercial partner, set the related field definition to move_id.team_id.

Group lines

To group lines, go to the Lines tab of the desired report, click on the line you want to group, and edit the Group by field. Enter the technical name (Field Name) of the field to use as the grouping key.

小技巧

To find a list of all the model’s fields and their technical names, go to Accounting ‣ Journal Items, and click the (bug) icon, then click Fields. The technical name of each field is listed in the Field Name column.