[FIX] base: search groups by full name not working with operators 'in' nor with operand boolean

bzr revid: dle@openerp.com-20140416112239-vl20z3xzgp61vygu
This commit is contained in:
Denis Ledoux 2014-04-16 13:22:39 +02:00
parent 8c8631b233
commit 3298051016
2 changed files with 42 additions and 8 deletions

View File

@ -28,7 +28,7 @@ import openerp
from openerp import SUPERUSER_ID
from openerp import pooler, tools
import openerp.exceptions
from openerp.osv import fields,osv
from openerp.osv import fields,osv, expression
from openerp.osv.orm import browse_record
from openerp.tools.translate import _
@ -51,13 +51,33 @@ class groups(osv.osv):
def _search_group(self, cr, uid, obj, name, args, context=None):
operand = args[0][2]
operator = args[0][1]
values = operand.split('/')
group_name = values[0]
where = [('name', operator, group_name)]
if len(values) > 1:
application_name = values[0]
group_name = values[1]
where = ['|',('category_id.name', operator, application_name)] + where
lst = True
if isinstance(operand, bool):
domains = [[('name', operator, operand)], [('category_id.name', operator, operand)]]
if operator in expression.NEGATIVE_TERM_OPERATORS == (not operand):
return expression.AND(domains)
else:
return expression.OR(domains)
if isinstance(operand, basestring):
lst = False
operand = [operand]
where = []
for group in operand:
values = filter(bool, group.split('/'))
group_name = values.pop().strip()
category_name = values and '/'.join(values).strip() or group_name
group_domain = [('name', operator, lst and [group_name] or group_name)]
category_domain = [('category_id.name', operator, lst and [category_name] or category_name)]
if operator in expression.NEGATIVE_TERM_OPERATORS and not values:
category_domain = expression.OR([category_domain, [('category_id', '=', False)]])
if (operator in expression.NEGATIVE_TERM_OPERATORS) == (not values):
sub_where = expression.AND([group_domain, category_domain])
else:
sub_where = expression.OR([group_domain, category_domain])
if operator in expression.NEGATIVE_TERM_OPERATORS:
where = expression.AND([where, sub_where])
else:
where = expression.OR([where, sub_where])
return where
_columns = {

View File

@ -302,3 +302,17 @@
float_round(0.01, precision_digits=3, precision_rounding=0.01)
except AssertionError:
pass
-
Test res.groups name search
-
!python {model: res.groups}: |
all_groups = self.search(cr, uid, [])
full_names = [(group.id, group.full_name) for group in self.browse(cr, uid, all_groups)]
group_ids = self.search(cr, uid, [('full_name', 'like', '%Sale%')])
assert set(group_ids) == set([id for (id, full_name) in full_names if 'Sale' in full_name]), "did not match search for 'Sale'"
group_ids = self.search(cr, uid, [('full_name', 'like', '%Technical%')])
assert set(group_ids) == set([id for (id, full_name) in full_names if 'Technical' in full_name]), "did not match search for 'Technical'"
group_ids = self.search(cr, uid, [('full_name', 'like', '%Sales /%')])
assert set(group_ids) == set([id for (id, full_name) in full_names if 'Sales /' in full_name]), "did not match search for 'Sales /'"
group_ids = self.search(cr, uid, [('full_name', 'in', ['Administration / Access Rights','Contact Creation'])])
assert group_ids, "did not match search for 'Administration / Access Rights' and 'Contact Creation'"