From 7c76232a18357dd32170dabdea10296d66b586ff Mon Sep 17 00:00:00 2001 From: Holger Brunn Date: Fri, 20 Nov 2015 13:52:28 +0100 Subject: [PATCH] [FIX] disjunctions in advanced search fixes #222 --- .../static/src/js/web_advanced_search_x2x.js | 59 +++++++++++++------ 1 file changed, 42 insertions(+), 17 deletions(-) diff --git a/web_advanced_search_x2x/static/src/js/web_advanced_search_x2x.js b/web_advanced_search_x2x/static/src/js/web_advanced_search_x2x.js index f233c235..baf29f0a 100644 --- a/web_advanced_search_x2x/static/src/js/web_advanced_search_x2x.js +++ b/web_advanced_search_x2x/static/src/js/web_advanced_search_x2x.js @@ -283,6 +283,42 @@ openerp.web_advanced_search_x2x = function(instance) }, }); + normalize_domain = function(domain) + { + // this is the js version of https://github.com/odoo/odoo/blob/8.0/openerp/osv/expression.py#L203 + if(!domain.length) + { + return [(1, '=', 1)] + } + result = [] + expected = 1 + op_arity = {'!': 1, '&': 2, '|': 2}; + _(domain).each(function(token) + { + if(expected == 0) + { + result.unshift('&'); + expected = 1; + } + result.push(token); + if(_.isArray(token)) + { + expected -= 1; + } + else + { + expected += (op_arity[token] || 0) - 1; + } + }) + if(expected) + { + throw _.sprintf( + 'This domain is syntactically not correct: %s', + domain) + } + return result; + }; + instance.web.SearchView.include({ build_search_data: function() { @@ -297,31 +333,20 @@ openerp.web_advanced_search_x2x = function(instance) { return; } - var compound_domains = [], leaves = []; + var combined = []; _.each(domain, function(leaf) { if(leaf instanceof instance.web.CompoundDomain) { - compound_domains.push(leaf); + combined = combined.concat( + normalize_domain(leaf.eval())); } - if(_.isArray(leaf)) + else { - leaves.push(leaf); + combined.push(leaf); } }); - if(compound_domains.length) - { - var combined = new instance.web.CompoundDomain(); - _.each(compound_domains, function(domain) - { - combined.add(domain.eval()); - }) - _.each(leaves, function(leaf) - { - combined.add([leaf]) - }); - result.domains[index] = combined; - } + result.domains[index] = combined; }); return result; },