Odoo16 实用功能之Tree视图详解(树形视图)

目录

1、什么是tree视图

2、源码Tree视图详解

1、源码

2、参数讲解

3、Tree视图中标签的常用参数详解

4、标签参数详解

3、Tree视图中的按钮

1、表头按钮

2、记录行按钮


1、什么是tree视图

        Tree视图是一种用于显示记录列表的视图类型。它通常用于显示数据库中的多个记录,并以表格的形式呈现数据。Tree视图是Odoo中最常见和灵活的视图之一。

2、源码Tree视图详解

1、源码

本次以CRM中的渠道Tree视图做为讲解

源码为:

        <record id="crm_case_tree_view_oppor" model="ir.ui.view">
            <field name="name">crm.lead.tree.opportunity</field>
            <field name="model">crm.lead</field>
            <field name="priority">1</field>
            <field name="arch" type="xml">
                <tree string="Opportunities" sample="1" multi_edit="1">
                    <header>
                        <button name="%(crm.action_lead_mass_mail)d" type="action" string="Email" />
                    </header>
                    <field name="company_id" invisible="1"/>
                    <field name="user_company_ids" invisible="1"/>
                    <field name="date_deadline" invisible="1"/>
                    <field name="create_date" optional="hide"/>
                    <field name="name" string="Opportunity" readonly="1"/>
                    <field name="partner_id" optional="hide"/>
                    <field name="contact_name" optional="show"/>
                    <field name="email_from"/>
                    <field name="phone" class="o_force_ltr"/>
                    <field name="company_id" groups="base.group_multi_company" optional="show"/>
                    <field name="city" optional="hide"/>
                    <field name="state_id" optional="hide"/>
                    <field name="country_id" optional="hide" options="{'no_open': True, 'no_create': True}"/>
                    <!-- Explicit domain due to multi edit -> real company domain would be complicated -->
                    <field name="user_id" widget="many2one_avatar_user" optional="show"
                        domain="[('share', '=', False)]"/>
                    <field name="team_id" optional="hide"/>
                    <field name="priority" optional="hide" widget="priority"/>
                    <field name="activity_ids" widget="list_activity"/>
                    <field name="activity_user_id" optional="hide" string="Activity by" widget="many2one_avatar_user"/>
                    <field name="my_activity_date_deadline" string="My Deadline" widget="remaining_days" options="{'allow_order': '1'}"/>
                    <field name="activity_calendar_event_id" invisible="1"/>
                    <field name="campaign_id" optional="hide"/>
                    <field name="medium_id" optional="hide"/>
                    <field name="source_id" optional="hide"/>
                    <field name="company_currency" invisible="1"/>
                    <field name="expected_revenue" sum="Expected Revenues" optional="show" widget="monetary" options="{'currency_field': 'company_currency'}"/>
                    <field name="date_deadline" optional="hide"/>
                    <field name="recurring_revenue_monthly" sum="Expected MRR" optional="show" widget="monetary"
                        options="{'currency_field': 'company_currency'}" groups="crm.group_use_recurring_revenues"/>
                    <field name="recurring_revenue" sum="Recurring Revenue" optional="hide" widget="monetary"
                        options="{'currency_field': 'company_currency'}" groups="crm.group_use_recurring_revenues"/>
                    <field name="recurring_plan" optional="hide" groups="crm.group_use_recurring_revenues"/>
                    <field name="stage_id" optional="show" decoration-bf="1"/>
                    <field name="active" invisible="1"/>
                    <field name="probability" string="Probability (%)" optional="hide"/>
                    <field name="tag_ids" optional="hide" widget="many2many_tags" options="{'color_field': 'color'}"/>
                    <field name="referred" invisible="1"/>
                    <field name="message_needaction" invisible="1"/>
                    <button name="%(crm.action_lead_mail_compose)d" type="action" string="Email" icon="fa-envelope"/>
                    <button name="action_reschedule_meeting" class="text-warning" type="object" string="Reschedule"
                        icon="fa-calendar" attrs="{'invisible': ['|', ('my_activity_date_deadline', '=', False),
                        ('activity_calendar_event_id', '=', False)]}"/>
                    <button name="action_snooze" class="text-warning" type="object" string="Snooze 7d"
                        icon="fa-bell-slash" attrs="{'invisible': ['|', ('my_activity_date_deadline', '=', False),
                        ('activity_calendar_event_id', '!=', False)]}"/>
                </tree>
            </field>
        </record>

2、参数讲解

  1. <record id="crm_case_tree_view_oppor" model="ir.ui.view">: 定义一个ir.ui.view记录,其唯一标识为"crm_case_tree_view_oppor",属于"ir.ui.view"模型。

  2. <field name="name">crm.lead.tree.opportunity</field>: 设置视图的名称为"crm.lead.tree.opportunity"。

  3. <field name="model">crm.lead</field>: 设置该视图关联的模型为"crm.lead",即CRM模块中的机会模型。

  4. <field name="priority">1</field>: 设置优先级为1,表示这个视图的优先级。

  5. <field name="arch" type="xml">: 定义了视图的结构部分,类型为XML。

  6. <tree string="Opportunities" sample="1" multi_edit="1">: 开始定义Tree视图,设置标题为"Opportunities",samplemulti_edit分别表示启用示例模式和多编辑模式。

  7. <header>: 定义Tree视图的头部,用于显示一些操作按钮等。

  8. <button name="%(crm.action_lead_mass_mail)d" type="action" string="Email" />: 在头部添加一个按钮,点击后执行crm.action_lead_mass_mail动作,显示"Email"。

  9. <field name="company_id" invisible="1"/>: 设置字段company_id在Tree视图中不可见。

  10. <field name="user_company_ids" invisible="1"/>: 设置字段user_company_ids在Tree视图中不可见。

  11. <field name="date_deadline" invisible="1"/>: 设置字段date_deadline在Tree视图中不可见。

  12. ...(后续为一系列字段的定义,包括name、partner_id等等)

  13. <field name="stage_id" optional="show" decoration-bf="1"/>: 定义字段stage_id,并且在Tree视图中可选显示(optional="show"),decoration-bf表示在字段周围显示背景标志。

  14. <field name="active" invisible="1"/>: 设置字段active在Tree视图中不可见。

  15. <field name="probability" string="Probability (%)" optional="hide"/>: 定义字段probability,在Tree视图中可选隐藏,设置显示名称为"Probability (%)"。

  16. <field name="tag_ids" optional="hide" widget="many2many_tags" options="{'color_field': 'color'}"/>: 定义字段tag_ids,可选隐藏,使用many2many_tags小部件,根据color字段设置标签的颜色。

3、Tree视图中<field>标签的常用参数详解

  1. name: 字段的名称,指定在模型中的字段。

  2. string: 用于显示在Tree视图表头的字段标签的文本。

  3. invisible: 控制字段是否可见。可选值为"1"(不可见)或"0"(可见)。

  4. optional: 控制字段是否可选。可选值为"hide"(不可选)或"show"(可选)。

  5. widget: 指定在Tree视图中使用的小部件,影响字段的显示方式。例如,"many2one_avatar_user"。

  6. options: 提供一些小部件相关的选项,以字典形式表示。

  7. class: 添加额外的CSS类,用于自定义样式。

  8. sum: 在Tree视图底部显示字段的总和,通常用于数字字段。

  9. groups: 通过用户组控制字段的可见性,只有属于指定用户组的用户才能看到该字段。

  10. readonly: 控制字段是否为只读。可选值为"1"(只读)或"0"(可编辑)。

  11. decoration-bf: 在字段周围显示背景标志。可选值为"1"(显示)或"0"(不显示)

4、<tree>标签参数详解

1、string:设置Tree视图的标题,该标题将显示在页面顶部

<tree string="My Tree View">

 2、editable:指定Tree视图是否可编辑。

<tree editable="bottom">

create:指定是否显示“创建”按钮以创建新记录

<tree create="true">

delete:指定是否显示“删除”按钮以删除选定的记录

<tree delete="true">

default_order:设置Tree视图的默认排序规则

<tree default_order="date desc, name">

 decoration-muted:定义一个域列表,表示记录行是否显示为灰色

<tree decoration-muted="{'in_progress': [('state','=','draft')]}" string="My Tree View">

 decoration-danger:定义一个域列表,表示记录行是否显示为红色

<tree decoration-danger="{'overdue': [('date_deadline','&lt;',time.strftime('%Y-%m-%d'))]}" string="My Tree View">

 decoration-warning:定义一个域列表,表示记录行是否显示为黄色

<tree decoration-warning="{'warning': [('date_deadline','=',time.strftime('%Y-%m-%d'))]}" string="My Tree View">

3、Tree视图中的按钮

1、表头按钮

        通过在<tree>标签下的<header>标签内部定义按钮,将按钮显示在Tree视图的表头部分

<tree>
    <header>
        <button name="your_button_function" string="Your Button" type="object"/>
    </header>
    <!-- Fields and other configurations go here -->
</tree>

2、记录行按钮

 通过在<tree>标签下的<button>标签内部定义按钮,将按钮显示在每条记录行的最右侧

<tree>
    <!-- Fields and other configurations go here -->
    <button string="Your Action Button" type="object" name="your_button_function" class="oe_highlight"/>
</tree>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Dear.爬虫

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值