元素xpath不能位于父视图中

时间:2019-01-16 17:21:23

标签: python-3.x odoo

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

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>

1 个答案:

答案 0 :(得分:1)

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

使用xpath时,您的expr应该以{{1​​}}开头(是//的简写)。任何其他元素都应以单个/sheet/分隔。

/

您将需要更新所有在元素之间使用# Instead of # <xpath expr="//table[@class='table table-condensed']//thead//tr"> # Try using <xpath expr="//table[@class='table table-condensed']/thead/tr"> 的{​​{1}}表达式。

您可以see this documentation作为基本示例。

可以找到更多更高级的示例in the Odoo source code