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

爷,独闯天下 提交于 2019-12-11 02:21:28

问题


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 1st load...

Thanks in advance for any pointers.


回答1:


try:

this.view.datarecord.id

OpenERP 7 in form view: debugged using google chrome




回答2:


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.



来源:https://stackoverflow.com/questions/11151768/client-web-how-to-get-current-record-id-at-any-time

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!