Odoo 10:从按钮打开 XML 视图

Odoo 10 : Open XML view from a button

由于我是新手,所以我进行了大量搜索以找到一个简单的示例,这是我正在研究的第一个模块。我找到的所有示例都有点难以理解或无法满足我的需求。

我有 3 个模型: 产品 包裹 Product_package(根据我的项目数据库概念,我需要将这个作为依赖 table)

我需要从产品视图创建一个 product_package。

我在 views/product.xml 页面试过:

<record model="ir.ui.view" id="product_form_view">
        <field name="name">product.form</field>
        <field name="model">tjara.product</field>
        <field name="arch" type="xml">
            <form string="Produit Form">
                <head>
                   <button name="%(product_package_list_action2)d" type='action' string='Ajouter Emballage'/>
                </head>
                <sheet>
                    <group>
                        <field name="name"/>
                        <field name="add_date"/>
                    </group>
                    <notebook>
                        <page string="Description">
                            <label for="description" string="Fiche du produit"/>
                            <field name="description"/>
                        </page>
                        <page string="Fournisseurs">
                            <label for="provider_ids"/>
                            <field name="provider_ids"/>
                        </page>
                        <page string="Clients">
                            <label for="client_ids"/>
                            <field name="client_ids"/>
                        </page>
                    </notebook>

                </sheet>
            </form>
        </field>
    </record>

并且在同一页中我添加了:

<record model="ir.actions.act_window" id="product_package_list_action2">
        <field name="name">Emballages</field>
        <field name="res_model">tjara.product_package</field>
        <field name="view_type">form</field>
        <field name="view_mode">tree,form</field>
        <field name="view_id" ref="product_package_form_view"/>
    </record>

有人有解决方案吗?

好的,我找到了解决方案。

这是产品 Xml 页面中的按钮:

                    <header>
                         <button name="%(product_package_list_action2)d" type='action' string='Ajouter Emballage'/>
                    </header>

在同一页中,我插入以下内容:

    <record model="ir.actions.act_window" id="product_package_list_action2">
        <field name="name">Emballages</field>
        <field name="res_model">tjara.product_package</field>
        <field name="view_type">form</field>
        <field name="view_mode">tree,form</field>
        <field name="view_id" ref="product_package_form_view"/>
    </record>

在 product_price Xml 页面中,我有以下代码:

    <record model="ir.ui.view" id="product_package_form_view">
        <field name="name">product_package.form</field>
        <field name="model">tjara.product_package</field>
        <field name="arch" type="xml">
            <form string="Emballage Form">
                <sheet>
                    <group>
                        <field name="product_id"/>
                        <field name="package_id"/>
                        <field name="price"/>
                    </group>
                    <notebook>
                        <page string="Description">
                            <field name="description"/>
                        </page>
                    </notebook>

                </sheet>
            </form>
        </field>
    </record>

在清单中,我在产品 Xml 之前加载了 product_package。这解决了我的问题,尽管我得到的是整页而不是弹出 window.