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.

1

how to get active_id in a web module

By
Mike Telahun
on 6/7/13, 10:43 AM 1,979 views

I am writing a module that will allow a user to take a picture of the employee right from the employee record. It's a web module and it's triggered by a client action (activated by clicking a button in the hr.employee form view). I have the mechanics of getting the picture and saving it to the database worked out. However, I don't have any way of finding out the id of the employee to which it belongs. In a regular (server side) module you can usually just get it from the context. But it seems this is not possible in a web module. I found a field called active_id in instance.session but it is incorrect (I don't know if that's by design or if it's a bug). I also found a user_context object in instance.session but it contains only lang, tz, and uid.

Is there a way I can find out the id of the record from which a client action was launched?

1
Mike Telahun
On 6/7/13, 12:05 PM

I figured it out:

Instead of just calling the action directly from the form I changed the type of the button to "object" and had it call a function. Then, I created a function in hr.employee that searches for the client action by id, inserts the record's id in its params attribute and then returns it.

def action_take_picture(self, cr, uid, ids, context=None):

    if context == None:
        context = {}

    res_model, res_id = self.pool.get('ir.model.data').get_object_reference(cr, uid,
                                                                            'hr_webcam',
                                                                            'action_take_photo')
    dict_act_window = self.pool.get('ir.actions.client').read(cr, uid, res_id, [])
    if not dict_act_window.get('params', False):
        dict_act_window.update({'params': {}})
    dict_act_window['params'].update({'employee_id': len(ids) and ids[0] or False})
    return dict_act_window

I then save this value in my javascript init function:

    init: function(parent, action) {
        this._super(parent, action);
        this.employee_id = action.params.employee_id;
    },

07.06.13 and no upvote? That solution saves my day. Awesome contribution. Thank you.

Andre
on 7/28/16, 7:25 AM

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: 6/7/13, 10:43 AM
Seen: 1979 times
Last updated: 7/28/16, 7:26 AM