如何使用Odoo 10 Xpath查找特定路径

时间:2016-11-04 09:54:26

标签: xpath openerp odoo-9

    <group>
        <field name="tax_id" widget="many2many_tags" domain="[('type_tax_use','=','sale'),('company_id','=',parent.company_id)]"
            attrs="{'readonly': [('qty_invoiced', '&gt;', 0)]}"/>
        <label for="customer_lead"/>
        <div>
            <field name="customer_lead" class="oe_inline"/> days
        </div>
        <label for="analytic_tag_ids"/>
        <div>
            <field name="analytic_tag_ids" widget="many2many_tags"/>
        </div>
    </group>
</group>
############WANT TO INSERT HERE
<label for="name"/>
<field name="name"/>
<div groups="base.group_no_one">
    <label for="invoice_lines"/>
    <field name="invoice_lines"/>
</div>
<field name="state" invisible="1"/>

这是sale_view.xml

我试过了

xpath expr="//label[@for='name'//field name='name']" position='before'

并尝试了各种其他路径和完整路径

/odoo/record[7]/field[3]/form/sheet/notebook/page[1]/field[1]/form/group

/odoo/record[7]//form[2]/group

我不明白为什么它找不到这条路径,为什么不接受字符串作为选择器。

修改

<record id="view_order_form" model="ir.ui.view">
    <field name="model">sale.order</field>
    <field name="inherit_id" ref="sale.view_order_form"/>
    <field name="arch" type="xml">
      <xpath expr="//form//form//label[@for='name']" position="before">
        <div groups="base,group_no_one">
          <label for="l_ids"/>
          <field name="l_ids"/>
        </div>
      </xpath>
      <field name="partner_id" position="after">
        <button name="abc" string="abc" type="object"
                class="oe_inline fa fa-arrow-right oe_link"/>
      </field>
    </field>
  </record>

这是错误:

Error context:
View `sale.order form`
[view_id: 687, xml_id: promo.view_order_form, model: sale.order, parent_id: 508]
2016-11-07 06:43:03,556 22642 CRITICAL odoo10 odoo.service.server: Failed to initialize database `odoo10`.
Traceback (most recent call last):
  File "/home/maharshi/workspace/odoo-10.0/odoo/service/server.py", line 898, in preload_registries
    registry = Registry.new(dbname, update_module=update_module)
  File "/home/maharshi/workspace/odoo-10.0/odoo/modules/registry.py", line 78, in new
    odoo.modules.load_modules(registry._db, force_demo, status, update_module)
  File "/home/maharshi/workspace/odoo-10.0/odoo/modules/loading.py", line 333, in load_modules
    force, status, report, loaded_modules, update_module)
  File "/home/maharshi/workspace/odoo-10.0/odoo/modules/loading.py", line 235, in load_marked_modules
    loaded, processed = load_module_graph(cr, graph, progressdict, report=report, skip_modules=loaded_modules, perform_checks=perform_checks)
  File "/home/maharshi/workspace/odoo-10.0/odoo/modules/loading.py", line 177, in load_module_graph
    env['ir.ui.view']._validate_module_views(module_name)
  File "/home/maharshi/workspace/odoo-10.0/odoo/addons/base/ir/ir_ui_view.py", line 1171, in _validate_module_views
    self.raise_view_error("Can't validate view:\n%s" % (e.message or repr(e)), vid)
  File "/home/maharshi/workspace/odoo-10.0/odoo/addons/base/ir/ir_ui_view.py", line 445, in raise_view_error
    raise ValueError(message)
ValueError: Can't validate view:
External ID must be fully qualified

Error context:
View `sale.order form`

这是我尝试使用的大多数路径的问题。

1 个答案:

答案 0 :(得分:3)

应该是:

<label for="name" position="before">
    <!-- your xml here -->
</label>

<xpath expr="//form//form//label[@for='name']" position="before">
    <!-- your xml here -->
</xpath>

修改

您的record应该是这样的:

<record id="view_order_form" model="ir.ui.view">
    <field name="name">my.sale.order.form</field>
    <field name="model">sale.order</field>
    <field name="inherit_id" ref="sale.view_order_form" />
    <field name="arch" type="xml">
        <!-- one of the above here -->
    </field>
</record