Openerp: action to call a method for all identifiers selected in a tree view

I want to create an action that will call a method on the model that passes the identifiers of the selected rows in the tree view so that the action is available on the right side of the screen when selecting elements. Can this be done without creating a wizard with one ok button?

As a rule, I would like to be able to call the button_upgrade method for ir.module.module to update several modules at once, but this would be useful for many cases in the application.

I am using OpenERP 6.1 and the web client.

+4
source share
4 answers

I did this in 5.0 using the old-style wizard , but I did not see a way to do this in 6.1 web client, though. You can still use the old-style wizard in the 6.1 GTK client, but it does not work in the web client.

You can send fate messages to the OK dialog to, in my opinion, entertain your users.

+2
source

I don't have v6, but it works in v7:

<record id="action_id_name" model="ir.actions.server"> <field name="name">Name that shows in More button</field> <field name="type">ir.actions.server</field> <field name="model_id" ref="model_blah_blah"/> <field name="state">code</field> <field name="code">self.some_custom_code(cr, uid, context.get('active_ids'), ..., context=context)</field> </record> <record id="value_id_name" model="ir.values"> <field name="name">Name</field> <field name="action_id" ref="action_id_name"/> <field name="value" eval="'ir.actions.server,' + str(ref('action_id_name'))"/> <field name="key">action</field> <field name="model_id" ref="model_blah_blah"/> <field name="model">blah.blah</field> <field name="key2">client_action_multi</field> </record> def some_custom_code(self, cursor, uid, ids, ..., context): # possibly do some processing # maybe with the ... extra fields you added # # post your changes, either with an sql statement or by calling # self.write(...) return True 

Names you should replace with actual values:

  • action_id_name : id of your action record
  • Name that shows in More button : everything you want to show in the button
  • model_blah_blah : the name of the model used (should match what is found in your security/ir.model.access.csv )
  • some_custom_code : function name in your model
  • value_id_name : identifier of your action value entry
  • Name : name (not sure where it appears)
  • blah.blah : model and table name in OpenERP notation
  • ... : any additional arguments / parameters that you add
+2
source

I got this job:

  • Create a new server action , in the settings "Settings" Low-level objects "Actions" Server actions:

    • Action Name : Update Selected Modules
    • Object : ir.module.module
    • Action Type : Python Code
    • Python code : action = obj.button_upgrade (context = context)
  • Create a new action binding , in the settings "Settings" Low-level objects "Actions" Action bindings:

    • Name : "Updating Update Engine Bindings"
    • Model Name : ir.module.module
    • Qualifier : client_action_multi
    • Action : Look for "Update selected modules" in the "Action (change only)" field. You should get an Action Reference field with something like: "ir.actions.server, 680".

Forum topic "Action: how to get selected rows?" used as a reference. You can also find an interesting Email Template button that automates the creation of an action for mass mailings using a given email template.

+1
source

You must do this with the execute action. http://doc.openerp.com/v6.1/developer/03_modules_4.html#actions

0
source

All Articles