def check_group(node): """Apply group restrictions, may be set at view level or model level:: * at view level this means the element should be made invisible to people who are not members * at model level (exclusively for fields, obviously), this means the field should be completely removed from the view, as it is completely unavailable for non-members :return: True if field should be included in the result of fields_view_get """ if node.tag == 'field' and node.get('name') in Model._all_columns: column = Model._all_columns[node.get('name')].column if column.groups and not self.user_has_groups( cr, user, groups=column.groups, context=context): node.getparent().remove(node) fields.pop(node.get('name'), None) # no point processing view-level ``groups`` anymore, return return False if node.get('groups'): can_see = self.user_has_groups( cr, user, groups=node.get('groups'), context=context) if not can_see: node.set('invisible', '1') modifiers['invisible'] = True if 'attrs' in node.attrib: del(node.attrib['attrs']) #avoid making field visible later del(node.attrib['groups']) return True
def check_group(node): """Apply group restrictions, may be set at view level or model level:: * at view level this means the element should be made invisible to people who are not members * at model level (exclusively for fields, obviously), this means the field should be completely removed from the view, as it is completely unavailable for non-members :return: True if field should be included in the result of fields_view_get """ if node.tag == 'field' and node.get('name') in Model._all_columns: column = Model._all_columns[node.get('name')].column if column.groups and not self.user_has_groups( cr, user, groups=column.groups, context=context): node.getparent().remove(node) fields.pop(node.get('name'), None) # no point processing view-level ``groups`` anymore, return return False if node.get('groups'): can_see = self.user_has_groups( cr, user, groups=node.get('groups'), context=context) if not can_see: node.set('invisible', '1') modifiers['invisible'] = True if 'attrs' in node.attrib: del(node.attrib['attrs']) #avoid making field visible later del(node.attrib['groups']) return True
def name_search(self, cr, user, name, args=None, operator='ilike', context=None, limit=100): if not args: args = [] if context is None: context = {} if not name: ids = self.search(cr, user, args, limit=limit, context=context) elif context.get('contact_display', 'contact') == 'partner': ids = self.search(cr, user, [('partner_id', operator, name)] + args, limit=limit, context=context) else: # first lookup zip code, as it is a common and efficient way to search on these data ids = self.search(cr, user, [('zip', '=', name)] + args, limit=limit, context=context) # then search on other fields: if context.get('contact_display', 'contact') == 'partner_address': fields = ['partner_id', 'name', 'country_id', 'city', 'street'] else: fields = ['name', 'country_id', 'city', 'street'] # Here we have to search the records that satisfy the domain: # OR([[(f, operator, name)] for f in fields])) + args # Searching on such a domain can be dramatically inefficient, due to the expansion made # for field translations, and the handling of the disjunction by the DB engine itself. # So instead, we search field by field until the search limit is reached. while (not limit or len(ids) < limit) and fields: f = fields.pop(0) new_ids = self.search(cr, user, [(f, operator, name)] + args, limit=(limit-len(ids) if limit else limit), context=context) # extend ids with the ones in new_ids that are not in ids yet (and keep order) old_ids = set(ids) ids.extend([id for id in new_ids if id not in old_ids]) if limit: ids = ids[:limit] return self.name_get(cr, user, ids, context=context)
def name_search(self, cr, user, name, args=None, operator='ilike', context=None, limit=100): if not args: args = [] if context is None: context = {} if not name: ids = self.search(cr, user, args, limit=limit, context=context) elif context.get('contact_display', 'contact') == 'partner': ids = self.search(cr, user, [('partner_id', operator, name)] + args, limit=limit, context=context) else: # first lookup zip code, as it is a common and efficient way to search on these data ids = self.search(cr, user, [('zip', '=', name)] + args, limit=limit, context=context) # then search on other fields: if context.get('contact_display', 'contact') == 'partner_address': fields = ['partner_id', 'name', 'country_id', 'city', 'street'] else: fields = ['name', 'country_id', 'city', 'street'] # Here we have to search the records that satisfy the domain: # OR([[(f, operator, name)] for f in fields])) + args # Searching on such a domain can be dramatically inefficient, due to the expansion made # for field translations, and the handling of the disjunction by the DB engine itself. # So instead, we search field by field until the search limit is reached. while (not limit or len(ids) < limit) and fields: f = fields.pop(0) new_ids = self.search(cr, user, [(f, operator, name)] + args, limit=(limit - len(ids) if limit else limit), context=context) # extend ids with the ones in new_ids that are not in ids yet (and keep order) old_ids = set(ids) ids.extend([id for id in new_ids if id not in old_ids]) if limit: ids = ids[:limit] return self.name_get(cr, user, ids, context=context)