4
votes

I want to create an action which will call a method on a model passing the ids of the selected rows in a tree view, so that the action is available in the right hand part of the screen when items are selected. Is this possible to do this without creating a wizard with a single 'ok' button ?

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

I'm using OpenERP 6.1 and the web client.

4

4 Answers

2
votes

I did this in 5.0 with an old-style wizard, but I haven't seen a way to do it in 6.1 web client, yet. You can still use the old-style wizard in 6.1 GTK client, but it doesn't work in the web client.

You could pipe fortune messages into the OK dialog to entertain your users, I guess.

2
votes

I don't have v6, but this 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

The names that you should replace with actual values:

  • action_id_name: the id for your action record
  • Name that shows in More button: whatever you want to show in the button
  • model_blah_blah: the name of the model used (should match whatever is found in your security/ir.model.access.csv file)
  • some_custom_code: the name of the function in your model
  • value_id_name: the id of your action's value record
  • Name: a name (not sure where it shows up)
  • blah.blah: the name your model and table in OpenERP notation
  • ...: any extra arguments/parameters you add
1
votes

I got this working:

  1. Create a new Server Action, at Settings » Customization » Low Level Objects » Actions » Server Actions:

    • Action Name: "Upgrade Selected Modules"
    • Object: ir.module.module
    • Action Type: Python Code
    • Python Code: action = obj.button_upgrade(context=context)
  2. Create a new Action Binding, at Settings » Customization » Low Level Objects » Actions » Action Bindings:

    • Name: "Upgrade Modules action binding"
    • Model name: ir.module.module
    • Qualifier: client_action_multi
    • Action: search for "Upgrade Selected Modules" in the "Action (change only)" box. You should get the Action Reference field with something like: "ir.actions.server,680".

The forum topic "Action : how to get selected rows ?" was used as a reference. You might also find interesting the Email Template's button automating the creation of an action to do mass mailings using the defined email template.

0
votes