首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

添加按钮'action_open_quants‘到继承的'product.template’模型- Odoo v8

在Odoo v8中,要将按钮“action_open_quants”添加到继承的“product.template”模型,可以按照以下步骤进行操作:

  1. 创建一个自定义模块(如果还没有)。
  2. 在模块的目录结构中,打开或创建一个名为views.xml的文件。
  3. views.xml文件中,添加以下代码:
代码语言:txt
复制
<record model="ir.ui.view" id="view_product_template_inherit">
    <field name="name">product.template.inherit.view</field>
    <field name="model">product.template</field>
    <field name="inherit_id" ref="product.product_template_only_form_view"/>
    <field name="arch" type="xml">
        <xpath expr="//form" position="attributes">
            <attribute name="create">false</attribute>
        </xpath>
        <xpath expr="//form//sheet//notebook//page[@string='Inventory']" position="after">
            <page string="Quants">
                <field name="quants" widget="one2many_list" context="{'active_test': False}">
                    <tree editable="bottom">
                        <!-- Add your desired fields here -->
                    </tree>
                </field>
            </page>
        </xpath>
    </field>
</record>
  1. views.xml文件中,添加以下代码来定义按钮的行为:
代码语言:txt
复制
<record model="ir.actions.act_window" id="action_open_quants">
    <field name="name">Open Quants</field>
    <field name="res_model">stock.quant</field>
    <field name="view_mode">tree,form</field>
    <field name="view_type">form</field>
    <field name="domain">[('product_id', '=', active_id)]</field>
    <field name="context">{'search_default_product_id': active_id}</field>
    <field name="help" type="html">
        <p class="oe_view_nocontent_create">
            Click to view the quants for this product.
        </p>
    </field>
</record>
  1. views.xml文件中,添加以下代码来将按钮添加到模型中:
代码语言:txt
复制
<record model="ir.ui.view" id="view_product_template_inherit_form">
    <field name="name">product.template.inherit.form.view</field>
    <field name="model">product.template</field>
    <field name="inherit_id" ref="product.product_template_only_form_view"/>
    <field name="arch" type="xml">
        <xpath expr="//form//sheet//notebook//page[@string='Inventory']" position="after">
            <button name="%(action_open_quants)d" string="Open Quants" type="action"/>
        </xpath>
    </field>
</record>
  1. views.xml文件中,添加以下代码来将新的视图和按钮与模型关联起来:
代码语言:txt
复制
<record model="ir.ui.view" id="view_product_template_inherit_form">
    <field name="name">product.template.inherit.form.view</field>
    <field name="model">product.template</field>
    <field name="inherit_id" ref="product.product_template_only_form_view"/>
    <field name="arch" type="xml">
        <xpath expr="//form" position="attributes">
            <attribute name="create">false</attribute>
        </xpath>
        <xpath expr="//form//sheet//notebook//page[@string='Inventory']" position="after">
            <page string="Quants">
                <field name="quants" widget="one2many_list" context="{'active_test': False}">
                    <tree editable="bottom">
                        <!-- Add your desired fields here -->
                    </tree>
                </field>
            </page>
        </xpath>
        <xpath expr="//form//sheet//notebook//page[@string='Inventory']" position="after">
            <button name="%(action_open_quants)d" string="Open Quants" type="action"/>
        </xpath>
    </field>
</record>
  1. 保存并关闭views.xml文件。
  2. 在模块的目录结构中,打开或创建一个名为__openerp__.py的文件。
  3. __openerp__.py文件中,添加以下代码来声明视图和按钮的依赖关系:
代码语言:txt
复制
'data': [
    'views.xml',
],
  1. 保存并关闭__openerp__.py文件。
  2. 在Odoo中重新加载模块,以使更改生效。

现在,你应该能够在继承的“product.template”模型中看到一个名为“Open Quants”的按钮,并且点击该按钮将打开一个包含与该产品相关的quants的视图。

页面内容是否对你有帮助?
有帮助
没帮助

相关·内容

  • 领券