Programmer LiLi
Programmer LiLi

Reputation: 157

Element xpath cannot be located in parent view

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>

Upvotes: 2

Views: 6548

Answers (1)

Travis Waelbroeck
Travis Waelbroeck

Reputation: 2135

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.

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">

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.

Some more advanced examples can be found in the Odoo source code.

Upvotes: 1

Related Questions