Odoo中文社区可以通过以下三个域名访问:shine-it.net , odoocn.org,odoo.net.cn

原论坛用户的基本信息和发帖这里都予以保留,请注意:原论坛用户无需重新注册新用户,但是您的密码需要重置

开发人员可以登录gitter讨论组: http://gitter.im/odoo-china/Talk, 需要github账号

如果您登录系统碰到问题,请在微信公众号留言:

如何在继承的视图中有重复的field name的字段后添加新字段的方法



  • 该问题是校长在给我们公司财务经理写的一个模块中出现的,目的是在供应商的“销售&采购“Tab页下面的供应商后面添加一字段,显示该供应商可供产品的类型。

    下面是校长的代码:
    partner.py

    <br /># coding: utf-8<br />from osv import orm, fields<br /><br />class Partner(orm.Model):<br />&nbsp; &nbsp; _inherit = &#039;res.partner&#039;<br /><br />&nbsp; &nbsp; _columns = {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#039;product_categ_id&#039;: fields.many2one(&#039;product.category&#039;,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; u&#039;供货类型&#039;),<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br /><br />
    


    partner_view.xml:

    <br />&lt;openerp&gt;<br />&nbsp; &nbsp; &lt;data&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &lt;record id=&quot;res_partner_view_supplier_product_categ&quot; model=&quot;ir.ui.view&quot;&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;field name=&quot;name&quot;&gt;res.partner.view.supplier.product_categ&lt;/field&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;field name=&quot;model&quot;&gt;res.partner&lt;/field&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;field name=&quot;inherit_id&quot; ref=&quot;base.view_partner_form&quot; /&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;field name=&quot;priority&quot; eval=&quot;20&quot;/&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;field name=&quot;arch&quot; type=&quot;xml&quot;&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;xpath expr=&quot;//field[@name=&#039;supplier&#039;]&quot; position=&quot;after&quot;&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;field name=&quot;product_categ_id&quot;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; attrs=&quot;{&#039;invisible&#039;: [(&#039;supplier&#039;, &#039;=&#039;, False)]}&quot;/&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;/xpath&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;/field&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &lt;/record&gt;<br />&nbsp; &nbsp; &nbsp; &lt;/data&gt;<br />&lt;/openerp&gt;<br />
    



    问题来了,页面并没有如预期中的那样在‘供应商’后显示‘供货类型’。
    我之前喜欢采用<field name="xxx" position='after'>的方式定位字段,自己尝试一下同样行不通。后来我把字段放在了“customer"后面,却能够正常的显示。。。

    找res.partner模块的源码,发现问题:
    res_partner_view.xml

    <br /> &lt;form string=&quot;Contact&quot; version=&quot;7.0&quot;&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;sheet&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;field name=&quot;image&quot; widget=&#039;image&#039; class=&quot;oe_avatar oe_left&quot; options=&#039;{&quot;preview_image&quot;: &quot;image_medium&quot;}&#039;/&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;div class=&quot;oe_title&quot;&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;label for=&quot;name&quot; class=&quot;oe_edit_only&quot;/&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;h1&gt;&lt;field name=&quot;name&quot; style=&quot;width: 70%%&quot;/&gt;&lt;/h1&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;field name=&quot;category_id&quot; widget=&quot;many2many_tags&quot; placeholder=&quot;Tags...&quot; style=&quot;width: 70%%&quot;/&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;/div&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;group&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;field name=&quot;function&quot; placeholder=&quot;e.g. Sales Director&quot;/&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;field name=&quot;email&quot;/&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;field name=&quot;phone&quot;/&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;field name=&quot;mobile&quot;/&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;/group&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;div&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;field name=&quot;use_parent_address&quot;/&gt;&lt;label for=&quot;use_parent_address&quot;/&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;/div&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;group&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;label for=&quot;type&quot;/&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;div name=&quot;div_type&quot;&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;field class=&quot;oe_inline&quot; name=&quot;type&quot;/&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;/div&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;label for=&quot;street&quot; string=&quot;Address&quot; attrs=&quot;{&#039;invisible&#039;: [(&#039;use_parent_address&#039;,&#039;=&#039;, True)]}&quot;/&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;div attrs=&quot;{&#039;invisible&#039;: [(&#039;use_parent_address&#039;,&#039;=&#039;, True)]}&quot; name=&quot;div_address&quot;&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;field name=&quot;street&quot; placeholder=&quot;Street...&quot;/&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;field name=&quot;street2&quot;/&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;div class=&quot;address_format&quot;&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;field name=&quot;city&quot; placeholder=&quot;City&quot; style=&quot;width: 40%%&quot;/&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;field name=&quot;state_id&quot; class=&quot;oe_no_button&quot; placeholder=&quot;State&quot; style=&quot;width: 37%%&quot; options=&#039;{&quot;no_open&quot;: True}&#039; on_change=&quot;onchange_state(state_id)&quot;/&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;field name=&quot;zip&quot; placeholder=&quot;ZIP&quot; style=&quot;width: 20%%&quot;/&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;/div&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;field name=&quot;country_id&quot; placeholder=&quot;Country&quot; class=&quot;oe_no_button&quot; options=&#039;{&quot;no_open&quot;: True}&#039;/&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;/div&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;/group&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;field name=&quot;supplier&quot; invisible=&quot;True&quot;/&gt;&lt;-------------------------看这里<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;/sheet&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;/form&gt;<br />.......<br /> &lt;page string=&quot;Internal Notes&quot;&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;field name=&quot;comment&quot; placeholder=&quot;Put an internal note...&quot;/&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;/page&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;page string=&quot;Sales &amp;amp; Purchases&quot;&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;group&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;group&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;field name=&quot;user_id&quot;/&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;field name=&quot;company_id&quot; groups=&quot;base.group_multi_company&quot; widget=&quot;selection&quot;/&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;/group&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;group&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;field name=&quot;customer&quot;/&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;field name=&quot;supplier&quot;/&gt;&lt;-----------------------------------再看这里<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;/group&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;group&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;field name=&quot;ref&quot;/&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;field name=&quot;lang&quot;/&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;field name=&quot;date&quot;/&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;/group&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;group&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;field name=&quot;active&quot;/&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;/group&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;/group&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;/page&gt;<br />
    


    发现在res_partner_view.xml文件中居然存在两个相同name的field,看来这就为什么字段不显示的原因了,个人猜想xpath
    <xpath expr="//field[@name='supplier']" position="after">方式的定位只会定位第一个字段,
    修改代码如下:

    <br />&lt;openerp&gt;<br />&nbsp; &nbsp; &lt;data&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &lt;record id=&quot;res_partner_view_supplier_product_categ&quot; model=&quot;ir.ui.view&quot;&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;field name=&quot;name&quot;&gt;res.partner.view.supplier.product_categ&lt;/field&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;field name=&quot;model&quot;&gt;res.partner&lt;/field&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;field name=&quot;inherit_id&quot; ref=&quot;base.view_partner_form&quot; /&gt;<br />			&lt;field name=&quot;priority&quot; eval=&quot;40&quot;/&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;field name=&quot;arch&quot; type=&quot;xml&quot;&gt;<br />				&lt;xpath expr=&quot;/form/sheet/notebook/page[@string=&#039;Sales &amp;amp; Purchases&#039;]/group/group/field[@name=&#039;supplier&#039;]&quot; position=&quot;after&quot;&gt;<br />				&nbsp; &lt;field name=&quot;product_categ_id&quot; attrs=&quot;{&#039;invisible&#039;: [(&#039;supplier&#039;, &#039;=&#039;, False)]}&quot;/&gt;<br />				&lt;/xpath&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;/field&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &lt;/record&gt;<br />&nbsp; &nbsp; &nbsp; &lt;/data&gt;<br />&lt;/openerp&gt;<br />
    



    刷新页面,成功。
    看来在用xpath定位字段的时候,最好还是把路径写全比较稳妥。


  • 管理员

    @KevinKong
    这文章写的干净漂亮,多谢帮我修了bug。 🙂

    这个invisible 的 supplier不知道是哪个模块加上去的。一个对象上的同样字段不应该在视图里出现两次的。





  • ;D校长过奖了,还得多谢校长指点啦

    我还有个问题想咨询一下,xpath 和 name 定位的方式有什么区别?哪个比较好呢?



  • name 一般能唯一定位的话,用name就可以了,xpath则可以精确定位,依据DOM规则


  • 管理员

    你其实已经发现了。
    用字段名定位的方法,对某种情况下是无法处理的。必须用xpath
    比如,要定位销售订单行上的name字段,用字段名定位就做不到了。
    因为销售订单(sale.order)上有name字段,在order的视图里同样有订单行(sale.order.line)的name字段, 这就必须用xpath来定位了。
    另外,xpath提供灵活定位方式可以通过相对路径定位到xml的任何一个节点,比如search view里的filter元素等等
    象上面的例子也可以用下面这些方法定位:

    &lt;xpath expr=&quot;//field[@name=&#039;customer&#039;]/field[@name=&#039;supplier&#039;]&quot; position=&quot;after&quot;&gt;
    


  • learned a lot  & thanks a lot.



  • 报告校长,代码

    &lt;xpath expr=&quot;//field[@name=&#039;customer&#039;]/field[@name=&#039;supplier&#039;]&quot; position=&quot;after&quot;&gt;
    


    还是行不通 :-\,好像customer跟supplier是并列的。

    我试了一下,这样是可以的:

    <br />xpath expr=&quot;//page[@string=&#039;Sales &amp;amp; Purchases&#039;]/group/group/field[@name=&#039;supplier&#039;]&quot; position=&quot;after&quot;&gt;<br />
    

  • 管理员

    不好意思,试试下面的:


    &lt;xpath expr=&quot;//field[@name=&#039;customer&#039;]/../field[@name=&#039;supplier&#039;]&quot; position=&quot;after&quot;&gt;
    


  • 试了,好用 😉



  • 高手论剑~~~~~~~~~~~~~~~~~~~~~~~~

    我来收门票~!!!



  • [quote author=digitalsatori link=topic=16281.msg27626#msg27626 date=1394788274]
    不好意思,试试下面的:


    &lt;xpath expr=&quot;//field[@name=&#039;customer&#039;]/../field[@name=&#039;supplier&#039;]&quot; position=&quot;after&quot;&gt;
    


    [/quote]

    求教一下吃个快餐,  这里的两个点 ..  怎么理解?



  • [quote author=ccdos link=topic=16281.msg27632#msg27632 date=1394885702]
    [quote author=digitalsatori link=topic=16281.msg27626#msg27626 date=1394788274]
    不好意思,试试下面的:


    &lt;xpath expr=&quot;//field[@name=&#039;customer&#039;]/../field[@name=&#039;supplier&#039;]&quot; position=&quot;after&quot;&gt;
    


    [/quote]

    求教一下吃个快餐,  这里的两个点 ..  怎么理解?
    [/quote]

    个人感觉应该跟linux中的cd ..差不多意思,先找到customer的父节点,然后在该父节点下找supplier。



  • 明知道是两个,可以直接找第二个(或者叫最后一个的)

    http://shine-it.net/index.php?topic=14508.0



  • [quote author=Jeff link=topic=16281.msg27647#msg27647 date=1395063648]
    明知道是两个,可以直接找第二个(或者叫最后一个的)
    <br / http://shine-it.net/index.php?topic=14508.0 br />[/quote]

    谢谢Jeff大神分享,有学了一招。