【问题标题】:Error Element xpath cannot be located in parent view错误元素 xpath 不能位于父视图中
【发布时间】:2019-01-17 15:06:26
【问题描述】:

请,我需要自定义字段以从 rapport of sale 模块打印,所以我创建了一个新模块并安装了它(odoo 12)。我创建了一个 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>

【问题讨论】:

标签: odoo


【解决方案1】:

您也可以像这样定义 xpath

 <xpath expr="//table//thead//tr[1]" position="replace">

因此,该模板中必须只有一个表,该表中只有一个 thead

如果有多个,您可以定义数字,如我给出的示例 tr[1]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-07-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-02
    相关资源
    最近更新 更多