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.

5

Call function from the "More" dropdown list

By
Eric
on 8/27/14, 7:28 PM 8,518 views

Hello.  I was wondering how can you run a function when you click on an option from the "More" menu dropdown in a Tree view.

For example:  When you are looking at all the records in a Tree view, then you click the check box for each record, then the "More" button appears at the top and if you select "Delete" then it calls the unlink method for that model and deletes the selected records.

I figured out how to add another item in the "More" dropdown, but I don't know how to run a function when the item is clicked.  All it does right now is open another form view, but I would like it to process some information before displaying it in another form. Here is an example of what I have

 

<record id="hr_employee_normal_action_tree2" model="ir.actions.act_window">
            <field name="name">Erics More Item</field>
            <field name="type">ir.actions.act_window</field>
            <field name="res_model">hr.employee</field>
            <field name="view_type">form</field>
            <field name="view_mode">tree,form</field>
        </record>

        <record model="ir.values" id="test_more_item">
            <field name="name">Test Item</field>
            <field name="model" eval="'sale.order'" />
            <field name="key" >action</field>
            <field name="key2">client_action_multi</field>
            <field name="value" eval="'ir.actions.act_window,%d'%hr_employee_normal_action_tree2" />
            <field name="object" eval="True" />
        </record>

 

So does anyone know how to run a function when the item from the "More" dropdown is selected?  I guess what I kind of need is the functionality which is similar to a button that is an object type.  So when a button is clicked then it runs a function on that model. 

13

Maniganda

--Maniganda--
1038
| 5 7 7
Bangalore, India
--Maniganda--
Maniganda
On 8/28/14, 12:38 AM

Hi Eric you can achieve this by addind few lines of code in your server action

<record id="sale_license_more_item_action" model="ir.actions.server">

             <field name="name">Erics More Item</field>

            <field name="model_id" ref="model_sale_licenses"/>
            <field name="state">code</field>
            <field name="code">action = self.renew_license(cr, uid, context.get('active_ids', []), context=context)</field>
        </record>
        
        <record id="test_more_item" model="ir.values">
            <field eval="'client_action_multi'" name="key2"/>
            <field eval="'sale.licenses'" name="model"/>
            <field name="name">Test Item</field>
            <field eval="'ir.actions.server,%d'%sale_license_more_item_action" name="value"/>
        </record>

 

Hello Maniganda. Thank you for your help. I did what you said, but it still isn't working for me. Let me show you what I have again and can you let me know if you see anything wrong with it. Thank you again Erics More Item ir.actions.act_window sale.licenses form form self.renew_license(cr, uid, context.get('active_ids', []), context=context) Test Item action client_action_multi

Eric
on 8/28/14, 1:24 PM

the last comment got cut off. I'll post my code as another answer so that you can see

Eric
on 8/28/14, 1:26 PM

i want to call function :'action_button_confirm' in dropdown list menu "More" ???? this is my code and it dosent work : Transformer en BL ir.actions.act_window sale.order form form self.action_button_confirm(cr, uid, context.get('active_ids', []), context=context) Test Item action client_action_multi

abdallah ghrir
on 10/27/14, 10:45 AM

Thanks @Maniganda: You saved my day!!! :)

dirtyHandsPHP
on 7/2/16, 1:33 PM
1
Eric
On 8/28/14, 1:29 PM

My new code:

<record id="sale_license_more_item_action" model="ir.actions.act_window">
            <field name="name">Erics More Item</field>
            <field name="type">ir.actions.act_window</field>
            <field name="res_model">sale.licenses</field>
            <field name="view_type">form</field>
            <field name="view_mode">form</field>
            <field name="code">self.renew_license(cr, uid, context.get('active_ids', []), context=context)</field>
        </record>

        <record model="ir.values" id="test_more_item">
            <field name="name">Test Item</field>
            <field name="model" eval="'sale.licenses'" />
            <field name="key" >action</field>
            <field name="key2">client_action_multi</field>
            <field name="value" eval="'ir.actions.act_window,%d'%sale_license_more_item_action" />
            <field name="object" eval="True" />
        </record>

 

I dont get any errors, but it still just goes to the form without running the code that was added.  Thank you again

Eric i have updated the answer you can check this

Maniganda
on 8/31/14, 11:04 PM

Thank you Maniganda for your help. Your solution works for me. Can you help me with one more thing? The function that is called is supposed to create a new sales order, which it does, but I would also like it to open the new sales order form when its finished. The end of my function returns a dictionary like this return { 'name': 'Sales Order', 'view_type': 'form', 'view_mode': 'form', 'view_id': self.pool.get('ir.ui.view').search(cr, uid, [('name','=','sale.order.form')])[0], 'res_model': 'sale.order', 'res_id': new_order_id, 'type': 'ir.actions.act_window', } This seems to work on other function calls, but for some reason it isn't working for this one.

Eric
on 9/2/14, 11:32 AM

Eric i have updated the answer

Maniganda
on 9/3/14, 1:59 AM
Hello Maniganda.  I appreciate your help.  I'm still having trouble with opening the new sale order in the form view once my function is done executing.  Do you have any other ideas?


On Tue, Sep 2, 2014 at 10:59 PM, Maniganda <k-maniganda-gmail-com@mail.odoo.com> wrote:

Eric i have updated the answer

--

Maniganda
Sent by OpenERP S.A. using Odoo about Forum Post False



--
Eric Bangerter | tel.: +1 (954) 585-9016 xYourExtension
Mertech Data Systems, Inc. | 114 East Shaw Avenue | Suite 209 | Fresno, CA 93710 | USA | Fax: +1 (866) 228-1213 | www.mertechdata.com
Building Bridges to New Technologies

CONFIDENTIALITY NOTICE
This email message from Mertech Data Systems, Inc. is intended only for the individual or entity to which it is addressed. This email may contain information that is privileged, confidential and exempt from disclosure under applicable law. This email may contain information which is shared in confidence with the recipient and must not be shared on any social media or posted on forums, blogs and websites without written consent from Mertech Data Systems, Inc. If you received this e-mail by accident, please notify the sender immediately and remove it from your system. You are hereby notified that unauthorized dissemination, distribution or copying of this communication is prohibited.

CONFIDENTIALITY NOTICE

This email message from Mertech Data Systems, Inc. is intended only for the individual or entity to which it is addressed. This email may contain information that is privileged, confidential and exempt from disclosure under applicable law. This email may contain information which is shared in confidence with the recipient and must not be shared on any social media or posted on forums, blogs and websites without written consent from Mertech Data Systems, Inc. If you received this e-mail by accident, please notify the sender immediately and remove it from your system. You are hereby notified that unauthorized dissemination, distribution or copying of this communication is prohibited.

Eric
on 9/4/14, 6:06 PM
0
Artem
On 9/17/16, 3:36 PM

working code

<record id="dditem1_action" model="ir.actions.server">
        <field name="name">Text to display as menu item</field>
        <field name="model_id" ref="model_your_model"/>
        <field name="state">code</field>
        <field name="condition">True</field>
        <field name="code">if object: self.browse(cr,uid,context.get('active_ids', [])).your_function()</field>
</record>
<record id="dditem1" model="ir.values">
        <field name="name">name</field>
        <field name="model">your.model</field>
        <field name="key" >action</field>
        <field name="key2">client_action_multi</field>
        <field name="value" eval="'ir.actions.server,%d'%dditem1_action"/>
</record>
@api.multi
def your_function(self):
     for item in self:
         # do something with selected records

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: 8/27/14, 7:28 PM
Seen: 8518 times
Last updated: 9/17/16, 3:36 PM