Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

1

How to make Xpath match multiple elements?

By
Jairo Llopis
on 5/29/14, 4:30 AM 3,032 views

From always, Xpath has matched all elements with a given query, and I had to add [1] at the end to match only the first match.

In OpenERP 7 I have this view definition:

<record id="view" model="ir.ui.view">
    <field name="name">mail.message.full_expand</field>
    <field name="model">mail.message</field>
    <field name="inherit_id" ref="mail.view_message_form"/>
    <field name="arch" type="xml">
        <xpath expr="//field" position="attributes">
            <attribute name="readonly">1</attribute>
        </xpath>
    </field>
</record>

Its purpose is to copy another view, but fully read-only. However it stops at the first match. Is there any way to make Xpath match every field?

0

Brett Lehrer

--Brett Lehrer--
1252
| 5 4 8
Milwaukee, United States
--Brett Lehrer--
Director of IT and open source enthusiast.
Brett Lehrer
On 4/16/15, 11:31 PM

You want to edit the root form tag directly to give it edit="false":

 <record id="view" model="ir.ui.view">
    <field name="name">mail.message.full_expand</field>
    <field name="model">mail.message</field>
    <field name="inherit_id" ref="mail.view_message_form"/>
    <field name="arch" type="xml">
        <xpath expr="/form" position="attributes">
            <attribute name="edit">false</attribute>
        </xpath>
    </field>
</record>

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

2 follower(s)

Stats

Asked: 5/29/14, 4:30 AM
Seen: 3032 times
Last updated: 4/16/15, 11:31 PM