콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다

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. 

아바타
취소
베스트 답변

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

작성자

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

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

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

베스트 답변

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
아바타
취소
작성자 베스트 답변

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

작성자

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 i have updated the answer

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.

베스트 답변

can you please tell me what is  eval="'ir.actions.act_window,%d'%hr_employee_normal_action_tree2"  stand for

아바타
취소
관련 게시물 답글 화면 활동
1
5월 21
2773
0
12월 24
1440
2
9월 22
8646
Button Functions 해결 완료
2
1월 22
5105
4
3월 19
9849