欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 汽车 > 新车 > odoo17创建一个默认UI视图

odoo17创建一个默认UI视图

2025/4/20 19:31:44 来源:https://blog.csdn.net/qq_42672770/article/details/140532632  浏览:    关键词:odoo17创建一个默认UI视图

XML  数据文件 

当要加载的数据具有简单格式时,CSV 格式很方便。当格式更复杂时(例如,加载视图或电子邮件模板的结构),我们使用 XML 格式。例如,此帮助字段包含 HTML 标记。虽然可以通过 CSV 文件加载此类数据,但使用 XML 文件更方便。


XML 文件必须添加到与 CSV 文件相同的文件夹中, __manifest__.py 并在 .在安装或更新模块时,数据文件的内容也会按顺序加载,因此对 CSV 文件所做的所有注释都适用于 XML 文件。当数据链接到视图时,我们会将它们添加到文件夹中 views 。

我们将通过 XML 文件加载第一个操作和菜单。操作和菜单是数据库中的标准记录。

在Odoo中,用户界面(操作,菜单和视图)主要是通过创建和撰写XML文件中定义的记录来定义的。常见的模式是“菜单”>“操作”>“视图”。要访问记录,用户需要通过多个菜单级别导航;最深层次是触发打开记录列表的操作。

Actions 操作

可以通过三种方式触发Action操作:

  1. by clicking on menu items (linked to specific actions)
    通过单击菜单项(链接到特定操作)

  2. by clicking on buttons in views (if these are connected to actions)
    通过单击视图中的按钮(如果这些按钮连接到操作)

  3. as contextual actions on object
    作为对对象的上下文操作

在本章中,我们将只介绍第一种情况。第二种情况将在后面的章节中介绍,而最后一种情况是高级主题的重点。在我们的房地产示例中,我们希望将菜单链接到 estate.property 模型,以便我们能够创建新记录。该操作可以被视为菜单和模型之间的链接。

A basic action for our test_model is:
我们在test_model 中的一个基础Action操作是:

<record id="test_model_action" model="ir.actions.act_window"><field name="name">Test action</field><field name="res_model">test_model</field><field name="view_mode">tree,form</field>
</record>
  • id is an external identifier. It can be used to refer to the record (without knowing its in-database identifier).
    id 是外部标识符。它可用于引用记录(不知道其数据库内标识符)。

  • model has a fixed value of ir.actions.act_window (Window Actions (ir.actions.act_window)).
    model 具有固定 ir.actions.act_window 值 (Window Actions (ir.actions.act_window))。

  • name is the name of the action.
    name 是操作的名称。

  • res_model is the model which the action applies to.
    res_model 是应用该操作的模型。

  • view_mode are the views that will be available; in this case they are the list (tree) and form views. We’ll see later that there can be other view modes.
    view_mode 是将可用的视图;在本例中,它们是列表(树)和表单视图。我们稍后会看到,可以有其他视图模式。

在Odoo中随处可见的例子,但这是简单操作的一个很好的例子。请注意 XML 数据文件的结构

Menus 菜单

定义结构的最简单方法是在 XML 文件中创建它。我们 test_model_action 的基本结构是:

<menuitem id="test_menu_root" name="Test"><menuitem id="test_first_level_menu" name="First Level"><menuitem id="test_model_menu_action" action="test_model_action"/></menuitem>
</menuitem>

The name for the third menu is taken from the name of the action.
第三个菜单的名称取自 action .

Fields, Attributes And View
字段、属性和视图

在进一步进行视图设计之前,让我们回到模型定义。我们看到某些属性(如 required=True )会影响数据库中的表架构。其他属性将影响视图或提供默认值。

可以为任何字段指定默认值。在字段定义中,添加选项 default=X ,其中 X 要么是 Python 文本值(布尔值、整数、浮点数、字符串),要么是接受模型并返回值的函数:

name = fields.Char(default="Unknown")
last_seen = fields.Datetime("Last Seen", default=fields.Datetime.now)

The name field will have the value ‘Unknown’ by default while the last_seen field will be set as the current time.
默认情况下,该 name 字段的值为“未知”,而该 last_seen 字段将设置为当前时间。

active 是具有特定行为的保留字段的示例:当记录具有 active=False 时,它会自动从任何搜索中删除。若要显示创建的属性,需要专门搜索非活动记录。

向 estate.property 模型添加字段 state 。可能有五个值:“新建”、“已收到报价”、“已接受报价”、“已售出”和“已取消”。它必须是必需的,不应复制,并且应将其默认值设置为“新建”。

Make sure to use the correct type!
确保使用正确的类型!

The state will be used later on for several UI enhancements.
稍后 state 将用于多个 UI 增强功能。

Now that we are able to interact with the UI thanks to the default views, the next step is obvious: we want to define our own views.
现在,由于默认视图,我们能够与UI进行交互,下一步是显而易见的:我们要定义自己的视图。

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词