[MERGE] 7.0 branch

bzr revid: nicolas.vanhoren@openerp.com-20130319102859-rj9r9ngqtf5ep3a3
This commit is contained in:
niv-openerp 2013-03-19 11:28:59 +01:00
commit 185b405b96
7 changed files with 34 additions and 13 deletions

View File

@ -969,7 +969,10 @@ instance.web.CompoundContext = instance.web.Class.extend({
},
get_eval_context: function () {
return this.__eval_context;
}
},
eval: function() {
return instance.web.pyeval.eval('context', this, undefined, {no_user_context: true});
},
});
instance.web.CompoundDomain = instance.web.Class.extend({
@ -992,7 +995,10 @@ instance.web.CompoundDomain = instance.web.Class.extend({
},
get_eval_context: function() {
return this.__eval_context;
}
},
eval: function() {
return instance.web.pyeval.eval('domain', this);
},
});
instance.web.DropMisordered = instance.web.Class.extend({

View File

@ -502,12 +502,15 @@ openerp.web.pyeval = function (instance) {
return py.PY_call(py.PY_getAttr(d, 'strftime'), [args.format]);
});
var args = _.map(('year month day hour minute second microsecond '
+ 'years months weeks days hours minutes secondes microseconds '
+ 'weekday leakdays yearday nlyearday').split(' '), function (arg) {
return [arg, null]
});
args.unshift('*');
var relativedelta = py.type('relativedelta', null, {
__init__: function () {
this.ops = py.PY_parseArgs(arguments,
'* year month day hour minute second microsecond '
+ 'years months weeks days hours minutes secondes microseconds '
+ 'weekday leakdays yearday nlyearday');
this.ops = py.PY_parseArgs(arguments, args);
},
__add__: function (other) {
if (!py.PY_isInstance(other, datetime.date)) {
@ -600,7 +603,7 @@ openerp.web.pyeval = function (instance) {
});
var eval_contexts = function (contexts, evaluation_context) {
evaluation_context = evaluation_context || {};
evaluation_context = _.extend(instance.web.pyeval.context(), evaluation_context || {});
return _(contexts).reduce(function (result_context, ctx) {
// __eval_context evaluations can lead to some of `contexts`'s
// values being null, skip them as well as empty contexts
@ -625,9 +628,10 @@ openerp.web.pyeval = function (instance) {
// siblings
_.extend(evaluation_context, evaluated);
return _.extend(result_context, evaluated);
}, _.extend({}, instance.session.user_context));
}, {});
};
var eval_domains = function (domains, evaluation_context) {
evaluation_context = _.extend(instance.web.pyeval.context(), evaluation_context || {});
var result_domain = [];
_(domains).each(function (domain) {
if (_.isString(domain)) {
@ -654,6 +658,7 @@ openerp.web.pyeval = function (instance) {
return result_domain;
};
var eval_groupbys = function (contexts, evaluation_context) {
evaluation_context = _.extend(instance.web.pyeval.context(), evaluation_context || {});
var result_group = [];
_(contexts).each(function (ctx) {
if (_.isString(ctx)) {
@ -704,14 +709,15 @@ openerp.web.pyeval = function (instance) {
* @param {Array} object domains or contexts to evaluate
* @param {Object} [context] evaluation context
*/
instance.web.pyeval.eval = function (type, object, context) {
instance.web.pyeval.eval = function (type, object, context, options) {
options = options || {};
context = _.extend(instance.web.pyeval.context(), context || {});
context['context'] = py.dict.fromJSON(context);
//noinspection FallthroughInSwitchStatementJS
switch(type) {
case 'context': object = [object];
case 'contexts': return eval_contexts(object, context);
case 'contexts': return eval_contexts((options.no_user_context ? [] : [instance.session.user_context]).concat(object), context);
case 'domain': object = [object];
case 'domains': return eval_domains(object, context);
case 'groupbys': return eval_groupbys(object, context);

View File

@ -382,6 +382,7 @@ instance.web.SearchView = instance.web.Widget.extend(/** @lends instance.web.Sea
model: this.dataset._model,
view_id: this.view_id,
view_type: 'search',
context: this.dataset.get_context(),
});
$.when(load_view).then(function (r) {

View File

@ -3277,7 +3277,8 @@ instance.web.form.FieldMany2One = instance.web.form.AbstractField.extend(instanc
res_model: self.field.relation,
res_id: self.get("value"),
views: [[false, 'form']],
target: 'current'
target: 'current',
context: self.build_context().eval(),
});
return false;
});

View File

@ -1282,6 +1282,7 @@ instance.web.View = instance.web.Widget.extend({
"view_id": this.view_id,
"view_type": this.view_type,
"toolbar": !!this.options.$sidebar,
"context": this.dataset.get_context(),
});
}
return view_loaded_def.then(function(r) {
@ -1496,7 +1497,7 @@ instance.web.fields_view_get = function(args) {
if (typeof model === 'string') {
model = new instance.web.Model(args.model, args.context);
}
return args.model.call('fields_view_get', [args.view_id, args.view_type, model.context(), args.toolbar]).then(function(fvg) {
return args.model.call('fields_view_get', [args.view_id, args.view_type, args.context, args.toolbar]).then(function(fvg) {
return postprocess(fvg);
});
};

View File

@ -125,7 +125,7 @@
<tr>
<td><label for="super_admin_pwd">Master password:</label></td>
<td>
<input type="text" name="super_admin_pwd" class="required" value="admin"/>
<input type="password" name="super_admin_pwd" class="required" value="admin"/>
</td>
</tr>
<tr>

View File

@ -259,6 +259,12 @@ openerp.testing.section('eval.types', {
py.eval('a + a', ctx);
}, /^Error: TypeError:/);
});
test('relastivedelta', function (instance) {
strictEqual(
py.eval("(datetime.date(2012, 2, 15) + relativedelta(days=-1)).strftime('%Y-%m-%d 23:59:59')",
instance.web.pyeval.context()),
"2012-02-14 23:59:59");
})
});
openerp.testing.section('eval.edc', {
dependencies: ['web.data'],