Odoo 中文社区

    • 注册
    • 登录
    • 搜索
    • 版块
    • 标签
    • 热门
    • 用户
    • 群组

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

    由于系统升迁的原因,本论坛部分较早期的内容存在格式和链接损坏失效的问题,并非本论坛系统本身的缺陷,望谅解

    本社区没有维护任何QQ群讨论组,任何与本社区同名的QQ群讨论组的言论与本社区无关!

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

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

    关于<xpath position="attributes"> 的问题

    Odoo 开发与实施交流
    3
    6
    5341
    正在加载更多帖子
    • 从旧到新
    • 从新到旧
    • 最多赞同
    回复
    • 在新帖中回复
    登录后回复
    此主题已被删除。只有拥有主题管理权限的用户可以查看。
    • W
      winson97 最后由 编辑

      本人遇到一个问题,代码如下:


      <record id="sale_view_order_form" model="ir.ui.view">
                  <field name="name">sale.order.form</field>
      <field name="model">sale.order</field>
                  <field name="inherit_id" ref="sale.view_order_form"/>
      <field name="arch" type="xml">
          <field name="partner_id" position="after">
            <field name="boatmodel_id" />
          </field>
          <xpath expr="//field[@name='product_id']"  position="attributes">
            <attribute name="context">{'boatmodel_id' : parent.boatmodel_id}</attribute>
          </xpath>
      </field>
      </record>


      问题:跟踪product.product 的search 发现{'boatmodel_id' : parent.boatmodel_id}  没有传给 context
      不知何故?

      context 为:  dict: {u'lang': u'en_US', u'shop': 1, u'tz': u'Asia/Hong_Kong', u'uid': 1, u'pricelist': 1, u'partner_id': 5, u'uom': 1, u'quantity': 1}


      sale.view_order_form 其中代码为:

          <field name="product_id" context="{'partner_id':parent.partner_id, 'quantity':product_uom_qty, 'pricelist':parent.pricelist_id, 'shop':parent.shop_id, 'uom':product_uom}" groups="base.group_user" on_change="product_id_change(parent.pricelist_id, product_id, product_uom_qty, product_uom, product_uos_qty, product_uos, name, parent.partner_id, False, True, parent.date_order, False, parent.fiscal_position, False, context)"/>

      1 条回复 最后回复 回复 引用 0
      • W
        wangbuke 最后由 编辑

        先给一段代码,慢慢体会下。

                <record id="sale_view_order_form" model="ir.ui.view">
                    <field name="name">sale.order.form</field>
                    <field name="model">sale.order</field>
                    <field name="inherit_id" ref="sale_stock.view_order_form_inherit"/>
                    <field name="arch" type="xml">
                        <data>
                            <field name="partner_id" position="after">
                                <field name="boatmodel_id" />
                            </field>
                            <xpath expr="//field[@name='product_id']"  position="attributes">
                                <attribute name="context">{'xxxx':'xxxx', 'partner_id':parent.partner_id, 'quantity':product_uom_qty, 'pricelist':parent.pricelist_id, 'shop':parent.shop_id, 'uom':product_uom}</attribute>
                            </xpath>
                        </data>
                    </field>
                </record> 


        1 条回复 最后回复 回复 引用 0
        • W
          wangbuke 最后由 编辑

          几点说明:

          1、inherit_id 不是 sale.view_order_form,而是 sale_stock.view_order_form_inherit。这是因为sale.view_order_form的 product_id field 被 sale_stock.view_order_form_inherit replace 替换了。

          因此,[color=red]必须继承替换的VIEW ID[/color]。

          2、<data> 标签,表示多个更改,虽然有时不用 data 也可以用,但严重建议遵循官方规范 [检测到链接无效,已移除] br />
          3、<attribute name="context"> 此处值为替换,因此需要把原来的 context 值写上。 如 {'xxxx':'xxxx', 'partner_id':parent.partner_id, 'quantity':product_uom_qty, 'pricelist':parent.pricelist_id, 'shop':parent.shop_id, 'uom':product_uom}



          另外,需要提醒的是:我在测试中发现 [color=red]xpath  只匹配第一个符合的node[/color]  (存疑,待后续求证)

          <xpath expr="//field[@name='product_id']"  position="attributes">

          因此这样只替换了 sale.order.line form view 的 product_id field ,如需替换 sale.order.line tree view 则需另外加一段,如:

                              <xpath expr="//tree/field[@name='product_id']"  position="replace">
                                      。。。。。。
                              </xpath>


          谢谢 !

          1 条回复 最后回复 回复 引用 0
          • W
            winson97 最后由 编辑

            感谢,感谢!

            昨晚也搜索到了 sale_stock.view_order_form_inherit ,试了一下,未果就放弃了。

            大师一出手,说得明明白白,一片 雨过天清 豁然开朗 感觉,苦想两天的问题终于明白了。

            buke,Thanks!


            [attachimg=1]

            附上 sale_stock.view_order_form_inherit 部份代码:

                  sale_stock_view.xml

                    <record[color=red] id="view_order_form_inherit"[/color] model="ir.ui.view">
                        [color=blue]<field name="name">sale.order.form.sale.stock</field>[/color]
                        <field name="model">sale.order</field>
                        <field name="inherit_id" ref="sale.view_order_form"/>
                        <field name="arch" type="xml">
                            <data>
                              ......
                              <field name="product_id" position="replace">
                                  <field name="product_id"
                                  context="{'partner_id':parent.partner_id, 'quantity':product_uom_qty, 'pricelist':parent.pricelist_id, 'shop':parent.shop_id, 'uom':product_uom}"
                                  groups="base.group_user"
                                  on_change="product_id_change(parent.pricelist_id,product_id,product_uom_qty,product_uom,product_uos_qty,product_uos,name,parent.partner_id, False, True, parent.date_order, product_packaging, parent.fiscal_position, False, context)"/>
                              </field>

            1 条回复 最后回复 回复 引用 0
            • mrshelly
              mrshelly 最后由 编辑

              嗯. xpath 一定要写得唯一才可以.
              xpath 如果不能唯一, 那肯定只对第一个匹配项进行 replace

              另: OpenERP context 传丢已经见惯不惊了.... context 传递的坑粉多....

              1 条回复 最后回复 回复 引用 0
              • First post
                Last post