This question has been flagged
3 Replies
6164 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"/>
            </tree>

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

Avatar
Discard
Author

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

Best Answer

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>
<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>
</record>

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!

Avatar
Discard
Author

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

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

Best Answer

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

Avatar
Discard
Author

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/

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

Author

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

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

Author Best Answer

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>

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

</record>

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

Avatar
Discard
Author

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

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

Author

Anyway,thank you so much~:D

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