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.

0

Enable and disable menu, is it possible?

By
Andrea Dalseno
on 5/7/14, 8:32 AM 2,387 views

Hi, in my custom module I've overridden the unlink method to perform a write instead so to update the value in a field (let's call it 'deleted' filed) to true. It works fine, but now I'd like to hide the delete action/menu (in other menu list at the top of the form/view) and show an undelete one (which updates the record setting deleted to false) based upon the value of the deleted field (true or false). How can I do it? The same when I'm in tree view; in the case the user selects both deleted and not deleted records both the menu should be hidden or disabled, but if he selects only one type of record (all deleted or all not deleted) the right menu (delete or undelete) should be available.

It was pretty easy to do it in a from, using the attrs directive based on the field value to show/hide my undelete button (that woks), but I can't figure out how to do it in a view. Moreover I'm not able to put my button in the header, nor under the more button list nor alone, cause I always get an xml error, and I cannot understand why (if i put the button in the header section the xml fails!). To conclude how can I disable the delete button in the more button list based on my field value? It should be possible, isn't it?

Andrea Dalseno
on 5/7/14, 1:23 PM
0

Ahmed M.Elmubarak

--Ahmed M.Elmubarak--
2988
| 5 3 5
Sudan
--Ahmed M.Elmubarak--


Ahmed M.Elmubarak
On 5/9/14, 7:24 AM

Hello,

Lets break down you question to:

  • add undelete action to More menu and linking it to the function
  • add your undelete button to the header of the form
  • hide delete on More menu

for now I'll go for the first one...

You can add an item to the More menu by using ir_set tag or ir.values model since the second one is the famous let us try it.

if you want the function to be invoked directly when the user press the undelete label "I mean without a pop up verification window like "are you sure ....." " then we have to link it with a server action.

a server action can be defined in xml like:

<record id="action_server_name" model="ir.actions.server">
        <field name="type">ir.actions.server</field>
        <field name="condition">True</field>
        <field name="state">code</field>
        <field name="model_id" ref="model_name_name"/>
        <field eval="5" name="sequence"/>
        <field name="code">self.method_name(cr, uid, context)</field>
       <field name="name">Your Name</field>
    </record>

the ref="model_name_name" is your model_id reference So if your model is test_model you have to make it like model_test_model

the self.method_name it'll by your function to be invoked in your case it'll by self.unlink(params ....)

then we have to link this action with the ir.values and it could like:

<record model="ir.values" id="action_your_action_id" >
        <field name="key2" eval="'client_action_multi'" />
        <field name="model" eval="'test.model'" />
        <field name="name">Undelete</field>
        <field name="value" eval="'ir.actions.server,%d'%action_server_name"/>
        <field name="object" eval="True" />
    </record>

If you want to pop up a window you have to make a wizard to achieve this, and put your button in it to invoke the function and then you have to link the wizard action to the ir.values and it'll be like

<record model="ir.values" id="values_id">
        <field name="name">Undelete</field>
        <field name="key2">client_action_multi</field>
        <field name="value" eval="'ir.actions.act_window,' + str(ref('action_wizard_id'))" />
        <field name="key">action</field>
        <field name="model">model.model</field>
    </record>

I hope this could helps you

Regards...

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

0 follower(s)

Stats

Asked: 5/7/14, 8:32 AM
Seen: 2387 times
Last updated: 3/16/15, 8:10 AM