微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何为 Odoo 智能按钮设置序列?

如何解决如何为 Odoo 智能按钮设置序列?

我要在产品的 button_Box div 中添加一个新按钮。为此,我编写了以下代码

<record id="product_template_form_view" model="ir.ui.view">
    <field name="name">product.template.common.form</field>
    <field name="model">product.template</field>
    <field name="inherit_id" ref="product.product_template_form_view"/>
    <field name="arch" type="xml">
        <div name="button_Box" position="inside">
            <button class="oe_stat_button" type="object" name="open_maintenance_equipments" groups="maintenance.group_equipment_manager" icon="fa-Wrench">
                <field string="Maintenance Equipments" name="maintenance_equipment_count" widget="statinfo"/>
            </button>
        </div>
    </field>
</record>

它工作正常,但按钮出现在左侧,在销售、购买等 odoo 主要按钮之前。我将代码更改为:

<record id="product_template_form_view" model="ir.ui.view">
    <field name="name">product.template.common.form</field>
    <field name="model">product.template</field>
    <field name="inherit_id" ref="product.product_template_form_view"/>
    <field name="arch" type="xml">
        <xpath expr="//div[@name='button_Box']/button[last()]" position="after">
            <button class="oe_stat_button" type="object" name="open_maintenance_equipments" groups="maintenance.group_equipment_manager" icon="fa-Wrench">
                <field string="Maintenance Equipments" name="maintenance_equipment_count" widget="statinfo"/>
            </button>
        </xpath>
    </field>
</record>

但这里的问题是在源视图 product.product_template_form_view 中,div 中仍然没有按钮。因此,要应用这一点,我应该从修改此产品视图的主要视图之一(例如由 salepurchase 等应用程序引入的视图)继承。但我不想这样做,因为:

  1. 我的模块应该依赖于与我的模块无关的应用程序。安装模块时,我无法自动安装例如 purchase
  2. 尽管这样做,但不能保证我的按钮在这些“主要”按钮之后,因为这取决于模块安装顺序。

那么,你知道实现我的目的的方法吗,比如 sequence 字段或类似的东西?

解决方法

模型 ir.ui.view 上有一个序列字段,可用于您的要求。因此,请尝试继承其中一个基本视图,但也要设置高优先级,这意味着该新视图的顺序很高。

<record id="product_template_form_view" model="ir.ui.view">
    <field name="name">product.template.common.form</field>
    <field name="model">product.template</field>
    <field name="inherit_id" ref="product.product_template_form_view"/>
    <field name="priority" eval="100" />
    <field name="arch" type="xml">
        <div name="button_box" position="inside">
            <button class="oe_stat_button" type="object" name="open_maintenance_equipments" groups="maintenance.group_equipment_manager" icon="fa-wrench">
                <field string="Maintenance Equipments" name="maintenance_equipment_count" widget="statinfo"/>
            </button>
        </div>
    </field>
</record>

您当然可以使用除 100 以外的其他值,但这似乎是一个神奇的边界值,因为 Odoo 中没有使用如此高的序列。

如果您希望客户获得与 Odoo Studio 的更多兼容性,请记住,Studio 视图始终获得 99 (IIRC) 的序列值。

,

采购和库存模块继承 product.product_template_only_form_view 视图,销售模块继承 product.product_normal_form_view,并且您正在继承父视图,在应用当前视图的继承规范之前,父视图将始终完全解析:

如果视图有父视图,则父视图完全解析,然后应用当前视图的继承规范

有关详细信息,请查看 view resolution 文档

如果您继承了上述视图之一,则该按钮将自动添加到右侧,具体取决于视图的优先级,正如@CZoellner 已经提到的

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。