Browse Source

[FIX] disjunctions in advanced search

fixes #222
pull/263/head
Holger Brunn 9 years ago
parent
commit
7c76232a18
  1. 59
      web_advanced_search_x2x/static/src/js/web_advanced_search_x2x.js

59
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({ instance.web.SearchView.include({
build_search_data: function() build_search_data: function()
{ {
@ -297,31 +333,20 @@ openerp.web_advanced_search_x2x = function(instance)
{ {
return; return;
} }
var compound_domains = [], leaves = [];
var combined = [];
_.each(domain, function(leaf) _.each(domain, function(leaf)
{ {
if(leaf instanceof instance.web.CompoundDomain) 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; return result;
}, },

Loading…
Cancel
Save