[MERGE]: Merge with lp:~openerp-commiter/openobject-addons/crm-improvement

bzr revid: rpa@tinyerp.com-20100317134902-5k1m34vzz6tg3xpe
This commit is contained in:
rpa (Open ERP)
2010-03-17 19:19:02 +05:30
13 changed files with 1311 additions and 826 deletions
+226 -154
View File
@@ -19,10 +19,7 @@
#
##############################################################################
import string
import time
import tools
from osv import fields,osv,orm
from osv import fields, osv
from tools.translate import _
class report_creator(osv.osv):
@@ -36,51 +33,74 @@ class report_creator(osv.osv):
# Should request only used fields
#
def export_data(self, cr, uid, ids, fields_to_export, context=None):
if not context:
context = {}
data_l = self.read(cr, uid, ids, ['sql_query'], context)
final_datas =[]
final_datas = []
#start Loop
for i in data_l:
datas = []
for key,value in i.items():
for key, value in i.items():
if key not in fields_to_export:
continue
if isinstance(value,tuple):
if isinstance(value, tuple):
datas.append(str(value[1]))
else:
datas.append(str(value))
final_datas += [datas]
#End Loop
return {'datas':final_datas}
return {'datas': final_datas}
def fields_get(self, cr, user, fields=None, context=None):
"""
Get Fields.
@param cr: the current row, from the database cursor,
@param user: the current user’s ID for security checks,
@param Fields: List of field of customer reports form.
@return: Dictionary of Fields
"""
if not context:
context = {}
data = context and context.get('report_id', False) or False
if (not context) or 'report_id' not in context:
return super(report_creator, self).fields_get(cr, user, fields, context)
report = self.browse(cr, user, context['report_id'])
models = {}
if data:
report = self.browse(cr, user, data)
models = {}
#Start Loop
for model in report.model_ids:
models[model.model] = self.pool.get(model.model).fields_get(cr, user, context=context)
#End Loop
fields = {}
i = 0
for f in report.field_ids:
if f.field_id.model:
fields['field'+str(i)] = models[f.field_id.model][f.field_id.name]
i+=1
else:
fields['column_count'] = {'readonly': True, 'type': 'integer', 'string': 'Count', 'size': 64, 'name': 'column_count'}
return fields
for model in report.model_ids:
models[model.model] = self.pool.get(model.model).fields_get(cr, user, context=context)
#End Loop
fields = {}
i = 0
for f in report.field_ids:
if f.field_id.model:
fields['field'+str(i)] = models[f.field_id.model][f.field_id.name]
i += 1
else:
fields['column_count'] = {'readonly': True, 'type': 'integer', 'string': 'Count', 'size': 64, 'name': 'column_count'}
return fields
#
# Should Call self.fields_get !
#
def fields_view_get(self, cr, user, view_id=None, view_type='form', context=None, toolbar=False, submenu=False):
"""
Overrides orm field_view_get.
@param cr: the current row, from the database cursor,
@param user: the current user’s ID for security checks,
@return: Dictionary of Fields, arch and toolbar.
"""
if not context:
context = {}
data = context and context.get('report_id', False) or False
if (not context) or 'report_id' not in context:
return super(report_creator, self).fields_view_get(cr, user, view_id, view_type, context, toolbar=toolbar, submenu=submenu)
report = self.browse(cr, user, context['report_id'])
report = self.browse(cr, user, data)
models = {}
for model in report.model_ids:
models[model.model] = self.pool.get(model.model).fields_get(cr, user, context=context)
@@ -89,33 +109,33 @@ class report_creator(osv.osv):
for f in report.field_ids:
if f.field_id.model:
fields['field'+str(i)] = models[f.field_id.model][f.field_id.name]
i+=1
i += 1
else:
fields['column_count'] = {'readonly': True, 'type': 'integer', 'string': 'Count', 'size': 64, 'name': 'column_count'}
arch = '<?xml version="1.0" encoding="utf-8"?>\n'
if view_type=='graph':
arch +='<graph string="%s" type="%s" orientation="%s">' % (report.name, report.view_graph_type,report.view_graph_orientation)
if view_type == 'graph':
arch += '<graph string="%s" type="%s" orientation="%s">' % (report.name, report.view_graph_type, report.view_graph_orientation)
for val in ('x','y'):
i = 0
for f in report.field_ids:
if f.graph_mode==val:
if f.graph_mode == val:
if f.field_id.model:
arch += '<field name="%s" select="1"/>' % ('field'+str(i),)
i+=1
i += 1
else:
arch += '<field name="%s" select="1"/>' % ('column_count',)
elif view_type=='calendar':
required_types = ['date_start','date_delay','color']
set_dict = {'view_type':view_type,'string':report.name}
elif view_type == 'calendar':
required_types = ['date_start', 'date_delay', 'color']
set_dict = {'view_type':view_type, 'string':report.name}
temp_list = []
i=0
i = 0
for f in report.field_ids:
if f.calendar_mode and f.calendar_mode in required_types:
if f.field_id.model:
field_cal = 'field'+str(i)
i+=1
i += 1
else:
field_cal = 'column_count'
set_dict[f.calendar_mode] = field_cal
@@ -123,20 +143,20 @@ class report_creator(osv.osv):
else:
if f.field_id.model:
temp_list.append('''<field name="%(name)s" select="1"/>''' % {'name':'field'+str(i)})
i+=1
temp_list.append('''<field name = "%(name)s" select = "1"/>''' % {'name': 'field' + str(i)})
i += 1
else:
temp_list.append('''<field name="%(name)s" select="1"/>''' % {'name':'column_count'})
arch += '''<%(view_type)s string="%(string)s" date_start="%(date_start)s" ''' %set_dict
if set_dict.get('date_delay',False):
arch +=''' date_delay="%(date_delay)s" '''%set_dict
arch += '''<% (view_type)s string = "%(string)s" date_start = "%(date_start)s" ''' % set_dict
if set_dict.get('date_delay', False):
arch += ''' date_delay = "%(date_delay)s" ''' % set_dict
if set_dict.get('date_stop',False):
arch +=''' date_stop="%(date_stop)s" '''%set_dict
if set_dict.get('date_stop', False):
arch += ''' date_stop="%(date_stop)s" '''%set_dict
if set_dict.get('color',False):
arch +=''' color="%(color)s"'''%set_dict
if set_dict.get('color', False):
arch += ''' color="%(color)s"'''%set_dict
arch += '''>'''
arch += ''.join(temp_list)
else:
@@ -144,8 +164,8 @@ class report_creator(osv.osv):
i = 0
for f in report.field_ids:
if f.field_id.model:
arch += '<field name="%s" select="1"/>' % ('field'+str(i),)
i+=1
arch += '<field name="%s" select="1"/>' % ('field' + str(i),)
i += 1
else:
arch += '<field name="%s" select="1"/>' % ('column_count',)
arch += '</%s>' % (view_type,)
@@ -158,33 +178,53 @@ class report_creator(osv.osv):
'action': [],
'relate': []
}
return result
def read(self, cr, user, ids, fields = None, context = None, load = '_classic_read'):
"""
overrides orm Read method.Read List of fields for report creator.
@param cr: the current row, from the database cursor,
@param user: the current user’s ID for security checks,
@param ids: List of report creator's id.
@param fields: List of fields.
@return: List of Dictionary of form [{‘name_of_the_field’: value, ...}, ...]
"""
data = context and context.get('report_id', False) or False
if (not context) or 'report_id' not in context:
return super(report_creator, self).read(cr, user, ids, fields, context, load)
ctx = context or {}
wp = ''
if self.model_set_id:
wp = [self._id_get(cr, user, context['report_id'], context)+(' in (%s)' % (','.join(map(lambda x: "'"+str(x)+"'",ids))))]
report = self._sql_query_get(cr, user, [context['report_id']], 'sql_query', None, ctx, where_plus = wp)
sql_query = report[context['report_id']]
cr.execute(sql_query)
res = cr.dictfetchall()
fields_get = self.fields_get(cr,user,None,context)
for r in res:
for k in r:
r[k] = r[k] or False
field_dict = fields_get.get(k)
field_type = field_dict and field_dict.get('type',False) or False
if field_type and field_type == 'many2one':
if r[k]==False:
continue
related_name = self.pool.get(field_dict.get('relation')).name_get(cr,user,[r[k]],context)[0]
r[k] = related_name
return res
if data:
if self.model_set_id:
wp = [self._id_get(cr, user, data, context) + (' in (%s)' % (','.join(map(lambda x: "'" + str(x) + "'", ids))))]
report = self._sql_query_get(cr, user, [data], 'sql_query', None, ctx, where_plus = wp)
sql_query = report[data]
cr.execute(sql_query)
res = cr.dictfetchall()
fields_get = self.fields_get(cr, user, None, context)
for r in res:
for k in r:
r[k] = r[k] or False
field_dict = fields_get.get(k)
field_type = field_dict and field_dict.get('type', False) or False
if field_type and field_type == 'many2one':
if r[k] == False:
continue
related_name = self.pool.get(field_dict.get('relation')).name_get(cr, user, [r[k]], context)[0]
r[k] = related_name
return res
def search(self, cr, user, args, offset=0, limit=None, order=None, context=None, count=False):
"""
overrides orm search method.
@param cr: the current row, from the database cursor,
@param user: the current user’s ID for security checks,
@param args: list of tuples of form [(‘name_of_the_field’, ‘operator’, value), ...].
@return: List of id
"""
context_id = context and context.get('report_id', False) or False
if (not context) or 'report_id' not in context:
@@ -196,16 +236,16 @@ class report_creator(osv.osv):
for f in report.field_ids:
if f.field_id.model:
fields['field'+str(i)] = (f.field_id.model, f.field_id.name)
i+=1
i += 1
else:
fields['column_count'] = (False, 'Count')
newargs = []
newargs2 = []
for a in args:
if fields[a[0]][0]:
res = self.pool.get(fields[a[0]][0])._where_calc(cr, user, [[fields[a[0]][1],a[1],a[2]]], active_test = False, context = context)
newargs+=res[0]
newargs2+=res[1]
res = self.pool.get(fields[a[0]][0])._where_calc(cr, user, [[fields[a[0]][1], a[1], a[2]]], active_test = False, context = context)
newargs += res[0]
newargs2 += res[1]
else:
newargs += [("count(*) " + a[1] +" " + str(a[2]))]
ctx = context or {}
@@ -216,8 +256,12 @@ class report_creator(osv.osv):
result = cr.fetchall()
return map(lambda x: x[0], result)
def _path_get(self,cr, uid, models, filter_ids=[]):
def _path_get(self, cr, uid, models, filter_ids=[]):
"""
@param cr: the current row, from the database cursor,
@param uid: the current user’s ID for security checks,
@param models: List of object.
"""
self.model_set_id = False
model_dict = {}
from_list = []
@@ -225,7 +269,7 @@ class report_creator(osv.osv):
filter_list = []
for model in models:
model_dict[model.model] = self.pool.get(model.model)._table
model_list = model_dict.keys()
reference_model_dict = {}
for model in model_dict:
@@ -233,7 +277,7 @@ class report_creator(osv.osv):
rest_list = model_dict.keys()
rest_list.remove(model)
model_pool = self.pool.get(model)
fields_get = model_pool.fields_get(cr,uid)
fields_get = model_pool.fields_get(cr, uid)
model_columns = {}
def _get_inherit_fields(obj):
@@ -242,24 +286,24 @@ class report_creator(osv.osv):
model_columns.update(pool_model._columns)
#Adding the columns of its _inherits
for record in pool_model._inherits.keys():
_get_inherit_fields(record)
_get_inherit_fields(record)
_get_inherit_fields(model)
fields_filter = dict(filter(lambda x:x[1].get('relation',False)
fields_filter = dict(filter(lambda x:x[1].get('relation', False)
and x[1].get('relation') in rest_list
and x[1].get('type')=='many2one'
and not (isinstance(model_columns[x[0]],fields.function) or isinstance(model_columns[x[0]],fields.related)), fields_get.items()))
and x[1].get('type') == 'many2one'
and not (isinstance(model_columns[x[0]], fields.function) or isinstance(model_columns[x[0]], fields.related)), fields_get.items()))
if fields_filter:
model in model_list and model_list.remove(model)
model_count = reference_model_dict.get(model,False)
model_count = reference_model_dict.get(model, False)
if model_count:
reference_model_dict[model] = model_count +1
else:
reference_model_dict[model] = 1
for k,v in fields_filter.items():
for k, v in fields_filter.items():
v.get('relation') in model_list and model_list.remove(v.get('relation'))
relation_count = reference_model_dict.get(v.get('relation'),False)
relation_count = reference_model_dict.get(v.get('relation'), False)
if relation_count:
reference_model_dict[v.get('relation')] = relation_count+1
else:
@@ -271,9 +315,9 @@ class report_creator(osv.osv):
if reference_model_dict:
self.model_set_id = model_dict.get(reference_model_dict.keys()[reference_model_dict.values().index(min(reference_model_dict.values()))])
if model_list and not len(model_dict.keys()) == 1:
raise osv.except_osv(_('No Related Models!!'),_('These is/are model(s) (%s) in selection which is/are not related to any other model') % ','.join(model_list))
raise osv.except_osv(_('No Related Models!!'), _('These is/are model(s) (%s) in selection which is/are not related to any other model') % ','.join(model_list))
if filter_ids and where_list<>[]:
if filter_ids and where_list <> []:
filter_list.append(' and ')
filter_list.append(' ')
@@ -288,25 +332,32 @@ class report_creator(osv.osv):
else:
ret_str = ",\n".join(from_list)
if where_list:
where_list = list(set(where_list))
ret_str+="\n where \n"+" and\n".join(where_list)
ret_str += "\n where \n"+" and\n".join(where_list)
ret_str = ret_str.strip()
if filter_list:
ret_str +="\n".join(filter_list)
ret_str += "\n".join(filter_list)
if ret_str.endswith('and'):
ret_str = ret_str[0:len(ret_str)-3]
if ret_str.endswith('or'):
ret_str = ret_str[0:len(ret_str)-2]
ret_str = ret_str.strip()
return ret_str % {'uid' : uid}
return ret_str % {'uid': uid}
def _id_get(self, cr, uid, id, context):
"""
Get Model id
"""
# return 'min(sale_order_line.id)'
return self.model_set_id and 'min('+self.model_set_id+'.id)'
def _sql_query_get(self, cr, uid, ids, prop, unknow_none, context, where_plus=[], limit=None, offset=None):
"""
Get sql query which return on sql_query field.
@return: Dictionary of sql query.
"""
result = {}
for obj in self.browse(cr, uid, ids):
fields = []
@@ -315,7 +366,7 @@ class report_creator(osv.osv):
for f in obj.field_ids:
# Allowing to use count(*)
if not f.field_id.model and f.group_method == 'count':
fields.insert(0,('count(*) as column_count'))
fields.insert(0, ('count(*) as column_count'))
continue
t = self.pool.get(f.field_id.model_id.model)._table
if f.group_method == 'group':
@@ -323,11 +374,11 @@ class report_creator(osv.osv):
else:
fields.append('\t'+f.group_method+'('+t+'.'+f.field_id.name+')'+' as field'+str(i))
groupby.append(t+'.'+f.field_id.name)
i+=1
i += 1
models = self._path_get(cr, uid, obj.model_ids, obj.filter_ids)
check = self._id_get(cr, uid, ids[0], context)
if check<>False:
fields.insert(0,(check+' as id'))
fields.insert(0, (check + ' as id'))
if models:
result[obj.id] = """select
@@ -348,49 +399,58 @@ class report_creator(osv.osv):
return result
_columns = {
'name': fields.char('Report Name',size=64, required=True),
'type': fields.selection([('list', 'Rows And Columns Report'), ], 'Report Type', required=True),#('sum','Summation Report')
'active': fields.boolean('Active', help="If the active field is set to true, it will allow you to hide the report without removing it."),
'view_type1': fields.selection([('form','Form'),
('tree','Tree'),
('graph','Graph'),
('calendar','Calendar')], 'First View', required=True),
'view_type2': fields.selection([('','/'),
('form','Form'),
('tree','Tree'),
('graph','Graph'),
('calendar','Calendar')], 'Second View'),
'view_type3': fields.selection([('','/'),
('form','Form'),
('tree','Tree'),
('graph','Graph'),
('calendar','Calendar')], 'Third View'),
'view_graph_type': fields.selection([('pie','Pie Chart'),
('bar','Bar Chart')], 'Graph Type', required=True),
'view_graph_orientation': fields.selection([('horz','Horizontal'),
('vert','Vertical')], 'Graph Orientation', required=True),
'model_ids': fields.many2many('ir.model', 'base_report_creator_report_model_rel', 'report_id','model_id', 'Reported Objects'),
'field_ids': fields.one2many('base_report_creator.report.fields', 'report_id', 'Fields to Display'),
'filter_ids': fields.one2many('base_report_creator.report.filter', 'report_id', 'Filters'),
'name': fields.char('Report Name', size=64, required=True),
'type': fields.selection([('list', 'Rows And Columns Report'), ], 'Report Type', required=True), #('sum','Summation Report')
'active': fields.boolean('Active', help="If the active field is set to true, it will allow you to hide the report without removing it."),
'view_type1': fields.selection([('form', 'Form'),
('tree', 'Tree'),
('graph', 'Graph'),
('calendar', 'Calendar')], 'First View', required=True),
'view_type2': fields.selection([('', '/'),
('form', 'Form'),
('tree', 'Tree'),
('graph', 'Graph'),
('calendar', 'Calendar')], 'Second View'),
'view_type3': fields.selection([('', '/'),
('form', 'Form'),
('tree', 'Tree'),
('graph', 'Graph'),
('calendar', 'Calendar')], 'Third View'),
'view_graph_type': fields.selection([('pie', 'Pie Chart'),
('bar', 'Bar Chart')], 'Graph Type', required=True),
'view_graph_orientation': fields.selection([('horz', 'Horizontal'),
('vert', 'Vertical')], 'Graph Orientation', required=True),
'model_ids': fields.many2many('ir.model', 'base_report_creator_report_model_rel', 'report_id', 'model_id', 'Reported Objects'),
'field_ids': fields.one2many('base_report_creator.report.fields', 'report_id', 'Fields to Display'),
'filter_ids': fields.one2many('base_report_creator.report.filter', 'report_id', 'Filters'),
'state': fields.selection([
('draft','Draft'),
('valid','Valid')],
'State', required=True,
('draft', 'Draft'),
('valid', 'Valid')],
'State', required=True,
help=' * The \'Draft\' state is used when a user is encoding a new and unconfirmed custom report. \
\n* The \'Valid\' state is used when user validates the custom report.'),
'sql_query': fields.function(_sql_query_get, method=True, type="text", string='SQL Query', store=True),
'group_ids': fields.many2many('res.groups', 'base_report_creator_group_rel','report_id','group_id','Authorized Groups'),
\n* The \'Valid\' state is used when user validates the custom report.'),
'sql_query': fields.function(_sql_query_get, method=True, type="text", string='SQL Query', store=True),
'group_ids': fields.many2many('res.groups', 'base_report_creator_group_rel', 'report_id', 'group_id', 'Authorized Groups'),
}
_defaults = {
'type': lambda *args: 'list',
'state': lambda *args: 'draft',
'active': lambda *args: True,
'view_type1': lambda *args: 'tree',
'view_type2': lambda *args: 'graph',
'view_graph_type': lambda *args: 'bar',
'view_graph_orientation': lambda *args: 'horz',
'type': lambda *args: 'list',
'state': lambda *args: 'draft',
'active': lambda *args: True,
'view_type1': lambda *args: 'tree',
'view_type2': lambda *args: 'graph',
'view_graph_type': lambda *args: 'bar',
'view_graph_orientation': lambda *args: 'horz',
}
def _function_field(self, cr, uid, ids):
"""
constraints function which specify that
not display field which are not stored in Database.
@param cr: the current row, from the database cursor,
@param uid: the current user’s ID for security checks,
@param ids: List of Report creator's id.
@return: True if display field which are stored in database.
or false if display field which are not store in dtabase.
"""
this_objs = self.browse(cr, uid, ids)
for obj in this_objs:
for fld in obj.field_ids:
@@ -398,13 +458,23 @@ class report_creator(osv.osv):
if not fld.field_id.model and fld.group_method == 'count':
continue
model_column = self.pool.get(fld.field_id.model)._columns[fld.field_id.name]
if (isinstance(model_column,fields.function) or isinstance(model_column,fields.related)) and not model_column.store:
if (isinstance(model_column, fields.function) or isinstance(model_column, fields.related)) and not model_column.store:
return False
return True
def _aggregation_error(self, cr, uid, ids):
aggregate_columns = ('integer','float')
apply_functions = ('sum','min','max','avg','count')
"""
constraints function which specify that
aggregate function to the non calculated field..
@param cr: the current row, from the database cursor,
@param uid: the current user’s ID for security checks,
@param ids: List of Report creator's id.
@return: True if model colume type is in integer or float.
or false model colume type is not in integer or float.
"""
aggregate_columns = ('integer', 'float')
apply_functions = ('sum', 'min', 'max', 'avg', 'count')
this_objs = self.browse(cr, uid, ids)
for obj in this_objs:
for fld in obj.field_ids:
@@ -421,7 +491,7 @@ class report_creator(osv.osv):
required_types = []
this_objs = self.browse(cr, uid, ids)
for obj in this_objs:
if obj.view_type1=='calendar' or obj.view_type2=='calendar' or obj.view_type3=='calendar':
if obj.view_type1 == 'calendar' or obj.view_type2 == 'calendar' or obj.view_type3 == 'calendar':
for fld in obj.field_ids:
# Allowing to use count(*)
if not fld.field_id.model and fld.group_method == 'count':
@@ -438,12 +508,13 @@ class report_creator(osv.osv):
return True
_constraints = [
(_function_field, 'You can not display field which are not stored in Database.', ['field_ids']),
(_aggregation_error, 'You can apply aggregate function to the non calculated field.', ['field_ids']),
(_calander_view_error, "You must have to give calendar view's color,start date and delay.", ['field_ids']),
(_function_field, 'You can not display field which are not stored in Database.', ['field_ids']),
(_aggregation_error, 'You can apply aggregate function to the non calculated field.', ['field_ids']),
(_calander_view_error, "You must have to give calendar view's color,start date and delay.", ['field_ids']),
]
report_creator()
class report_creator_field(osv.osv):
"""
Report Creator Field
@@ -453,28 +524,29 @@ class report_creator_field(osv.osv):
_rec_name = 'field_id'
_order = "sequence,id"
_columns = {
'sequence': fields.integer('Sequence', help="Gives the sequence order when displaying a list of fields."),
'field_id': fields.many2one('ir.model.fields', 'Field'),
'report_id': fields.many2one('base_report_creator.report','Report', on_delete='cascade'),
'group_method': fields.selection([('group','Grouped'),
('sum','Sum'),
('min','Minimum'),
('count','Count'),
('max','Maximum'),
('avg','Average')], 'Grouping Method', required=True),
'graph_mode': fields.selection([('','/'),
('x','X Axis'),
('y','Y Axis')], 'Graph Mode'),
'calendar_mode': fields.selection([('','/'),
('date_start','Starting Date'),
('date_end','Ending Date'),('date_delay','Delay'),('date_stop','End Date'),('color','Unique Colors')], 'Calendar Mode'),
'sequence': fields.integer('Sequence', help="Gives the sequence order when displaying a list of fields."),
'field_id': fields.many2one('ir.model.fields', 'Field'),
'report_id': fields.many2one('base_report_creator.report', 'Report', on_delete='cascade'),
'group_method': fields.selection([('group', 'Grouped'),
('sum', 'Sum'),
('min', 'Minimum'),
('count', 'Count'),
('max', 'Maximum'),
('avg', 'Average')], 'Grouping Method', required=True),
'graph_mode': fields.selection([('', '/'),
('x', 'X Axis'),
('y', 'Y Axis')], 'Graph Mode'),
'calendar_mode': fields.selection([('', '/'),
('date_start', 'Starting Date'),
('date_end', 'Ending Date'), ('date_delay', 'Delay'), ('date_stop', 'End Date'), ('color', 'Unique Colors')], 'Calendar Mode'),
}
_defaults = {
'group_method': lambda *args: 'group',
'graph_mode': lambda *args: '',
'group_method': lambda *args: 'group',
'graph_mode': lambda *args: '',
}
report_creator_field()
class report_creator_filter(osv.osv):
"""
Report Creator Filter
@@ -482,14 +554,14 @@ class report_creator_filter(osv.osv):
_name = "base_report_creator.report.filter"
_description = "Report Filters"
_columns = {
'name': fields.char('Filter Name',size=64, required=True),
'expression': fields.text('Value', required=True, help='Provide an expression for the field based on which you want to filter the records.\n e.g. res_partner.id=3'),
'report_id': fields.many2one('base_report_creator.report', 'Report', on_delete='cascade'),
'condition' : fields.selection([('and','AND'),
('or','OR')], 'Condition')
'name': fields.char('Filter Name', size=64, required=True),
'expression': fields.text('Value', required=True, help='Provide an expression for the field based on which you want to filter the records.\n e.g. res_partner.id=3'),
'report_id': fields.many2one('base_report_creator.report', 'Report', on_delete='cascade'),
'condition': fields.selection([('and', 'AND'),
('or', 'OR')], 'Condition')
}
_defaults = {
'condition': lambda *args: 'and',
'condition': lambda *args: 'and',
}
report_creator_filter()
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
@@ -41,7 +41,8 @@
<field name="active" select="2"/>
<notebook colspan="4">
<page string="General Configuration">
<field name="model_ids" colspan="4" context="{'model_ids':model_ids}"/>
<field name="model_ids" colspan="4"
context="{'model_ids':model_ids}" />
<separator string="State" colspan="4"/>
<field name="state"/>
<button string="Create Menu"
@@ -1,4 +1,5 @@
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
access_base_report_creator_report,base_report_creator.report,model_base_report_creator_report,base.group_system,1,1,1,1
access_base_report_creator_report_fields,base_report_creator.report.fields,model_base_report_creator_report_fields,base.group_system,1,1,1,1
access_base_report_creator_report_filter,base_report_creator.report.filter,model_base_report_creator_report_filter,base.group_system,1,1,1,1
"id","name","model_id:id","group_id:id","perm_read","perm_write","perm_create","perm_unlink"
"access_base_report_creator_report","base_report_creator.report","model_base_report_creator_report","base.group_system",1,1,1,1
"access_base_report_creator_report_fields","base_report_creator.report.fields","model_base_report_creator_report_fields","base.group_system",1,1,1,1
"access_base_report_creator_report_filter","base_report_creator.report.filter","model_base_report_creator_report_filter","base.group_system",1,1,1,1
"access_report_menu_create","report.menu.create","model_report_menu_create","base.group_system",1,1,1,1
1 id name model_id:id group_id:id perm_read perm_write perm_create perm_unlink
2 access_base_report_creator_report base_report_creator.report model_base_report_creator_report base.group_system 1 1 1 1
3 access_base_report_creator_report_fields base_report_creator.report.fields model_base_report_creator_report_fields base.group_system 1 1 1 1
4 access_base_report_creator_report_filter base_report_creator.report.filter model_base_report_creator_report_filter base.group_system 1 1 1 1
5 access_report_menu_create report.menu.create model_report_menu_create base.group_system 1 1 1 1
@@ -38,18 +38,18 @@ class report_menu_create(osv.osv_memory):
@param cr: the current row, from the database cursor,
@param uid: the current user’s ID for security checks,
@param ids: List of Report Menu Create's IDs
@return : Dictionary {}.
@return: Dictionary {}.
"""
if not context:
context={}
context = {}
context_id = context and context.get('active_id', False) or False
if context_id:
board = self.pool.get('base_report_creator.report').browse(cr, uid, context_id)
view = board.view_type1
if board.view_type2:
view+=','+board.view_type2
view += ',' + board.view_type2
if board.view_type3:
view+=','+board.view_type3
view += ',' + board.view_type3
action_id = self.pool.get('ir.actions.act_window').create(cr, uid, {
'name': board.name,
'view_type':'form',
@@ -64,7 +64,7 @@ class report_menu_create(osv.osv_memory):
'name': data.get('menu_name'),
'parent_id': data.get('menu_parent_id'),
'icon': 'STOCK_SELECT_COLOR',
'action': 'ir.actions.act_window,'+str(action_id)
'action': 'ir.actions.act_window, ' + str(action_id)
}, context=context)
return {}
#End Loop
+13 -20
View File
@@ -1,28 +1,21 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Copyright (c) 2004 TINY SPRL. (http://tiny.be) All Rights Reserved.
# Fabien Pinckaers <fp@tiny.Be>
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsability of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# garantees and support are strongly adviced to contract a Free Software
# Service Company
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
+23 -1
View File
@@ -1,3 +1,24 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
{
"name" : "Olap Schemes Management",
"version" : "0.1",
@@ -17,7 +38,8 @@
"data/olap_cube_view.xml",
"data/olap_fact_view.xml",
"data/olap_cube_workflow.xml",
"data/olap_security.xml"
"data/olap_security.xml",
'security/ir.model.access.csv'
],
"demo_xml" : ["data/olap_demo.xml"],
"active": False,
+878 -464
View File
File diff suppressed because it is too large Load Diff
+13 -19
View File
@@ -1,27 +1,21 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Copyright (c) 2005-2006 TINY SPRL. (http://tiny.be) All Rights Reserved.
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsability of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# garantees and support are strongly adviced to contract a Free Software
# Service Company
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
+22 -30
View File
@@ -1,37 +1,32 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Copyright (c) 2005-2006 TINY SPRL. (http://tiny.be) All Rights Reserved.
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsability of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# garantees and support are strongly adviced to contract a Free Software
# Service Company
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from osv import fields, osv
from osv import osv
class olap_load_column(osv.osv_memory):
_name = "olap.load.column"
_description = "Olap Load Column"
def get_table_data(self, cr, uid, ids, context={}):
"""
This function load column
@param cr: the current row, from the database cursor,
@@ -41,13 +36,13 @@ class olap_load_column(osv.osv_memory):
"""
data = context and context.get('active_id', False) or False
ids_cols = self.pool.get('olap.database.columns').search(cr, uid,\
([('table_id','=',data)]),context={})
model_data_ids = self.pool.get('ir.model.data').search(cr,uid,\
[('model','=','ir.ui.view'),\
('name','=','view_olap_database_columns_form')],context={})
resource_id = self.pool.get('ir.model.data').read(cr,uid,\
model_data_ids,fields=['res_id'])[0]['res_id']
ids_cols = self.pool.get('olap.database.columns').search(cr, uid, \
([('table_id', '=', data)]), context={})
model_data_ids = self.pool.get('ir.model.data').search(cr, uid, \
[('model', '=', 'ir.ui.view'), \
('name', '=', 'view_olap_database_columns_form')], context={})
resource_id = self.pool.get('ir.model.data').read(cr, uid, \
model_data_ids, fields=['res_id'])[0]['res_id']
return {
'domain': "[('id','in', ["+','.join(map(str,ids_cols))+"])]",
'name': 'Database Columns',
@@ -57,9 +52,6 @@ class olap_load_column(osv.osv_memory):
'views': [(False,'tree'),(resource_id,'form')],
'type': 'ir.actions.act_window',
}
_columns = {
}
olap_load_column()
+5 -1
View File
@@ -2,7 +2,7 @@
<openerp>
<data>
<!-- Open Column -->
<!-- Open Column From View -->
<record id="view_olap_load_column" model="ir.ui.view">
<field name="name">Open Columns</field>
@@ -16,6 +16,8 @@
</field>
</record>
<!-- Open Column Action -->
<record id="action_olap_load_column" model="ir.actions.act_window">
<field name="name">Open Columns</field>
<field name="type">ir.actions.act_window</field>
@@ -26,6 +28,8 @@
<field name="target">new</field>
</record>
<!-- Open Column Action Window -->
<act_window id="action_olap_load_column_values"
key2="client_action_multi" name="Open Columns"
res_model="olap.load.column" src_model="olap.database.columns"
+25 -32
View File
@@ -1,27 +1,21 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Copyright (c) 2005-2006 TINY SPRL. (http://tiny.be) All Rights Reserved.
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsability of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# garantees and support are strongly adviced to contract a Free Software
# Service Company
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
@@ -30,19 +24,20 @@ from osv import fields, osv
class olap_query_logs_clear(osv.osv_memory):
_name = "olap.query.logs.clear"
_description = "Olap Query Logs Clear"
_columns = {
'user_name':fields.char('User',size=64,required=True,readonly=True),
'user_name':fields.char('User', size=64, required=True, readonly=True),
}
def _getdata(self,cr,uid,context={}):
user = self.pool.get('res.users').browse(cr,uid,uid)
def _getdata(self, cr, uid, context={}):
user = self.pool.get('res.users').browse(cr, uid, uid)
return user.name
_defaults = {
'user_name': _getdata
}
def clear_logs(self,cr,uid,part,context={}):
def clear_logs(self, cr, uid, part, context={}):
"""
This function load column
@param cr: the current row, from the database cursor,
@@ -50,18 +45,18 @@ class olap_query_logs_clear(osv.osv_memory):
@param ids: List of load column,
@return: dictionary of query logs clear message window
"""
ids = self.pool.get('olap.query.logs').search(cr,uid,[('user_id','=',uid)])
self.pool.get('olap.query.logs').unlink(cr, uid,ids,context)
ids = self.pool.get('olap.query.logs').search(cr, uid, [('user_id', '=', uid)])
self.pool.get('olap.query.logs').unlink(cr, uid, ids, context)
data_obj = self.pool.get('ir.model.data')
id2 = data_obj._get_id(cr, uid, 'olap', 'view_olap_query_logs_clear_msg')
if id2:
id2 = data_obj.browse(cr, uid, id2, context=context).res_id
value = {
'view_type': 'form',
'view_mode': 'form',
'res_model': 'olap.query.logs.clear.msg',
'views': [(id2,'form'),(False,'tree'),(False,'calendar'),(False,'graph')],
'type': 'ir.actions.act_window',
'view_type': 'form',
'view_mode': 'form',
'res_model': 'olap.query.logs.clear.msg',
'views': [(id2, 'form'), (False, 'tree'), (False, 'calendar'), (False, 'graph')],
'type': 'ir.actions.act_window',
'target': 'new'
}
return value
@@ -73,9 +68,7 @@ class olap_query_logs_clear_msg(osv.osv_memory):
""" Display clear log message """
_name = "olap.query.logs.clear.msg"
_description = "Olap Query Logs Clear Message"
_columns = {
}
olap_query_logs_clear_msg()
# vim: ts=4 sts=4 sw=4 si et
@@ -2,7 +2,7 @@
<openerp>
<data>
<!-- Create Logs -->
<!-- Create Logs Form View -->
<record id="view_olap_query_logs_clear" model="ir.ui.view">
<field name="name">Clear Logs</field>
@@ -21,6 +21,8 @@
</field>
</record>
<!-- Create Logs Action -->
<record id="action_view_olap_query_logs_clear" model="ir.actions.act_window">
<field name="name">Clear Logs </field>
<field name="type">ir.actions.act_window</field>
@@ -30,6 +32,8 @@
<field name="target">new</field>
</record>
<!-- Clear Logs Form View -->
<record id="view_olap_query_logs_clear_msg" model="ir.ui.view">
<field name="name">Clear Logs Message</field>
<field name="model">olap.query.logs.clear.msg</field>
+89 -94
View File
@@ -1,29 +1,24 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Copyright (c) 2005-2006 TINY SPRL. (http://tiny.be) All Rights Reserved.
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsability of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# garantees and support are strongly adviced to contract a Free Software
# Service Company
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
import psycopg2
import time
@@ -41,11 +36,11 @@ form1 = '''<?xml version="1.0"?>
<form string="Load Database Structure">
<label align="0.0" string="We will load the complete structure of the database by introspection,
so that you will be able to work on it, and specify a better structure
so that you will be able to work on it, and specify a better structure
according to your reporting needs." colspan="4" />
<newline/>
<label align="0.0" string="After having loaded the structure, you will be able to hide/show or
rename tables and columns to simplify end-users interface. The following database
<label align="0.0" string="After having loaded the structure, you will be able to hide/show or
rename tables and columns to simplify end-users interface. The following database
will be loaded:" colspan="4"/>
<field align="0.0" name='fact_table'/>
<newline/>
@@ -81,37 +76,37 @@ def olap_db_connect(self,cr,uid,part,context={}):
cr.execute('select column_db_name,id,table_id from olap_database_columns where table_id in (' + ','.join(tables_id) +')')
else:
cr.execute('select column_db_name,id,table_id from olap_database_columns')
for data in cr.fetchall():
cols[str(data[1])]=(data[0],int(data[2]))
print 'Creating / Updating Tables...'
print 'Creating / Updating Tables...'
cr_db.execute("select table_name, table_catalog from INFORMATION_SCHEMA.tables as a where a.table_schema = 'public'")
for table in cr_db.fetchall():
val = {
'fact_database_id':id_db,
'table_db_name':table[0]
}
if table[0] in tables.keys():
table_id=tobj.write(cr,uid,[tables[table[0]]], val, context)
else:
val['name']=table[0]
tables[val['name']] = tobj.create(cr,uid,val, context)
print 'Creating / Updating Columns...'
tables[val['name']] = tobj.create(cr,uid,val, context)
print 'Creating / Updating Columns...'
cr_db.execute("""SELECT
table_name, column_name, udt_name
from
INFORMATION_SCHEMA.columns
WHERE table_schema = 'public'""")
for col in cr_db.fetchall():
val={
'table_id': tables[col[0]],
'column_db_name': col[1],
'type': col[2],
}
id_made=filter(lambda x:(int(cols[x][1])==int(tables[col[0]])),cols)
if col[1] in cols.keys() and col[0] in tables.keys()and id_made:
col_id=tcol.write(cr,uid,cols[tables[str(col[0])]], val, context)
@@ -119,54 +114,54 @@ def olap_db_connect(self,cr,uid,part,context={}):
val['name']=col[1]
id_made = tcol.create(cr,uid,val, context)
cols[str(id_made)] = (val['name'],int(val['table_id']))
print 'Creating / Updating Constraints...'
cr_db.execute("""select
table_name,column_name
from
print 'Creating / Updating Constraints...'
cr_db.execute("""select
table_name,column_name
from
INFORMATION_schema.key_column_usage
where
where
constraint_name in (
select constraint_name from INFORMATION_SCHEMA .table_constraints
where
where
constraint_type = 'PRIMARY KEY')""")
print "Updating the Primary Key Constraint"
print "Updating the Primary Key Constraint"
for constraint in cr_db.fetchall():
val={
'primary_key':True
}
id_to_write=filter(lambda x:(int(cols[x][1])==int(tables[constraint[0]])and(constraint[1]==cols[x][0])),cols)
col_id=tcol.write(cr,uid,int(id_to_write[0]),val,context)
print "Updating the Foreign key constraint"
cr_db.execute("""select
constraint_name,table_name
from
INFORMATION_schema.constraint_column_usage
col_id=tcol.write(cr,uid,int(id_to_write[0]),val,context)
print "Updating the Foreign key constraint"
cr_db.execute("""select
constraint_name,table_name
from
INFORMATION_schema.constraint_column_usage
where
constraint_name in (
select constraint_name from INFORMATION_SCHEMA.table_constraints
where
select constraint_name from INFORMATION_SCHEMA.table_constraints
where
constraint_type = 'FOREIGN KEY')""")
for_key=dict(cr_db.fetchall())
cr_db.execute("""select
table_name,column_name,constraint_name
from
cr_db.execute("""select
table_name,column_name,constraint_name
from
INFORMATION_schema.key_column_usage
where
where
constraint_name in (
select constraint_name from INFORMATION_SCHEMA.table_constraints
where
constraint_type = 'FOREIGN KEY')""")
select constraint_name from INFORMATION_SCHEMA.table_constraints
where
constraint_type = 'FOREIGN KEY')""")
for constraint in cr_db.fetchall():
val={
'related_to':tables[for_key[constraint[2]]]
}
id_to_write=filter(lambda x:(int(cols[x][1])==int(tables[constraint[0]])and (constraint[1]==cols[x][0])),cols)
col_id=tcol.write(cr,uid,int(id_to_write[0]),val,context)
col_id=tcol.write(cr,uid,int(id_to_write[0]),val,context)
elif type =='mysql':
try:
import MySQLdb
@@ -176,10 +171,10 @@ def olap_db_connect(self,cr,uid,part,context={}):
user = lines.database_id.db_login or ''
passwd = lines.database_id.db_password or ''
tdb = MySQLdb.connect(host = host,port = port, db = db, user = user, passwd = passwd)
except Exception, e:
raise osv.except_osv('MySQLdb Packages Not Installed.',e )
cr_db = tdb.cursor()
cr.execute('select table_db_name,id from olap_database_tables where fact_database_id=%d', (id_db,))
tables = dict(cr.fetchall())
@@ -189,20 +184,20 @@ def olap_db_connect(self,cr,uid,part,context={}):
cr.execute('select column_db_name,id,table_id from olap_database_columns where table_id in (' + ','.join(tables_id) +')')
else:
cr.execute('select column_db_name,id,table_id from olap_database_columns')
for data in cr.fetchall():
cols[str(data[1])]=(data[0],int(data[2]))
cr_db.execute("select table_name, table_catalog from INFORMATION_SCHEMA.tables where table_schema =%s",(db_name))
for table in cr_db.fetchall():
val = {
'fact_database_id':id_db,
'table_db_name':table[0]
}
if table[0] in tables.keys():
table_id=tobj.write(cr,uid,[tables[table[0]]], val, context)
else:
val['name']=table[0]
tables[val['name']] = tobj.create(cr,uid,val, context)
@@ -211,15 +206,15 @@ def olap_db_connect(self,cr,uid,part,context={}):
from
INFORMATION_SCHEMA.columns
WHERE table_schema = %s""",(db_name))
for col in cr_db.fetchall():
val={
'table_id': tables[col[0]],
'column_db_name': col[1],
'type': col[2],
}
id_made=filter(lambda x:(int(cols[x][1])==int(tables[col[0]])),cols)
if col[1] in cols.keys() and col[0] in tables.keys()and id_made:
col_id=tcol.write(cr,uid,cols[tables[str(col[0])]], val, context)
@@ -227,32 +222,32 @@ def olap_db_connect(self,cr,uid,part,context={}):
val['name']=col[1]
id_made = tcol.create(cr,uid,val, context)
cols[str(id_made)] = (val['name'],int(val['table_id']))
cr_db.execute("""select
cr_db.execute("""select
REFERENCED_COLUMN_NAME,REFERENCED_TABLE_NAME,COLUMN_NAME,TABLE_NAME
from
from
INFORMATION_schema.key_column_usage
where table_schema= %s and
where table_schema= %s and
constraint_name in (
select constraint_name from INFORMATION_SCHEMA .table_constraints
where
where
constraint_type in('PRIMARY KEY','FOREIGN KEY'))
""",(db_name))
""",(db_name))
for constraint in cr_db.fetchall():
if constraint[0]:
val={
'related_to':tables[constraint[1]]
}
else:
val={
'primary_key':True
}
id_to_write=filter(lambda x:(int(cols[x][1])==int(tables[constraint[3]])and(constraint[2]==cols[x][0])),cols)
col_id=tcol.write(cr,uid,int(id_to_write[0]),val,context)
col_id=tcol.write(cr,uid,int(id_to_write[0]),val,context)
elif type == 'oracle':
try:
import cx_Oracle
@@ -262,7 +257,7 @@ def olap_db_connect(self,cr,uid,part,context={}):
user = lines.database_id.db_login.upper() or ''
passwd = lines.database_id.db_password or ''
tdb = cx_Oracle.connect(user, passwrd, host)
except Exception, e:
raise osv.except_osv('cx_Oracle Packages Not Installed.',e )
@@ -275,7 +270,7 @@ def olap_db_connect(self,cr,uid,part,context={}):
cr.execute('select column_db_name,id,table_id from olap_database_columns where table_id in (' + ','.join(tables_id) +')')
else:
cr.execute('select column_db_name,id,table_id from olap_database_columns')
for data in cr.fetchall():
cols[str(data[1])]=(data[0],int(data[2]))
@@ -286,10 +281,10 @@ def olap_db_connect(self,cr,uid,part,context={}):
'fact_database_id':id_db,
'table_db_name':table[0]
}
if table[0] in tables.keys():
table_id=tobj.write(cr,uid,[tables[table[0]]], val, context)
else:
val['name']=table[0]
tables[val['name']] = tobj.create(cr,uid,val, context)
@@ -297,7 +292,7 @@ def olap_db_connect(self,cr,uid,part,context={}):
cr_db.execute("""SELECT
table_name, column_name, data_type
from
all_tab_columns
all_tab_columns
WHERE owner = %s""",(user))
temp = cr_db.fetchall()
for col in temp:
@@ -314,7 +309,7 @@ def olap_db_connect(self,cr,uid,part,context={}):
'column_db_name': col[1],
'type': type_col,
}
id_made=filter(lambda x:(int(cols[x][1])==int(tables[col[0]])),cols)
if col[1] in cols.keys() and col[0] in tables.keys()and id_made:
col_id=tcol.write(cr,uid,cols[tables[str(col[0])]], val, context)
@@ -323,18 +318,18 @@ def olap_db_connect(self,cr,uid,part,context={}):
id_made = tcol.create(cr,uid,val, context)
cols[str(id_made)] = (val['name'],int(val['table_id']))
cr_db.execute("""select
cr_db.execute("""select
table_name,column_name,constraint_name
from
from
all_cons_columns
where
constraint_name in (
select constraint_name from all_constraints
where
where
constraint_type = 'P' and owner= %s)
""",(user))
""",(user))
temp = cr_db.fetchall()
pk_table = {}
pk_table = {}
for constraint in temp:
val={
'primary_key' : True
@@ -344,26 +339,26 @@ def olap_db_connect(self,cr,uid,part,context={}):
id_to_write=filter(lambda x : (int(cols[x][1])==int(tables[constraint[0]])and(constraint[1]==cols[x][0])),cols)
col_id=tcol.write(cr,uid,int(id_to_write[0]),val,context)
cr_db.execute("""select
cr_db.execute("""select
constraint_name,r_constraint_name from all_constraints
where
where
constraint_type = 'R' and owner = %s
""",(user))
constraints_map={}
for data in cr_db.fetchall():
constraints_map[data[0]]=data[1]
cr_db.execute("""select
cr_db.execute("""select
table_name,column_name,constraint_name
from
from
all_cons_columns
where
constraint_name in (
select constraint_name from all_constraints
where
where
constraint_type = 'R' and owner = %s)
""",(user))
temp = cr_db.fetchall()
for constraint in temp:
@@ -374,7 +369,7 @@ def olap_db_connect(self,cr,uid,part,context={}):
}
id_to_write=filter(lambda x:(int(cols[x][1])==int(tables[constraint[0]])and (constraint[1]==cols[x][0])),cols)
col_id=tcol.write(cr,uid,int(id_to_write[0]),val,context)
pooler.get_pool(cr.dbname).get('olap.fact.database').write(cr,uid,[id_db],{'loaded':True})
wf_service = netsvc.LocalService('workflow')
wf_service.trg_validate(uid, 'olap.schema', part['id'], 'dbload', cr)