30
30
class module(osv.osv):
31
31
_inherit = 'ir.module.module'
32
32
_description = 'Module With Relationship Graph'
35
34
'file_graph': fields.binary('Relationship Graph'),
38
def _get_graphical_representation(self, cr, uid, model_ids, level=1, context=None):
37
def _get_graphical_representation(self, cr, uid, model_ids, level=1, context={}):
38
obj_model = self.pool.get('ir.model')
42
42
for id in model_ids:
43
model_data = self.pool.get('ir.model').browse(cr, uid, id)
43
model_data = obj_model.browse(cr, uid, id, context=context)
44
44
for field in (f for f in model_data.field_id if f.ttype in ('many2many', 'many2one', 'one2many')):
45
45
relation.append((model_data.model, field.name, field.ttype, field.relation, field.field_description))
46
new_model_ids = self.pool.get('ir.model').search(cr, uid, [('model', '=', field.relation)])
47
model = self.pool.get('ir.model').read(cr, uid, new_model_ids, ['id', 'name'])[0]
48
relation.extend(self._get_graphical_representation(cr, uid, model['id'], level - 1))
46
new_model_ids = obj_model.search(cr, uid, [('model', '=', field.relation)], context=context)
48
model = obj_model.read(cr, uid, new_model_ids, ['id', 'name'], context=context)[0]
49
relation.extend(self._get_graphical_representation(cr, uid, model['id'], level - 1))
49
50
return tuple(relation)
51
52
def _get_structure(self, relations, main_element):
73
74
def get_graphical_representation(self, cr, uid, model_ids, context=None):
75
obj_model = self.pool.get('ir.model')
74
76
if context is None:
78
for obj in self.pool.get('ir.model').browse(cr, uid, model_ids, context=context):
80
for obj in obj_model.browse(cr, uid, model_ids, context=context):
79
81
models.append(obj.model)
80
82
relations = set(self._get_graphical_representation(cr, uid, model_ids, context.get('level', 1)))
81
83
res[obj.model] = "digraph G {\nnode [style=rounded, shape=record];\n%s\n%s }" % (
99
101
def get_relation_graph(self, cr, uid, module_name, context=None):
100
102
object_ids = self._get_module_objects(cr, uid, module_name, context=context)
104
return {'module_file': False}
102
105
# raise orm.except_orm(_('Warning'),
103
106
# _('No object available on this module or Module is not installed'))
105
return {'module_file': False}
106
107
context.update({'level': 1})
107
108
dots = self.get_graphical_representation(cr, uid, object_ids, context=context)
108
109
# todo: use os.realpath