Odoo 使用 xpath 在树视图标题处添加按钮

问题描述 投票:0回答:1

我是一名初级 odoo 开发人员 (v14)。

我正在尝试在树视图的标题处添加一个按钮,位于“创建”按钮旁边。

我必须从继承模板添加按钮,所以我认为我必须使用 xpath。

继承的模板已经创建,我只需添加模型中定义的按钮,这是我最好的方法:

    <record id="view_stock_inventory_tree" model="ir.ui.view">
        <field name="name">stock.inventory.tree.view</field>
        <field name="model">stock.inventory</field>
        <field name="inherit_id" ref="stock.view_inventory_tree"/>
        <field name="arch" type="xml">
            <xpath expr="//tree" position="inside">
                <header>
                    <button name="create_button" type="object" class="oe_highlight" string="Custom Button"/>
                </header>
            </xpath>
            <field name="state" position="after">
                <field name="closure_id"/>
                <field name="cost_currency_id" invisible="1"/>
                <field name="valuation" widget='monetary' options="{'currency_field': 'cost_currency_id'}"/>
            </field>
        </field>
    </record>

但是,这不会在视图中显示按钮,但至少不会生成错误。

在模板片段中,如果我删除

header
标签,那么我可以查看表/树右侧每个记录中的按钮,它会执行我所期望的操作,但我需要找到旁边的按钮“创建”按钮。

考虑到我必须从继承的模板中执行此操作,如何找到“创建”按钮旁边的按钮?

xml odoo odoo-14
1个回答
0
投票

查看这篇关于在树视图标题中的“创建”按钮旁边放置按钮的博客文章。

https://www.cybrosys.com/blog/how-to-add-a-new-button-near-the-create-button-in-odoo-14

© www.soinside.com 2019 - 2024. All rights reserved.