[FIX] add 'context' free variable in evaluation contexts for domains and contexts

bzr revid: xmo@openerp.com-20121010145945-16shdry3udum0mn1
This commit is contained in:
Xavier Morel 2012-10-10 16:59:45 +02:00
parent 894bd34e62
commit 1fa00288b2
2 changed files with 33 additions and 1 deletions

View File

@ -307,7 +307,9 @@ openerp.web.pyeval = function (instance) {
* @param {Object} [context] evaluation context
*/
instance.web.pyeval.eval = function (type, object, context) {
if (!context) { context = instance.web.pyeval.context()}
context = _.extend(instance.web.pyeval.context(), context || {});
context['context'] = py.dict.fromJSON(context);
switch(type) {
case 'contexts': return eval_contexts(object, context);
case 'domains': return eval_domains(object, context);

View File

@ -29,6 +29,21 @@ $(document).ready(function () {
openerp.session.uid = 42;
}
});
test('context_recursive', function () {
var context_to_eval = [{
__ref: 'context',
__debug: '{"foo": context.get("bar", "qux")}'
}];
deepEqual(
openerp.web.pyeval.eval('contexts', context_to_eval, {bar: "ok"}),
{foo: 'ok'});
deepEqual(
openerp.web.pyeval.eval('contexts', context_to_eval, {bar: false}),
{foo: false});
deepEqual(
openerp.web.pyeval.eval('contexts', context_to_eval),
{foo: 'qux'});
});
test('context_sequences', function () {
// Context n should have base evaluation context + all of contexts
// 0..n-1 in its own evaluation context
@ -170,6 +185,21 @@ $(document).ready(function () {
['name', '<=', current_date]
]);
});
test('context_freevar', function () {
var domains_to_eval = [{
__ref: 'domain',
__debug: '[("foo", "=", context.get("bar", "qux"))]'
}, [['bar', '>=', 42]]];
deepEqual(
openerp.web.pyeval.eval('domains', domains_to_eval, {bar: "ok"}),
[['foo', '=', 'ok'], ['bar', '>=', 42]]);
deepEqual(
openerp.web.pyeval.eval('domains', domains_to_eval, {bar: false}),
[['foo', '=', false], ['bar', '>=', 42]]);
deepEqual(
openerp.web.pyeval.eval('domains', domains_to_eval),
[['foo', '=', 'qux'], ['bar', '>=', 42]]);
});
module('eval.groupbys', {
setup: function () {