コンテンツへスキップ
メニュー
この質問にフラグが付けられました
1 返信
8324 ビュー

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?

アバター
破棄
著作者 最善の回答

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.

+1 upvote. I have been searching for a solution for 3 weeks and you saved me. Thank you

関連投稿 返信 ビュー 活動
2
7月 25
640
2
7月 25
1304
1
6月 25
827
1
4月 25
996
1
3月 25
1232