Odoo Help


Why can't I make a button in tree

on 3/22/13, 3:47 AM 3,637 views

I want to add a button ,and I rectify the code like this:

             <button name="order_confirm" states="draft" string="Confirm Order" icon="gtk-apply" confirm="Are u want to confirm order?"/>                
        <tree string="Sales Orders" colors="grey:state=='cancel';blue:state in ('waiting_date','manual');red:state in ('invoice_except','shipping_except')">
                <field colspan="4" name="name"/>
               <field name="date_order"/>
                <field name="partner_id"/>
                <field name="user_id"/>
                <field name="picked_rate" widget="progressbar"/>
                <field name="invoiced_rate" widget="progressbar"/>
                <field name="amount_untaxed" sum="Total Tax Excluded"/>
                <field name="amount_total" sum="Total Tax Included"/>
                <field name="state"/>

But it cant work ,I want to know what mistake i make... Thanks...

it woke like this : http://postimg.org/image/x3xmfw18j/

on 3/22/13, 3:48 AM
On 3/22/13, 8:45 AM

As previous answers said, this is not possible (that I'm aware of!). You can either put the button in the tree lines, but this will create a different button for every line of the tree or you can create a server action that can be triggered from the 'More' menu on the top using as argument the selected rows.

For doing the later, you do it like:

<record id="id_for_the_action" model="ir.actions.server">
    <field name="name">The Name of the Action</field>
    <field name="type">ir.actions.server</field>
    <field name="model_id" ref="model_your_model"/>
    <field name="state">code</field>
    <field name="code>self.function_to_run(cr, uid, context.get('active_ids'), context=context)</field>
<record id="id_of_the_action_value" model="ir.values">
    <field name="name">Name for action value</field>
    <field name="action_id" ref="id_for_the_action"/>
    <field name="value" eval="'ir.actions.server,' + str(ref('id_for_the_action'))"/>
    <field name="key">action</field>
    <field name="model_id" ref="model_your_model"/>
    <field name="model">your_model</field>
    <field name="key2">client_action_multi</field>

Be aware that when putting model_id you need to put model_your_model with the model_ part included and _ instead of .

Hope this suits you!

I write " <field name="model_id" ref="model_sale_order"/> <field name="code">action_button_confirm(context=context)</field>" like this,and it installed success. it also has a trigger in "More"... but there is a new error here: NameError: name 'action_button_confirm' is not defined... i do not know where should i defined it ..

on 3/24/13, 11:00 PM

Sorry, my bad, I forgot to put it the right way, you have to put 'self.function_to_run'. I updated my answer.

on 3/25/13, 8:31 AM
Andreas Brueckl
On 3/22/13, 4:39 AM

You should put the <button> tag within the <tree> tag.

yeah..i try it ...but it also failure...I want it in the top of the tree ..it just add a icon in the list, .it look like: http://postimg.org/image/pacx2hm0f/

on 3/22/13, 4:44 AM

You mean next to "Create" and "Delete"? I do not think that this is possible.

Andreas Brueckl
on 3/22/13, 5:07 AM

maybe not next to "Create" and "Delete",can be in anywhere, i just want that i can "confirm sale" with many quotations ...

on 3/22/13, 5:28 AM

Then you have to use a separate window_action or wizard to perform a certain action on several resources.

Andreas Brueckl
on 3/22/13, 6:53 AM
On 3/24/13, 11:10 PM

I write like this

<record id="action_sale_order_confirm_sales" model="ir.actions.server">
<field name="name">Confirm sale1</field>
<field name="type">ir.actions.server</field>
<field name="model_id" ref="model_sale_order"/>
<field name="state">code</field>
<field name="code">action_button_confirm(context=context)</field>


<record id="id_of_the_action_value" model="ir.values">
<field name="name">Confirm sale1</field>
<field name="action_id" ref="action_sale_order_confirm_sales"/>
<field name="value" eval="'ir.actions.server,' + str(ref('action_sale_order_confirm_sales'))"/>
<field name="key">action</field>
<field name="model_id" ref="model_sale_order"/>
<field name="model">sale.order</field>
<field name="key2">client_action_multi</field>


and "def action_button_confirm" is in sale.py/class sale_order....

but there is a new error here: NameError: name 'action_button_confirm' is not defined... and i do not know where should i defined it ...

i know the problem ...i should write like this : <field name="code">obj.action_button_confirm(context=context)</field>

on 3/24/13, 11:16 PM

Did not saw this before and changed my answer! :D

on 3/25/13, 8:33 AM

Anyway,thank you so much~:D

on 3/26/13, 2:13 AM

Hi CK, I am having the same issue can you please help with the python and xml codes that works correctly for you? Thank you

on 8/5/13, 2:21 PM

About This Community

This platform 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.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

0 follower(s)


Asked: 3/22/13, 3:47 AM
Seen: 3637 times
Last updated: 9/18/15, 5:40 AM