自定义报告

Odoo 附带一个功能强大且易于使用的报告框架。该引擎允许您创建新的报告,如**税务报告**或**资产负债表**和**收入报表**,并可进行**特定分组**和**布局**。

重要

激活 开发者模式 访问会计报告创建界面。

要创建新报告,请访问 会计 ‣ 配置 ‣ 管理:会计报告。在这里,您可以创建 根报告变体

会计报告引擎。

根报告

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

Example

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

创建新的根报告时,需要为其创建**菜单项**。为此,请打开报告,然后在同一报告上单击 操作 ‣ 创建菜单项目。刷新页面;现在该报告在 会计 ‣ 报告 下可用。

注解

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

创建菜单项按钮。

变体

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

从会计应用程序的主菜单之一打开根报告时,其所有变体都会显示在视图右上角的变体选择器中。

Example

在下图中,:guilabel:`增值税报告(BE)`是根:guilabel:`通用税务报告`的变体。

报告变体选择。

明细行

创建报告(根报告或变量报告)后,需要在报告中添加行。您可以点击 添加行 创建新行,也可以点击现有行进行修改。所有行都*需要*一个 名称,如果您希望在公式中使用它们的值,还可以选择附加 :guilabel:`代码`(由您选择)。

Engine lines options.

表达式

每一行可以包含一个或多个**表达式**。表达式可视为报告行所需的**子变量**。要创建表达式,请单击行报告*内*的 添加行

创建表达式时,您必须为该表达式指定一个 标签 属性。因此,在每一行的表达式中,它必须是**唯一**的。还必须指定 计算引擎公式引擎**定义了如何解释您的**公式**和**子公式。如果需要,可以在同一行中混合使用不同计算引擎的表达式。

注解

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

‘Odoo 域名’ 引擎

使用此引擎时,公式被解释为针对`account.move.line`对象的:ref:Odoo 域名<reference/orm/domains>

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

总额

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

sum_if_pos

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

sum_if_neg

The result is the sum of all the balances of the matched move lines if this amount is negative. Otherwise, it is 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.

您也可以在子公式的开头加上 - 号,来**取反**结果的符号。

Expression line within a line report

‘Tax Tags’ engine

A formula made for this engine consists of a name used to match tax tags. If such tags do not exist when creating the expression, they will be created.

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

Example

If the formula is 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’ engine

当您需要对其他表达式得到的金额进行算术运算时,请使用此引擎。这里的公式由引用表达式组成,表达式由四个基本算术运算符(加法运算符 +、减法运算符 -、除法运算符 / 和乘法运算符 *)之一分隔。要引用一个表达式,请输入其上级行的**代码**,后跟一个句点`.`和表达式的**标签**(例如**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’ engine

该引擎用于匹配账户金额,使用这些账户代码的前缀作为算术表达式中的变量。

Example

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

Example

21 + 10 - 5
This formula adds the balances of the move lines made on accounts whose codes start with 21 and 10, and subtracts the balance of the ones on accounts with the prefix 5.

It is also possible to ignore a selection of sub-prefixes.

Example

21 + 10\(101, 102) - 5\(57)
This formula works the same way as the previous example but ignores the prefixes 101, 102, and 57.

You can apply ‘sub-filtering’ on credits and debits using the C and D suffixes. In this case, an account will only be considered if its prefix matches, and if the total balance of the move lines made on this account is credit/debit.

Example

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

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

Example

21D + 10\(101, 102)C - 5\(57)
This formula adds the balances of the move lines made on accounts whose code starts with 21 if it is debit (D) and 10 if it is credit (C), but ignores prefixes 101, 102, and subtracts the balance of the ones on accounts with the prefix 5, ignoring the prefix 57.

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

Example

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

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

Example

tag(25)
该公式会匹配相关标记包含 id 25 的账户。

如果您引用的标记是在数据文件中定义的,则可以使用 xmlid 代替 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 开头的账户。

‘外部价值’ 引擎

‘外部值’引擎用于参考**手动值**和**结转值**。这些值不是使用`account.move.line`存储的,而是使用`account.report.external.value`。这些对象中的每一个都直接指向它所影响的表达式,因此在这里几乎不需要进行选择。

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

总额

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

most_recent

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

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

舍入=X

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

可编辑

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

注解

Manual values are created at the date_to currently selected in the report.

Both subformulas can be mixed by separating them with a ;.

Example

editable;rounding=2
is a correct subformula mixing both behaviors.

‘Custom Python Function’ engine

This 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 it only if you are making a custom module of your own.

Reports can have an indefinite number of columns to display. Each column gets its values from the expressions declared on the lines. The field expression_label of the column gives the label of the expressions whose value is displayed. If a line has no expression in that field, then nothing is displayed for it in this column. If multiple columns are required, you must use different expression labels.

Columns of report.

When using the period comparison feature found under the Options tab of an accounting report, all columns are repeated in and for each period.