全局搜索与筛选

Global filters, represented by the :icon:`os-global-filters` Filters icon at the top right of an Odoo spreadsheet, allow you to apply one or more filters to all the Odoo data that has been inserted in that spreadsheet.

These filters are particularly useful for reports and dashboards as users can easily and dynamically customize the view to answer complex business questions spanning multiple data sources.

Tip

On a dashboard, global filters that have been created in the underlying spreadsheet are applied via the search bar at the top of the dashboard.

Global filters at the top of a dashboard

Four types of global filters are available:

  • 日期 :根据特定时间范围筛选数据,可使用 月/季度相对周期从 / 至 选项。

  • 关系 :根据相关模型中的关系字段筛选数据,例如,通过 销售人员 并将 用户 模型设置为相关模型。

  • ref:文本 <spreadsheet/global-filters/create-text> :根据文本字符串或预定义值范围(如产品编号或条形码)筛选数据。

  • Yes/No: filters data based on whether or not a checkbox, or boolean, field is set, e.g., lead is active.

全局筛选器与标准的 (添加筛选器)`电子表格函数不同,前者可让您对数据进行排序和临时隐藏,后者则作用于底层的 数据源 ,在数据载入电子表格之前对其进行筛选。

创建全局过滤器时,每个数据源的 字段匹配 将确保过滤器作用于正确的数据库 字段

Tip

  • 全局筛选器的工作原理是在电子表格中所有数据源的域中添加额外的条件。因此,如果打算使用全局筛选器,在配置数据库中的初始列表、透视表或图表时,不要使用相同的条件。

  • 在相关情况下设置默认值,可确保电子表格或仪表盘快速加载,并提供有用的初始视图,如有需要还可进一步自定义。例如,可以设置 日期 筛选器,默认显示过去 30 天的数据。

字段匹配

Important

这一过程至关重要,因为匹配错误的字段或根本不设置匹配字段,会导致全局筛选器无法显示所需的结果。

全局筛选器需要作用于正确的数据库字段,才能发挥预期功能。请看应用于销售数据的 日期 筛选器。由于*销售订单* 模型包含多个日期字段,因此确定哪个字段与筛选器相关至关重要,例如订单日期、交货日期、预期日期或到期日期。

当 :ref:` 创建全局筛选器 <spreadsheet/global-filters/create>` 时, 筛选器属性字段匹配 部分允许您为电子表格中的每个 数据源 ,确定筛选器应作用于或匹配哪个数据库字段。

Field matching is further explained in the relevant sections on creating Date, Relation, Text, and Yes/No global filters.

创建全局筛选器

Odoo 文件管理 应用程序或通过 Odoo 仪表板 应用程序打开所需的电子表格(如果您要向仪表板添加筛选器)。

To add a new filter, click :icon:`os-global-filters` Filters to open the Filters panel. Under Create filter, click Date, Relation, Text, or Yes/No as appropriate.

Note

Depending on the data source(s) present in the spreadsheet, suggested relation filters may be shown. Clicking on a suggested filter opens the Filter properties panel with certain values preconfigured.

保存全局筛选器时,如果缺少任何必填信息,或如果在 字段匹配 部分中提供的任何信息不合适,则会显示错误,说明 某些必填字段无效

Tip

  • To access the underlying spreadsheet of a dashboard, activate developer mode, then click the (Edit) icon that appears when hovering over the dashboard name in the left panel.

  • Click (pin) at the top of the Filters panel to allow another panel, such as the Filter properties panel, to open beside it.

日期

Note

日期 筛选器只能与 日期日期和时间 字段匹配。

With the Filter properties panel open:

  1. 标签 字段中输入新日期筛选器的名称。

  2. To set a Default value, select one of the available values, e.g, Last 30 Days or Month to Date. When applying the global filter, any of the available values can be selected.

  3. In the Field matching section, for each data source, click beside Date field and select the field the filter should match with.

    The Period offset option, which appears when a date field is chosen, enables comparisons to be made by shifting the time range by one or more periods in the past or future. By default, no period offset is defined. To define a period offset, select Previous or Next, then select the desired number of periods in the past or future.

    Tip

    要使用 周期偏移 功能有效地比较数据,请使用 复制相关插入列表数据透视表 ,然后在设置字段匹配时,为第二个数据源而不是第一个数据源设置周期偏移。

    应用筛选器时,原始列表或数据透视表显示所选时间范围内的数据,而第二个列表或数据透视表则显示该时间范围之前或之后的数据。

  4. 点击 保存

Example

In the example below, a Date global filter allows the pivot table and chart to show sales data for any defined time period, in this case, July 2025. The Custom Range always shows the actual dates corresponding to the chosen period; it can also be updated directly.

A date filter filters data for July 2025

In the Field matching section of the Filter properties, the field Order Date has been selected as the matching date field.

日期筛选器,选择订单日期作为匹配字段

关联

Note

关系 筛选器只能与 Many2OneOne2ManyMany2Many 字段匹配。

With the Filter properties panel open:

  1. 标签 字段中输入新关系筛选器的名称。

  2. 相关模型 字段中,开始键入模型名称以显示所有模型的列表,然后选择相应的模型。一旦选择了一个模型, 默认值可能值 字段以及 字段匹配 部分就会出现。

  3. 要设置 默认值 ,请从可用值中选择一个;这些值是模型中的记录。如果相关模型是*用户*模型,则可启用 自动筛选当前用户 选项。

  4. 要限制可显示的值,请启用 用域限制值 ,然后点击 编辑域 添加或编辑规则。

  5. 字段匹配 部分,检查是否已为每个数据源分配了正确的匹配字段。如果没有,请点击数据源名称下方以选择正确的字段。

  6. 点击 保存

Example

In the example below, a Relation filter allows the pivot table and chart to show sales data related to selected salespeople only. The User model is set as the Related model.

在数据透视表上设置关系筛选器

In the Field matching section of the Filter properties, the field Salesperson was automatically assigned as the matching field for both the pivot table and the chart.

配置了用户模型的关系筛选器

文本

Note

A Text filter can only match with a Text (char), Integer, or Decimal (float) field.

With the Filter properties panel open:

  1. 标签 字段中输入新文本筛选器的名称。

  2. Optionally, enable Restrict values to a range. Doing so allows you to input a spreadsheet range either by typing the range or selecting it from the relevant sheet. The referenced range must be in the same spreadsheet.

  3. 可选择输入 默认值

  4. 字段匹配 部分,点击每个数据源的数据源名称下方,选择 文本 筛选器应匹配的字段。

  5. 点击 保存

Example

In the example below, a Text global filter allows the pivot table and chart to show sales data only for products whose internal reference matches or contains the entered value, in this case, FURN. Multiple values can be entered if desired.

设置在枢轴表上的全局筛选器

In the Field matching section of the Filter properties, the Internal Reference of the Product Variant was selected as the matching field for both the pivot table and the chart.

A text filter matched to the product's internal reference

Tip

If you selected Restrict values to range when configuring the text filter and defined a range, you select the value of the text field from a dropdown.

是/否

Note

A Yes/No filter can only match with a Checkbox (boolean) field.

打开 筛选器属性 窗格:

  1. Enter a name for the new Yes/No filter in the Label field.

  2. Optionally, select Is set or Is not set as the Default value.

  3. In the Field matching section, for each data source, click below the data source name and select the field the Yes/No filter should match with.

  4. 点击 保存

Example

In the example below, a Yes/No global filter was created to allow the user to see all active opportunities, i.e., for which the Active checkbox is enabled on the record, or all inactive opportunities, i.e., for which the Active checkbox is disabled. Leaving the filter empty shows both active and inactive opportunities.

设置在枢轴表上的全局筛选器

In the Field matching section of the Filter properties, the field Active was assigned as the matching field for the pivot table.

A yes/no filter with the Active field set as matching field

管理和使用全局筛选器

点击 Odoo 电子表格右上方的 :icon:`os-global-filters` 筛选器 图标,即可访问为该电子表格创建的全局筛选器。

有可能:

  • 通过选择每个筛选器的适当值,应用一个或多个全局筛选器

    Tip

    Reloading the browser will cause any global filters to reset to their initial state or default value, as relevant. To refresh data in an inserted list, pivot table, or chart without losing global filters that have been applied, click Data ‣ :icon:`os-refresh-data` Refresh all data from the menu bar.

  • 将鼠标悬停在筛选器上,使用 :icon:`os-thin-drag-handle` (拖动手柄) 图标更改位置,即可**更改现有筛选器的顺序**。

  • 点击筛选器值旁边的 (清除) 图标,即可**清除筛选器值**(无论是默认值还是选定值)。

  • 编辑现有筛选器 通过选择 (编辑) 图标打开筛选器的 筛选器属性 ,然后根据需要进行编辑。

  • 通过选择 :icon:`fa-cog`:guilabel:`(编辑)` 图标打开筛选器的 :guilabel:`筛选器属性` ,然后点击 :guilabel:`移除` ,**删除现有的筛选器