From 69e615bb1753315984c5f04997552328c746e76a Mon Sep 17 00:00:00 2001 From: Andrea Date: Fri, 10 Mar 2017 13:14:08 +0100 Subject: [PATCH] Add fields selection for tree view --- bi_view_editor/models/bve_view.py | 25 +++++++++++++++++++++- bi_view_editor/static/src/js/bve.js | 15 +++++++++---- bi_view_editor/templates/qweb_template.xml | 1 + bi_view_editor/tests/test_bi_view.py | 3 +++ 4 files changed, 39 insertions(+), 5 deletions(-) diff --git a/bi_view_editor/models/bve_view.py b/bi_view_editor/models/bve_view.py index e24fef59..a8d36064 100644 --- a/bi_view_editor/models/bve_view.py +++ b/bi_view_editor/models/bve_view.py @@ -124,6 +124,29 @@ class BveView(models.Model): view_fields.append(field_def) return view_fields + @api.multi + def _create_tree_view_arch(self): + self.ensure_one() + + def _get_field_def(name): + return """""".format( + name + ) + + def _get_field_list(fields_info): + view_fields = [] + for field_info in fields_info: + field_name = field_info['name'] + if field_info['list'] and 'join_node' not in field_info: + field_def = _get_field_def(field_name) + view_fields.append(field_def) + return view_fields + + fields_info = json.loads(self._get_format_data(self.data)) + + view_fields = _get_field_list(fields_info) + return view_fields + @api.model def _get_format_data(self, data): data = data.replace('\'', '"') @@ -177,7 +200,7 @@ class BveView(models.Model): 'priority': 16, 'arch': """ {} - """.format("".join(self._create_view_arch())) + """.format("".join(self._create_tree_view_arch())) }) # set the Tree view as the default one diff --git a/bi_view_editor/static/src/js/bve.js b/bi_view_editor/static/src/js/bve.js index 455adaf8..b521bdbb 100644 --- a/bi_view_editor/static/src/js/bve.js +++ b/bi_view_editor/static/src/js/bve.js @@ -68,6 +68,8 @@ openerp.bi_view_editor = function (instance, local) { icons += " "; if(field.measure) icons += " "; + if(field.list) + icons += " "; return icons; }, @@ -165,15 +167,19 @@ openerp.bi_view_editor = function (instance, local) { _contextMenu.find(identifier).attr('checked', false); }, _false_if_undefined: function(to_check) { - if (typeof check === 'undefined') return false; - return check; + if (typeof to_check === 'undefined') return false; + return to_check; + }, + _true_if_undefined: function(to_check) { + if (typeof to_check === 'undefined') return true; + return to_check; }, add_field_to_table: function(data, options) { var self = this; - data.row = self._false_if_undefined(data.row); data.column = self._false_if_undefined(data.column); data.measure = self._false_if_undefined(data.measure); + data.list = self._true_if_undefined(data.list); var n = 1; var name = data.name; @@ -220,10 +226,11 @@ openerp.bi_view_editor = function (instance, local) { self.set_checkbox(currentFieldData.column, '#column-checkbox', contextMenu); self.set_checkbox(currentFieldData.row, '#row-checkbox', contextMenu); self.set_checkbox(currentFieldData.measure, '#measure-checkbox', contextMenu); + self.set_checkbox(currentFieldData.list, '#list-checkbox', contextMenu); var to_disable = false; if(currentFieldData.type === "float" || currentFieldData.type === "integer" || currentFieldData.type === "monetary") to_disable = true; - var identifiers = [['#column-checkbox', 'column', to_disable], ['#row-checkbox', 'row', to_disable], ['#measure-checkbox', 'measure', !to_disable]]; + var identifiers = [['#column-checkbox', 'column', to_disable], ['#row-checkbox', 'row', to_disable], ['#measure-checkbox', 'measure', !to_disable], ['#list-checkbox', 'list', false]]; identifiers.forEach(function (element) { contextMenu.find(element[0]).attr('disabled', element[2]); }); diff --git a/bi_view_editor/templates/qweb_template.xml b/bi_view_editor/templates/qweb_template.xml index fae5371b..b2aaa0e6 100644 --- a/bi_view_editor/templates/qweb_template.xml +++ b/bi_view_editor/templates/qweb_template.xml @@ -47,6 +47,7 @@
  • Column
  • Row
  • Measure
  • +
  • List
  • diff --git a/bi_view_editor/tests/test_bi_view.py b/bi_view_editor/tests/test_bi_view.py index b4f4f24b..26df020b 100644 --- a/bi_view_editor/tests/test_bi_view.py +++ b/bi_view_editor/tests/test_bi_view.py @@ -66,6 +66,7 @@ class TestBiViewEditor(TransactionCase): 'table_alias': 't0', 'row': 0, 'column': 1, + 'list': 1, 'measure': 0 }, {'model_id': self.partner_model.id, @@ -81,6 +82,7 @@ class TestBiViewEditor(TransactionCase): 'description': self.partner_company_field.field_description, 'row': 0, 'column': 0, + 'list': 1, 'measure': 0 }, {'model_id': self.company_model.id, @@ -94,6 +96,7 @@ class TestBiViewEditor(TransactionCase): 'table_alias': 't1', 'row': 1, 'column': 0, + 'list': 0, 'measure': 0 } ]