【问题标题】:Inherit view and adding fields继承视图并添加字段
【发布时间】:2017-02-15 11:56:36
【问题描述】:

我想在产品表单视图的价目表下添加我的 2 个字段boatlenght 和fuelcapacity,但它们没有显示出来。我错过了什么。

    <?xml version="1.0" encoding="utf-8"?>

    <openerp>
        <data>
            <!-- Inherit Form View to Modify it -->
            <record id="product_product_template_only_form_view" model="ir.ui.view">
                <field name="model">product.product</field>
                <field name="inherit_id" ref="product.product_template_only_form_view"/>
                <field name="arch" type="xml">
                    <field name="list_price" position="after">
                       <field name="boatlenght"/>
                       <field name="fuelcapacity"/>
                </field>
                </field>
            </record>


        </data>
    </openerp>

  from openerp import models, fields, api

  class ProductProduct(models.Model):
    _inherit = 'product.product'

    boatlenght = fields.Char(string="Lenght of the Boat", required=False, )
    fuelcapacity = fields.Char(string="Fuel Capacity", required=False, )

【问题讨论】:

    标签: python xml openerp


    【解决方案1】:

    试试

    <record id="product_product_template_only_form_view" model="ir.ui.view">
                    <field name="model">product.product</field>
                    <field name="inherit_id" ref="product.product_template_only_form_view"/>
                    <field name="arch" type="xml">
                        <xpath expr="//field[@name='list_price']" position="after">
                           <field name="boatlenght"/>
                           <field name="fuelcapacity"/>
                        </xpath>
                    </field>
                </record>
    

    为了正确地 insert 字段,您使用 xpath 表达式将其插入 DOM。

    检查文档。

    【讨论】:

    • 您是否收到错误消息?您是否在 __openerp__.py 文件中插入了这个 xml 文件
    • 是的,它在 openerp.py 中。不,如果我找到我的应用程序并转到技术数据,实际上没有错误,上面写着“创建的视图 * 继承 product.product form (form)”所以我在这里有点困惑。