[FIX] compound domain and context's eval_context can be a compound itself, evaluate those if needs be

also fix tests html file for renames and extracts, and add a test case for complex non-literal evaluation contexts

bzr revid: xmo@openerp.com-20120404114830-a6416m2v7h8cyf08
This commit is contained in:
Xavier Morel
2012-04-04 13:48:30 +02:00
parent 2a8d78c88c
commit 239a118913
3 changed files with 102 additions and 6 deletions
+10 -5
View File
@@ -13,7 +13,7 @@ openerp.web.core = function(openerp) {
// a function to override the "extend()" method of JR's inheritance, allowing
// the usage of "include()"
oe_override_class = function(claz){
var oe_override_class = function(claz){
var initializing = false, fnTest = /xyz/.test(function(){xyz;}) ?
/\b_super\b/ : /.*/;
@@ -625,16 +625,20 @@ openerp.web.Connection = openerp.web.CallbackEnabled.extend( /** @lends openerp.
var result_context = _.extend({}, this.user_context),
self = this;
_(contexts).each(function (ctx) {
// __eval_context evaluations can lead to some of `contexts`'s
// values being null, skip them as well as empty contexts
if (_.isEmpty(ctx)) { return; }
switch(ctx.__ref) {
case 'context':
_.extend(result_context, py.eval(
ctx.__debug, evaluation_context));
break;
case 'compound_context':
var eval_context = self.test_eval_contexts([ctx.__eval_context]);
_.extend(
result_context, self.test_eval_contexts(
ctx.__contexts, _.extend(
{}, evaluation_context, ctx.__eval_context)));
{}, evaluation_context, eval_context)));
break;
default:
_.extend(result_context, ctx);
@@ -642,19 +646,20 @@ openerp.web.Connection = openerp.web.CallbackEnabled.extend( /** @lends openerp.
});
return result_context;
},
test_eval_domains: function (domains, eval_context) {
test_eval_domains: function (domains, evaluation_context) {
var result_domain = [], self = this;
_(domains).each(function (dom) {
switch(dom.__ref) {
case 'domain':
result_domain.push.apply(
result_domain, py.eval(dom.__debug, eval_context));
result_domain, py.eval(dom.__debug, evaluation_context));
break;
case 'compound_domain':
var eval_context = self.test_eval_contexts([dom.__eval_context]);
result_domain.push.apply(
result_domain, self.test_eval_domains(
dom.__domains, _.extend(
{}, eval_context, dom.__eval_context)));
{}, evaluation_context, eval_context)));
break;
default:
result_domain.push.apply(
+88
View File
@@ -0,0 +1,88 @@
$(document).ready(function () {
var openerp;
module("eval.contexts", {
setup: function () {
openerp = window.openerp.init();
window.openerp.web.core(openerp);
}
});
test('non-literal_eval_contexts', function () {
var result = openerp.connection.test_eval_contexts([{
"__ref": "compound_context",
"__contexts": [
{"__ref": "context", "__debug": "{'type':parent.type}",
"__id": "462b9dbed42f"}
],
"__eval_context": {
"__ref": "compound_context",
"__contexts": [{
"__ref": "compound_context",
"__contexts": [
{"__ref": "context", "__debug": "{'type': type}",
"__id": "16a04ed5a194"}
],
"__eval_context": {
"__ref": "compound_context",
"__contexts": [
{"lang": "en_US", "tz": false, "uid": 1,
"journal_type": "sale", "section_id": false,
"default_type": "out_invoice",
"type": "out_invoice", "department_id": false},
{"id": false, "journal_id": 10,
"number": false, "type": "out_invoice",
"currency_id": 1, "partner_id": 4,
"fiscal_position": false,
"date_invoice": false, "period_id": false,
"payment_term": false, "reference_type": "none",
"reference": false, "account_id": 440,
"name": false, "invoice_line": [],
"tax_line": [], "amount_untaxed": 0,
"amount_tax": 0, "reconciled": false,
"amount_total": 0, "state": "draft",
"residual": 0, "company_id": 1,
"date_due": false, "user_id": 1,
"partner_bank_id": false, "origin": false,
"move_id": false, "comment": false,
"payment_ids": [[6, false, []]],
"active_id": false, "active_ids": [],
"active_model": "account.invoice",
"parent": {}}
], "__eval_context": null}
}, {
"id": false,
"product_id": 4,
"name": "[PC1] Basic PC",
"quantity": 1,
"uos_id": 1,
"price_unit": 100,
"account_id": 853,
"discount": 0,
"account_analytic_id": false,
"company_id": false,
"note": false,
"invoice_line_tax_id": [[6, false, [1]]],
"active_id": false,
"active_ids": [],
"active_model": "account.invoice.line",
"parent": {
"id": false, "journal_id": 10, "number": false,
"type": "out_invoice", "currency_id": 1,
"partner_id": 4, "fiscal_position": false,
"date_invoice": false, "period_id": false,
"payment_term": false, "reference_type": "none",
"reference": false, "account_id": 440, "name": false,
"tax_line": [], "amount_untaxed": 0, "amount_tax": 0,
"reconciled": false, "amount_total": 0,
"state": "draft", "residual": 0, "company_id": 1,
"date_due": false, "user_id": 1,
"partner_bank_id": false, "origin": false,
"move_id": false, "comment": false,
"payment_ids": [[6, false, []]]}
}],
"__eval_context": null
}
}]);
deepEqual(result, {type: 'out_invoice'});
});
});
+4 -1
View File
@@ -24,7 +24,9 @@
<script src="/web/static/lib/qweb/qweb2.js"></script>
<script src="/web/static/lib/py.parse/lib/py.js"></script>
<script src="/web/static/lib/py.js/lib/py.js"></script>
<script src="/web/static/lib/novajs/src/nova.js"></script>
<script src="/web/static/src/js/boot.js"></script>
<script src="/web/static/src/js/core.js"></script>
@@ -51,4 +53,5 @@
<script type="text/javascript" src="/web/static/test/list-utils.js"></script>
<script type="text/javascript" src="/web/static/test/formats.js"></script>
<script type="text/javascript" src="/web/static/test/onchange.js"></script>
<script type="text/javascript" src="/web/static/test/evals.js"></script>
</html>