|
@ -5,7 +5,7 @@ |
|
|
import json |
|
|
import json |
|
|
|
|
|
|
|
|
from odoo import api, fields, models, tools |
|
|
from odoo import api, fields, models, tools |
|
|
from odoo.exceptions import Warning as UserError |
|
|
|
|
|
|
|
|
from odoo.exceptions import UserError |
|
|
from odoo.tools.translate import _ |
|
|
from odoo.tools.translate import _ |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -63,8 +63,8 @@ class BveView(models.Model): |
|
|
_('Custom BI View names must be unique!')), |
|
|
_('Custom BI View names must be unique!')), |
|
|
] |
|
|
] |
|
|
|
|
|
|
|
|
@api.model |
|
|
|
|
|
def _get_format_data(self, data): |
|
|
|
|
|
|
|
|
@classmethod |
|
|
|
|
|
def _get_format_data(cls, data): |
|
|
data = data.replace('\'', '"') |
|
|
data = data.replace('\'', '"') |
|
|
data = data.replace(': u"', ':"') |
|
|
data = data.replace(': u"', ':"') |
|
|
return data |
|
|
return data |
|
@ -73,11 +73,11 @@ class BveView(models.Model): |
|
|
def _create_view_arch(self): |
|
|
def _create_view_arch(self): |
|
|
self.ensure_one() |
|
|
self.ensure_one() |
|
|
|
|
|
|
|
|
def _get_field_def(name, type=''): |
|
|
|
|
|
if not type: |
|
|
|
|
|
|
|
|
def _get_field_def(name, def_type=''): |
|
|
|
|
|
if not def_type: |
|
|
return '' |
|
|
return '' |
|
|
return """<field name="x_{}" type="{}" />""".format( |
|
|
return """<field name="x_{}" type="{}" />""".format( |
|
|
name, type |
|
|
|
|
|
|
|
|
name, def_type |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
def _get_field_type(field_info): |
|
|
def _get_field_type(field_info): |
|
@ -169,8 +169,8 @@ class BveView(models.Model): |
|
|
View.sudo().create(vals) |
|
|
View.sudo().create(vals) |
|
|
|
|
|
|
|
|
# create Tree view |
|
|
# create Tree view |
|
|
tree_view = View.sudo().create( |
|
|
|
|
|
{'name': 'Tree Analysis', |
|
|
|
|
|
|
|
|
tree_view = View.sudo().create({ |
|
|
|
|
|
'name': 'Tree Analysis', |
|
|
'type': 'tree', |
|
|
'type': 'tree', |
|
|
'model': self.model_name, |
|
|
'model': self.model_name, |
|
|
'priority': 16, |
|
|
'priority': 16, |
|
@ -219,10 +219,10 @@ class BveView(models.Model): |
|
|
return [x[0] for x in self.env.cr.fetchall()] |
|
|
return [x[0] for x in self.env.cr.fetchall()] |
|
|
|
|
|
|
|
|
info = json.loads(self._get_format_data(self.data)) |
|
|
info = json.loads(self._get_format_data(self.data)) |
|
|
models = list(set([f['model'] for f in info])) |
|
|
|
|
|
|
|
|
model_names = list(set([f['model'] for f in info])) |
|
|
read_groups = set.intersection(*[set( |
|
|
read_groups = set.intersection(*[set( |
|
|
group_ids_with_access(model_name, 'read') |
|
|
group_ids_with_access(model_name, 'read') |
|
|
) for model_name in models]) |
|
|
|
|
|
|
|
|
) for model_name in model_names]) |
|
|
|
|
|
|
|
|
# read access |
|
|
# read access |
|
|
for group in read_groups: |
|
|
for group in read_groups: |
|
@ -275,10 +275,9 @@ class BveView(models.Model): |
|
|
return tables |
|
|
return tables |
|
|
|
|
|
|
|
|
def get_fields(info): |
|
|
def get_fields(info): |
|
|
fields = [("{}.{}".format(f['table_alias'], |
|
|
|
|
|
|
|
|
return [("{}.{}".format(f['table_alias'], |
|
|
f['select_field']), |
|
|
f['select_field']), |
|
|
f['as_field']) for f in info if 'join_node' not in f] |
|
|
f['as_field']) for f in info if 'join_node' not in f] |
|
|
return fields |
|
|
|
|
|
|
|
|
|
|
|
def check_empty_data(data): |
|
|
def check_empty_data(data): |
|
|
if not data or data == '[]': |
|
|
if not data or data == '[]': |
|
@ -288,7 +287,7 @@ class BveView(models.Model): |
|
|
|
|
|
|
|
|
formatted_data = json.loads(self._get_format_data(self.data)) |
|
|
formatted_data = json.loads(self._get_format_data(self.data)) |
|
|
info = get_fields_info(formatted_data) |
|
|
info = get_fields_info(formatted_data) |
|
|
fields = get_fields(info) |
|
|
|
|
|
|
|
|
select_fields = get_fields(info) |
|
|
tables = get_tables(info) |
|
|
tables = get_tables(info) |
|
|
join_nodes = get_join_nodes(info) |
|
|
join_nodes = get_join_nodes(info) |
|
|
|
|
|
|
|
@ -307,7 +306,7 @@ class BveView(models.Model): |
|
|
WHERE %s |
|
|
WHERE %s |
|
|
)""" % (table_name, ','.join( |
|
|
)""" % (table_name, ','.join( |
|
|
["{} AS {}".format(f[0], f[1]) |
|
|
["{} AS {}".format(f[0], f[1]) |
|
|
for f in basic_fields + fields]), ','.join( |
|
|
|
|
|
|
|
|
for f in basic_fields + select_fields]), ','.join( |
|
|
["{} AS {}".format(t[0], t[1]) |
|
|
["{} AS {}".format(t[0], t[1]) |
|
|
for t in list(tables)]), " AND ".join( |
|
|
for t in list(tables)]), " AND ".join( |
|
|
["{}.{} = {}.id".format(j[0], j[2], j[1]) |
|
|
["{}.{} = {}.id".format(j[0], j[2], j[1]) |
|
@ -339,8 +338,11 @@ class BveView(models.Model): |
|
|
if field.ttype == 'selection' and not field.selection: |
|
|
if field.ttype == 'selection' and not field.selection: |
|
|
model_obj = self.env[field.model_id.model] |
|
|
model_obj = self.env[field.model_id.model] |
|
|
selection = model_obj._fields[field.name].selection |
|
|
selection = model_obj._fields[field.name].selection |
|
|
selection_domain = str(selection) |
|
|
|
|
|
vals.update({'selection': selection_domain}) |
|
|
|
|
|
|
|
|
if callable(selection): |
|
|
|
|
|
selection_domain = selection(model_obj) |
|
|
|
|
|
else: |
|
|
|
|
|
selection_domain = selection |
|
|
|
|
|
vals.update({'selection': str(selection_domain)}) |
|
|
return vals |
|
|
return vals |
|
|
|
|
|
|
|
|
# clean dirty view (in case something went wrong) |
|
|
# clean dirty view (in case something went wrong) |
|
@ -399,9 +401,11 @@ class BveView(models.Model): |
|
|
self.action_id.view_id.sudo().unlink() |
|
|
self.action_id.view_id.sudo().unlink() |
|
|
self.action_id.sudo().unlink() |
|
|
self.action_id.sudo().unlink() |
|
|
|
|
|
|
|
|
models = self.env['ir.model'].sudo().search( |
|
|
|
|
|
|
|
|
self.env['ir.ui.view'].sudo().search( |
|
|
|
|
|
[('model', '=', self.model_name)]).unlink() |
|
|
|
|
|
ir_models = self.env['ir.model'].sudo().search( |
|
|
[('model', '=', self.model_name)]) |
|
|
[('model', '=', self.model_name)]) |
|
|
for model in models: |
|
|
|
|
|
|
|
|
for model in ir_models: |
|
|
model.sudo().unlink() |
|
|
model.sudo().unlink() |
|
|
|
|
|
|
|
|
table_name = self.model_name.replace('.', '_') |
|
|
table_name = self.model_name.replace('.', '_') |
|
|