def _remove_bad_fields_values(self, fields, values, bad_fields): for bad_field in bad_fields: i = fields.index(bad_field) fields.pop(i) values.pop(i) return (fields, values)
def get_fields( self, req, model, prefix='', parent_name='', import_compat=True, parent_field_type=None, exclude=None): if not exclude: Model = req.session.model(model) exclude = Model.fields_get_exclude() # Below is a nearly verbatim copy of the method from openerp-web/addons/web/controllers/main.py # Could not call it as super, as it is a decorated method if True: # masq the indentation difference with the copied method for easy upgrading if import_compat and parent_field_type == "many2one": fields = {} else: fields = self.fields_get(req, model) if import_compat: fields.pop('id', None) else: fields['.id'] = fields.pop('id', {'string': 'ID'}) fields_sequence = sorted(fields.iteritems(), key=lambda field: field[1].get('string', '')) records = [] for field_name, field in fields_sequence: # Therp: move this out of the import_compat condition if exclude and field_name in exclude: continue if import_compat: if field.get('readonly'): # If none of the field's states unsets readonly, skip the field if all(dict(attrs).get('readonly', True) for attrs in field.get('states', {}).values()): continue id = prefix + (prefix and '/' or '') + field_name name = parent_name + (parent_name and '/' or '') + field['string'] record = {'id': id, 'string': name, 'value': id, 'children': False, 'field_type': field.get('type'), 'required': field.get('required'), 'relation_field': field.get('relation_field')} records.append(record) if len(name.split('/')) < 3 and 'relation' in field: ref = field.pop('relation') if import_compat: record['value'] += '/id' record['params'] = {'model': ref, 'prefix': id, 'name': name} if not import_compat or field['type'] == 'one2many': # m2m field in import_compat is childless record['children'] = True return records
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', 'ref', 'name', 'street', 'zip', 'state_id'] else: fields = ['ref', 'name', 'street', 'zip', 'state_id'] # 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 len(ids) < limit and fields: f = fields.pop(0) new_ids = self.search(cr, user, [(f, operator, name)] + args, limit=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]) 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', 'ref', 'name', 'street', 'zip', 'state_id' ] else: fields = ['ref', 'name', 'street', 'zip', 'state_id'] # 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 get_fields(self, req, model, prefix='', parent_name='', import_compat=True, parent_field_type=None, exclude=None): if not exclude: Model = req.session.model(model) exclude = Model.fields_get_exclude() # Below is a nearly verbatim copy of the method from openerp-web/addons/web/controllers/main.py # Could not call it as super, as it is a decorated method if True: # masq the indentation difference with the copied method for easy upgrading if import_compat and parent_field_type == "many2one": fields = {} else: fields = self.fields_get(req, model) if import_compat: fields.pop('id', None) else: fields['.id'] = fields.pop('id', {'string': 'ID'}) fields_sequence = sorted(fields.iteritems(), key=lambda field: field[1].get('string', '')) records = [] for field_name, field in fields_sequence: # Therp: move this out of the import_compat condition if exclude and field_name in exclude: continue if import_compat: if field.get('readonly'): # If none of the field's states unsets readonly, skip the field if all( dict(attrs).get('readonly', True) for attrs in field.get('states', {}).values()): continue id = prefix + (prefix and '/' or '') + field_name name = parent_name + (parent_name and '/' or '') + field['string'] record = { 'id': id, 'string': name, 'value': id, 'children': False, 'field_type': field.get('type'), 'required': field.get('required'), 'relation_field': field.get('relation_field') } records.append(record) if len(name.split('/')) < 3 and 'relation' in field: ref = field.pop('relation') if import_compat: record['value'] += '/id' record['params'] = {'model': ref, 'prefix': id, 'name': name} if not import_compat or field['type'] == 'one2many': # m2m field in import_compat is childless record['children'] = True return records