diff --git a/bi_view_editor/models/bve_view.py b/bi_view_editor/models/bve_view.py index bdf16a6f..89e61b8b 100644 --- a/bi_view_editor/models/bve_view.py +++ b/bi_view_editor/models/bve_view.py @@ -73,11 +73,9 @@ class BveView(models.Model): def _create_view_arch(self): self.ensure_one() - def _get_field_def(name, type=False): + def _get_field_def(name, type=''): if not type: - return """""".format( - name - ) + return '' return """""".format( name, type ) @@ -90,30 +88,40 @@ class BveView(models.Model): def _get_field_list(fields_info): view_fields = [] - all_fields = [] for field_info in fields_info: field_name = field_info['name'] - field_type = field_info['type'] def_type = _get_field_type(field_info) - field_def = _get_field_def(field_name, def_type) if def_type: + field_def = _get_field_def(field_name, def_type) view_fields.append(field_def) - if field_type not in ['many2one', 'one2many', 'many2many']: - all_fields.append(field_def) - return view_fields, all_fields + return view_fields fields_info = json.loads(self._get_format_data(self.data)) - is_tree_view = self._context.get('no_empty') - - view_fields, all_fields = _get_field_list(fields_info) - if not view_fields and is_tree_view: - view_fields = all_fields + view_fields = _get_field_list(fields_info) return view_fields @api.multi def _create_tree_view_arch(self): self.ensure_one() - return self.with_context(no_empty=True)._create_view_arch() + + 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.multi def _create_bve_view(self): diff --git a/bi_view_editor/models/models.py b/bi_view_editor/models/models.py index 699bef60..233fd8a8 100644 --- a/bi_view_editor/models/models.py +++ b/bi_view_editor/models/models.py @@ -19,6 +19,11 @@ class Base(models.AbstractModel): if not self._bi_view(): super(Base, self)._auto_end() + @api.model + def _auto_init(self): + if not self._bi_view(): + super(Base, self)._auto_init() + @api.model def _setup_complete(self): if not self._bi_view(): diff --git a/bi_view_editor/static/src/js/bve.js b/bi_view_editor/static/src/js/bve.js index fbc09a41..f1d08085 100644 --- a/bi_view_editor/static/src/js/bve.js +++ b/bi_view_editor/static/src/js/bve.js @@ -61,7 +61,7 @@ odoo.define('bi_view_editor', function (require) { }, start: function() { this._super(); - this.view.on("change:effective_readonly", this, function() { + this.on("change:effective_readonly", this, function() { this.display_field(); this.render_value(); }); @@ -120,6 +120,8 @@ odoo.define('bi_view_editor', function (require) { icons += " "; if(field.measure) icons += " "; + if(field.list) + icons += " "; return icons; }, @@ -217,15 +219,19 @@ odoo.define('bi_view_editor', function (require) { _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; @@ -272,10 +278,11 @@ odoo.define('bi_view_editor', function (require) { 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..b38ca727 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 ae30c76e..ebe85827 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 } ]