Browse Source

Merge pull request #191 from onesteinbv/10_porting_bi_view_editor

[10.0][FIX] bi_view_editor: bugfixing
pull/197/head
Pedro M. Baeza 6 years ago
committed by GitHub
parent
commit
4d41769a0f
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      bi_view_editor/__manifest__.py
  2. 62
      bi_view_editor/models/bve_view.py
  3. 2
      bi_view_editor/models/models.py
  4. 30
      bi_view_editor/static/src/js/bve.js
  5. 2
      bi_view_editor/tests/test_bi_view.py

2
bi_view_editor/__manifest__.py

@ -10,7 +10,7 @@
'license': 'AGPL-3', 'license': 'AGPL-3',
'website': 'http://www.onestein.eu', 'website': 'http://www.onestein.eu',
'category': 'Reporting', 'category': 'Reporting',
'version': '10.0.1.0.0',
'version': '10.0.1.0.1',
'depends': [ 'depends': [
'base', 'base',
'web' 'web'

62
bi_view_editor/models/bve_view.py

@ -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,17 +169,17 @@ 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',
'type': 'tree',
'model': self.model_name,
'priority': 16,
'arch': """<?xml version="1.0"?>
<tree string="List Analysis" create="false">
{}
</tree>
""".format("".join(self._create_tree_view_arch()))
})
tree_view = View.sudo().create({
'name': 'Tree Analysis',
'type': 'tree',
'model': self.model_name,
'priority': 16,
'arch': """<?xml version="1.0"?>
<tree string="List Analysis" create="false">
{}
</tree>
""".format("".join(self._create_tree_view_arch()))
})
# set the Tree view as the default one # set the Tree view as the default one
action_vals = { action_vals = {
@ -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'],
f['select_field']),
f['as_field']) for f in info if 'join_node' not in f]
return fields
return [("{}.{}".format(f['table_alias'],
f['select_field']),
f['as_field']) for f in info if 'join_node' not in f]
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('.', '_')

2
bi_view_editor/models/models.py

@ -3,7 +3,7 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo import api, models from odoo import api, models
from odoo.exceptions import Warning as UserError
from odoo.exceptions import UserError
from odoo.tools.translate import _ from odoo.tools.translate import _

30
bi_view_editor/static/src/js/bve.js

@ -178,12 +178,13 @@ odoo.define('bi_view_editor', function (require) {
} }
} }
function renderFields(result) { function renderFields(result) {
console.log(result);
var item = self.$el.find(".class-list #bve-class-" + result[0].model_id);
for (var o = 0; o < result.length; o++) {
self._render_field(self, o, result, item, addField)
if (typeof(result[0]) !== 'undefined') {
var item = self.$el.find(".class-list #bve-class-" + result[0].model_id);
for (var o = 0; o < result.length; o++) {
self._render_field(self, o, result, item, addField)
}
item.data('bve-processed', true);
} }
item.data('bve-processed', true);
} }
for (var i = 0; i < result.length; i++) { for (var i = 0; i < result.length; i++) {
var item = $("<div style=\"" + css + "\" class=\"class\" title=\"" + result[i].model + "\" id=\"bve-class-" + result[i].id + "\">" + result[i].name + "</div>") var item = $("<div style=\"" + css + "\" class=\"class\" title=\"" + result[i].model + "\" id=\"bve-class-" + result[i].id + "\">" + result[i].name + "</div>")
@ -321,8 +322,13 @@ odoo.define('bi_view_editor', function (require) {
self.clean_join_nodes(); self.clean_join_nodes();
self.internal_set_value(JSON.stringify(self.get_fields())); self.internal_set_value(JSON.stringify(self.get_fields()));
self.load_classes(); self.load_classes();
self.$el.find(".field-list .delete-button").hide();
self.$el.find(".field-list .delete-button:last").show();
return false; return false;
}); });
self.$el.find(".field-list .delete-button").hide();
self.$el.find(".field-list .delete-button:last").show();
}, },
clean_join_nodes: function () { clean_join_nodes: function () {
var aliases = $.makeArray(this.$el.find(".field-list tbody tr").map(function (idx, el) { var aliases = $.makeArray(this.$el.find(".field-list tbody tr").map(function (idx, el) {
@ -381,17 +387,27 @@ odoo.define('bi_view_editor', function (require) {
self.load_classes(field); self.load_classes(field);
}, },
add_field: function(field) { add_field: function(field) {
var self = this;
// Quick fix for double click
if(self._adding) {
return;
}
self._adding = true;
setTimeout(function() {
self._adding = false;
}, 1000);
// End quick fix
var data = field.data('field-data'); var data = field.data('field-data');
var model = new Model("ir.model"); var model = new Model("ir.model");
var model_ids = this.get_model_ids(); var model_ids = this.get_model_ids();
var field_data = this.get_fields(); var field_data = this.get_fields();
var self = this;
model.call('get_join_nodes', [field_data, data], {context: new Data.CompoundContext()}).then(function(result) { model.call('get_join_nodes', [field_data, data], {context: new Data.CompoundContext()}).then(function(result) {
if (result.length === 1) { if (result.length === 1) {
self.add_field_and_join_node(data, result[0]); self.add_field_and_join_node(data, result[0]);
self.internal_set_value(JSON.stringify(self.get_fields())); self.internal_set_value(JSON.stringify(self.get_fields()));
//self.load_classes(data);
} else if (result.length > 1) { } else if (result.length > 1) {
var pop = new JoinNodePopup(self); var pop = new JoinNodePopup(self);
pop.display_popup(result, self.get_model_data(), self.add_field_and_join_node.bind(self), data); pop.display_popup(result, self.get_model_data(), self.add_field_and_join_node.bind(self), data);

2
bi_view_editor/tests/test_bi_view.py

@ -3,7 +3,7 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo.tests.common import TransactionCase, at_install, post_install from odoo.tests.common import TransactionCase, at_install, post_install
from odoo.exceptions import Warning as UserError
from odoo.exceptions import UserError
class TestBiViewEditor(TransactionCase): class TestBiViewEditor(TransactionCase):

Loading…
Cancel
Save