simahawk
simahawk

Reputation: 2431

Client web - how to get current record id at any time

I'm trying to work on the "different permissions based on workflow state" issue but I'm struggling with the fact that it seems impossible to get the id of the current object 'at any time' that is necessary in order to get the permission of that object. What I mean is that I manage to get it from the client state following jQuery bbq docs like:

$.bbq.getState().id

BUT it looks like this is doable only AFTER a complete page load. I investigated this by placing some alert in the main view events, like:

openerp.web.PageView = openerp.web.PageView.extend({
    on_loaded: function(data) {
        this._super(data);
        alert('page load ' + $.bbq.getState().id);
    },
    do_show: function() {
        this._super();
        alert('page show ' + $.bbq.getState().id);
    },
    reload: function() {
        this._super();
        alert('page reload ' + $.bbq.getState().id);
    },
    on_record_loaded: function(record) {
        this._super(record);
        alert('record loaded ' + $.bbq.getState().id);
    }
});

and I found that when you open the page view (by clicking on an item in a search view, for instance) you get always "undefined".

Then, you get it into "reload" and "on_record_loaded" when passing from an object to another using paged navigation. And then, you miss it again when you click on the "edit" button.

In the form view I successfully got it only on the 1st load because it seems that some caching is in-place. So that, if I place a pdb into web client's fields_view_get and I do this into the form "init_view":

var ids = [];
if ($.bbq.getState().id){
    ids = [parseInt($.bbq.getState().id)];
}
console.log(ids);
return this.rpc("/web/view/load", {
    "model": this.model,
    "view_id": this.view_id,
    "view_type": "form",
    toolbar: this.options.sidebar,
    context: context,
    ids: ids,
    }, this.on_loaded);

I get it only the 1st time that the page gets loaded. The same happen if I take ids from

this.dataset.ids

I looked anywhere at the core web module and I can't find a proper API for this and it looks weird (above all on dataset) that we don't have a proper way for getting/working on the current record/s. Even the context and the session do not have any information about that.

Probably I should store this into the view itself on first load...

Upvotes: 2

Views: 1983

Answers (2)

kite
kite

Reputation: 1548

try:

this.view.datarecord.id

OpenERP 7 in form view: debugged using google chrome

Upvotes: 1

Ruchir Shukla
Ruchir Shukla

Reputation: 805

Try the combination of the

this.dataset.ids and this.dataset.index

like curr_id = this.dataset.ids[this.dataset.index]

this might solve your problem.

Upvotes: 0

Related Questions