元素xpath不能位于父视图中 [英] Element xpath cannot be located in parent view

查看:77
本文介绍了元素xpath不能位于父视图中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要自定义字段以从销售模块融洽地打印,所以我创建了一个新模块并安装了它.我已经创建了一个XML文件,但是出现此错误:

I need to customize fields to print from rapport of sale module, so I created a new module and installed it. I have created an XML file, but have this error:

odoo.tools.convert.ParseError: "Error while validating constraint

Element '<xpath expr="//table[@class='table table-condensed']//thead//tr">' cannot be located in parent view

Error context:
View `report_quotation_inherit_demo`
[view_id: 1603, xml_id: n/a, model: n/a, parent_id: 649]
None" while parsing None:5, near
<data inherit_id="sale.report_saleorder_document">
        <!-- Finds the first table with as class table table-condensed and gives the ability to modify it
         This will replace everything withing tr (including tr)-->
        <xpath expr="//table[@class='table table-condensed']//thead//tr" position="replace">
                    <tr style="background-color:lightgray;">
                        <th>Description</th>
                        <th class="text-right">Price</th>
                    </tr>
        </xpath>
        <!-- This will search for the 4'th td element (in the tbody with class sale_tbody) and will remove it. -->
        <!-- Important: if you would start with element 2, then do 3 and then do 4 you will see strange behaviour.
            The first statement would remove element 2 making all other elements move in numbering too. -->
        <xpath expr="//tbody[@class='sale_tbody']//tr//td[4]" position="replace">
        </xpath>
        <xpath expr="//tbody[@class='sale_tbody']//tr//td[3]" position="replace">
        </xpath>
        <xpath expr="//tbody[@class='sale_tbody']//tr//td[2]" position="replace">
        </xpath>
        </data>

推荐答案

您尚未提供完整的视图定义,因此我不确定这是问题所在,但似乎您只需要更改自己的方式即可正在使用您的xpath表达式.

You haven't provided your full view definition so I can't be sure this is the issue, but it seems like you just need to change the way you are using your xpath expressions.

使用xpath时,expr应该以//开头(这是/sheet/的简写).任何其他元素都应由单个/分隔.

When using xpath, your expr should start with // (which is shorthand for /sheet/). Any additional elements should be separated by a single /.

# Instead of
# <xpath expr="//table[@class='table table-condensed']//thead//tr">
# Try using
 <xpath expr="//table[@class='table table-condensed']/thead/tr">

您将需要更新所有在元素之间使用//xpath表达式.

You will need to update all of your xpath expressions that have use the // between elements.

您可以参阅此文档以了解基本的例子.

You can see this documentation for a basic example.

可以在中找到一些更高级的示例Odoo源代码.

这篇关于元素xpath不能位于父视图中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆