models = [x[1].model for x in relation_fields]
model_obj = self.pool.get('ir.model')
model_osv = self.pool[model.model]
- for colinfo in model_osv._all_columns.itervalues():
- coldef = colinfo.column
- coltype = coldef._type
+ for field in model_osv._fields.itervalues():
+ ftype = field.type
relation_field = None
- if coltype in ttypes and colinfo.column._obj not in models:
- relation_model_id = model_obj.search(cr, UID_ROOT, [('model','=',coldef._obj)])[0]
+ if ftype in ttypes and field.comodel_name not in models:
+ relation_model_id = model_obj.search(cr, UID_ROOT, [('model','=',field.comodel_name)])[0]
relation_model_browse = model_obj.browse(cr, UID_ROOT, relation_model_id, context=context)
- relation_osv = self.pool[coldef._obj]
+ relation_osv = self.pool[field.comodel_name]
#skip virtual one2many fields (related, ...) as there is no reverse relationship
- if coltype == 'one2many' and hasattr(coldef, '_fields_id'):
+ if ftype == 'one2many' and field.inverse_name:
# don't record reverse path if it's not a real m2o (that happens, but rarely)
- dest_model_ci = relation_osv._all_columns
- reverse_rel = coldef._fields_id
- if reverse_rel in dest_model_ci and dest_model_ci[reverse_rel].column._type == 'many2one':
+ dest_fields = relation_osv._fields
+ reverse_rel = field.inverse_name
+ if reverse_rel in dest_fields and dest_fields[reverse_rel].type == 'many2one':
relation_field = ('%s.%s'%(reverse_rel, suffix)) if suffix else reverse_rel
local_rel_fields.append((relation_field, relation_model_browse))
for parent in relation_osv._inherits:
if parent not in models:
parent_model = self.pool[parent]
- parent_colinfos = parent_model._all_columns
+ parent_fields = parent_model._fields
parent_model_browse = model_obj.browse(cr, UID_ROOT,
model_obj.search(cr, UID_ROOT, [('model','=',parent)]))[0]
- if relation_field and coldef._fields_id in parent_colinfos:
+ if relation_field and field.inverse_name in parent_fields:
# inverse relationship is available in the parent
local_rel_fields.append((relation_field, parent_model_browse))
else:
# TODO: can we setup a proper rule to restrict inherited models
# in case the parent does not contain the reverse m2o?
local_rel_fields.append((None, parent_model_browse))
- if relation_model_id != model.id and coltype in ['one2many', 'many2many']:
+ if relation_model_id != model.id and ftype in ['one2many', 'many2many']:
local_rel_fields += self._get_recursive_relations(cr, uid, relation_model_browse,
- [coltype], relation_fields + local_rel_fields, suffix=relation_field, context=context)
+ [ftype], relation_fields + local_rel_fields, suffix=relation_field, context=context)
return local_rel_fields
def _get_relationship_classes(self, cr, uid, model, context=None):