Browse Source

Added selection of fields of a tree view

pull/106/head
Andrea 8 years ago
parent
commit
a0869b2d85
  1. 40
      bi_view_editor/models/bve_view.py
  2. 5
      bi_view_editor/models/models.py
  3. 17
      bi_view_editor/static/src/js/bve.js
  4. 1
      bi_view_editor/templates/qweb_template.xml
  5. 3
      bi_view_editor/tests/test_bi_view.py

40
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 """<field name="x_{}" />""".format(
name
)
return ''
return """<field name="x_{}" type="{}" />""".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 """<field name="x_{}" />""".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):

5
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():

17
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 += "<span class='fa fa-bars' title='Row'></span> ";
if(field.measure)
icons += "<span class='fa fa-bar-chart-o' title='Measure'></span> ";
if(field.list)
icons += "<span class='fa fa-list' title='List'></span> ";
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]);
});

1
bi_view_editor/templates/qweb_template.xml

@ -47,6 +47,7 @@
<li><input type="checkbox" id="column-checkbox"/> Column</li>
<li><input type="checkbox" id="row-checkbox"/> Row</li>
<li><input type="checkbox" id="measure-checkbox"/> Measure</li>
<li><input type="checkbox" id="list-checkbox"/> List</li>
</ul>
</div>

3
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
}
]

Loading…
Cancel
Save