[imp] added helper to call any method on models
bzr revid: nicolas.vanhoren@openerp.com-20110902152622-marolbq8hkxu6wd0
This commit is contained in:
parent
f46984aa76
commit
ae91f6400b
|
@ -700,6 +700,12 @@ class DataSet(openerpweb.Controller):
|
|||
args[domain_id] = d
|
||||
if context_id and len(args) - 1 >= context_id:
|
||||
args[context_id] = c
|
||||
|
||||
for i in xrange(len(args)):
|
||||
if isinstance(args[i], base.common.nonliterals.BaseContext):
|
||||
args[i] = session.eval_context(args[i])
|
||||
if isinstance(args[i], base.common.nonliterals.BaseDomain):
|
||||
args[i] = session.eval_domain(args[i])
|
||||
|
||||
return getattr(req.session.model(model), method)(*args)
|
||||
|
||||
|
|
|
@ -737,6 +737,50 @@ openerp.web.ReadOnlyDataSetSearch = openerp.web.DataSetSearch.extend({
|
|||
on_unlink: function(ids) {}
|
||||
});
|
||||
|
||||
openerp.base.Model = openerp.base.SessionAware.extend({
|
||||
init: function(session, model_name) {
|
||||
this._super(session);
|
||||
this.model_name = model_name;
|
||||
},
|
||||
get_func: function(method_name) {
|
||||
var self = this;
|
||||
return function() {
|
||||
if (method_name == "search_read")
|
||||
return self._search_read.apply(self, arguments);
|
||||
return self._call(method_name, arguments);
|
||||
};
|
||||
},
|
||||
_call: function (method, args) {
|
||||
return this.rpc('/base/dataset/call', {
|
||||
model: this.model_name,
|
||||
method: method,
|
||||
args: args
|
||||
}).pipe(function(result) {
|
||||
if (method == "read" && result instanceof Array && result.length > 0 && result[0]["id"]) {
|
||||
var index = {};
|
||||
_.each(_.range(result.length), function(i) {
|
||||
index[result[i]["id"]] = result[i];
|
||||
})
|
||||
result = _.map(args[0], function(x) {return index[x];});
|
||||
}
|
||||
return result;
|
||||
});
|
||||
},
|
||||
_search_read: function(domain, fields, offset, limit, order, context) {
|
||||
return this.rpc('/base/dataset/search_read', {
|
||||
model: this.model_name,
|
||||
fields: fields,
|
||||
offset: offset,
|
||||
limit: limit,
|
||||
domain: domain,
|
||||
sort: order,
|
||||
context: context
|
||||
}).pipe(function(result) {
|
||||
return result.records;
|
||||
});;
|
||||
}
|
||||
});
|
||||
|
||||
openerp.web.CompoundContext = openerp.web.Class.extend({
|
||||
init: function () {
|
||||
this.__ref = "compound_context";
|
||||
|
|
Loading…
Reference in New Issue