[FIX] add 'context' free variable in evaluation contexts for domains and contexts
bzr revid: xmo@openerp.com-20121010145945-16shdry3udum0mn1
This commit is contained in:
parent
894bd34e62
commit
1fa00288b2
|
@ -307,7 +307,9 @@ openerp.web.pyeval = function (instance) {
|
||||||
* @param {Object} [context] evaluation context
|
* @param {Object} [context] evaluation context
|
||||||
*/
|
*/
|
||||||
instance.web.pyeval.eval = function (type, object, 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) {
|
switch(type) {
|
||||||
case 'contexts': return eval_contexts(object, context);
|
case 'contexts': return eval_contexts(object, context);
|
||||||
case 'domains': return eval_domains(object, context);
|
case 'domains': return eval_domains(object, context);
|
||||||
|
|
|
@ -29,6 +29,21 @@ $(document).ready(function () {
|
||||||
openerp.session.uid = 42;
|
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 () {
|
test('context_sequences', function () {
|
||||||
// Context n should have base evaluation context + all of contexts
|
// Context n should have base evaluation context + all of contexts
|
||||||
// 0..n-1 in its own evaluation context
|
// 0..n-1 in its own evaluation context
|
||||||
|
@ -170,6 +185,21 @@ $(document).ready(function () {
|
||||||
['name', '<=', current_date]
|
['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', {
|
module('eval.groupbys', {
|
||||||
setup: function () {
|
setup: function () {
|
||||||
|
|
Loading…
Reference in New Issue