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.

0

Weird error "Expression cannot be located in parent view" in view inheritance

By
Raffaele
on 7/7/16, 5:06 AM 443 views

In v9 I'm trying to add a smart button to the partner form. I copied the code from the sale module, at https://github.com/odoo/odoo/blob/9.0/addons/sale/res_partner_view.xml#L38

The original code is: 

<record id="res_partner_view_buttons" model="ir.ui.view">
<field name="name">res.partner.view.buttons</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="base.view_partner_form" />
<field name="priority" eval="20"/>
<field name="groups_id" eval="[(4, ref('base.group_sale_salesman'))]"/>
<field name="arch" type="xml">
<div name="button_box" position="inside">
<button class="oe_stat_button" type="action" name="%(sale.act_res_partner_2_sale_order)d"
attrs="{'invisible': [('customer', '=', False)]}"
icon="fa-usd">
<field string="Sales" name="sale_order_count" widget="statinfo"/>
</button>
</div>
</field>
</record>


I fitted it to suit my needs

<record id="res_partner_view_buttons" model="ir.ui.view">

<field name="name">res.partner.view.buttons</field>

<field name="model">res.partner</field>

<field name="inherit_id" ref="base.view_partner_form" />

<field name="priority" eval="20"/>

<field name="arch" type="xml">

  <div name="buttons" position="inside"

<button class="oe_inline oe_stat_button" type="action" string="Cycles"

name="medical_report_basic.act_res_partner_2_cycle"

icon="fa-repeat" help="Manage patient's cycles">

</button> 

</div>

</field>

</record>

The system keeps complaining that 

Element '<div name="buttons">' cannot be located in parent view

I changed it to 

<xpath expr="(//sheet/div)[last()]" position="before">

<div class="oe_right oe_button_box" name="cycle_buttons">

<button class="oe_inline oe_stat_button" type="action" string="Cycles"

name="medical_report_basic.act_res_partner_2_cycle"

icon="fa-repeat" help="Manage patient's cycles">

</button>

</div>

</xpath>

And it is working fine - but it is a weird solution.

Why is the sale module code not working for me?

1

Sudhir Arya (SA)

--Sudhir Arya (SA)--
10150
| 6 8 8
Ahmedabad, India
--Sudhir Arya (SA)--

Working as an OpenERP/Odoo developer and a Team Leader 

Top 5 Odoo contributor On Stackoverflow

LinkedIn

Blog

Stackoverflow

Sudhir Arya (SA)
On 7/7/16, 2:05 PM

Hello Raffaele,

The <div name="buttons" you are trying might not exists in parent view.

Better to try with following code:

<div name="button_box" position="inside">
...add your fields...
</div>

Actually, looking at the Fields View Get, the <div name="buttons"> does not exist at all. There is <div name="button_box"> instead

Thank you!

Raffaele
on 7/8/16, 9:59 AM

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

1 follower(s)

Stats

Asked: 7/7/16, 5:06 AM
Seen: 443 times
Last updated: 7/8/16, 9:58 AM