Inherit view and adding fields

让人想犯罪 __ 提交于 2019-12-12 04:23:10

问题


I want to add my 2 fields boatlenght and fuelcapacity under price list in product form view but they are not showing up. What did i miss.

    <?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, )

回答1:


Try

<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>

In order to insert the field properly you use an xpath expression to insert it on the DOM.

Check the documentation.



来源:https://stackoverflow.com/questions/42248731/inherit-view-and-adding-fields

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!