Odoo is the world's easiest all-in-one management software. It includes hundreds of business apps:
CRM | e-Commerce | Accounting | Inventory | PoS | Project management | MRP | etc.
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.
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
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 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.Register
Odoo Training Center
Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.Test it now
|Asked: 5/7/14, 8:32 AM|
|Seen: 2456 times|
|Last updated: 3/16/15, 8:10 AM|