def __setup__(cls): super(TreeMixin, cls).__setup__() field = getattr(cls, name) clause = (name, 'not like', '%' + escape_wildcard(separator) + '%') # If TreeMixin is after the class where name is defined in # __mro__, it modifies the base field copied so it must ensure # to add only once the domain if clause not in field.domain: domain = [clause] if field.domain: domain.append(field.domain) field.domain = domain
def _match(cls, name, email): pool = Pool() User = pool.get('res.user') domain = ['OR'] for field in ['name', 'login', 'email']: for value in [name, email]: if value and len(value) >= 3: domain.append( (field, 'ilike', '%' + escape_wildcard(value) + '%')) for user in User.search([ ('email', '!=', ''), domain, ], order=[]): yield user.name, user.email
def _match(cls, name, email): pool = Pool() User = pool.get('web.user') yield from super()._match(name, email) domain = ['OR'] for field in ['party.name', 'email']: for value in [name, email]: if value and len(value) >= 3: domain.append( (field, 'ilike', '%' + escape_wildcard(value) + '%')) for user in User.search([ ('email', '!=', ''), domain, ], order=[]): yield user.party.name if user.party else '', user.email
def _match(cls, name, email): pool = Pool() ContactMechanism = pool.get('party.contact_mechanism') yield from super()._match(name, email) domain = ['OR'] for field in ['name', 'party.name', 'value']: for value in [name, email]: if value and len(value) >= 3: domain.append( (field, 'ilike', '%' + escape_wildcard(value) + '%')) for contact in ContactMechanism.search([ ('type', '=', 'email'), ('value', '!=', ''), domain, ], order=[]): yield contact.name or contact.party.name, contact.value
def test_escape_wildcard(self): self.assertEqual(escape_wildcard('foo%bar_baz\\'), 'foo\\%bar\\_baz\\\\')