def _sql_query_get(self, cr, uid, ids, prop, unknow_none, context=None, 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, context=context): fields = [] groupby = [] i = 0 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')) continue t = self.pool.get(f.field_id.model_id.model)._table if f.group_method == 'group': fields.append('\t' + t + '.' + f.field_id.name + ' as field' + str(i)) groupby.append(t + '.' + f.field_id.name) else: fields.append('\t' + f.group_method + '(' + t + '.' + f.field_id.name + ')' + ' as field' + str(i)) 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')) if models: result[obj.id] = """select %s from %s """ % (',\n'.join(fields), models) if groupby: result[obj.id] += "group by\n\t" + ', '.join(groupby) if where_plus: result[obj.id] += "\nhaving \n\t" + "\n\t and ".join( where_plus) if limit: result[obj.id] += " limit " + str(limit) if offset: result[obj.id] += " offset " + str(offset) else: result[obj.id] = False return result
def _sql_query_get(self, cr, uid, ids, prop, unknow_none, context=None, 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, context=context): fields = [] groupby = [] i = 0 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')) continue t = self.pool.get(f.field_id.model_id.model)._table if f.group_method == 'group': fields.append('\t'+t+'.'+f.field_id.name+' as field'+str(i)) groupby.append(t+'.'+f.field_id.name) else: fields.append('\t'+f.group_method+'('+t+'.'+f.field_id.name+')'+' as field'+str(i)) 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')) if models: result[obj.id] = """select %s from %s """ % (',\n'.join(fields), models) if groupby: result[obj.id] += "group by\n\t"+', '.join(groupby) if where_plus: result[obj.id] += "\nhaving \n\t"+"\n\t and ".join(where_plus) if limit: result[obj.id] += " limit "+str(limit) if offset: result[obj.id] += " offset "+str(offset) else: result[obj.id] = False return result