Skip to Content
Menu
This question has been flagged
1 Reply
5606 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?

Avatar
Discard
Best Answer

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>

Avatar
Discard
Author

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!

Related Posts Replies Views Activity
1
Mar 20
1987
12
Dec 18
32518
1
Mar 15
6239
0
Mar 15
3027
1
Mar 15
2706