diff --git a/addons/base/static/src/js/tree.js b/addons/base/static/src/js/tree.js index dcdcfa65d8a..acb588366a1 100644 --- a/addons/base/static/src/js/tree.js +++ b/addons/base/static/src/js/tree.js @@ -39,9 +39,27 @@ openerp.base.TreeView = openerp.base.View.extend({ toolbar: this.view_manager ? !!this.view_manager.sidebar : false }, this.on_loaded); }, - + /** + * Returns the list of fields needed to correctly read objects. + * + * Gathers the names of all fields in fields_view_get, and adds the + * field_parent (children_field in the tree view) if it's not already one + * of the fields to fetch + * + * @returns {Array} an array of fields which can be provided to DataSet.read_slice and others + */ + fields_list: function () { + var fields = _.keys(this.fields); + if (!_(fields).contains(this.children_field)) { + fields.push(this.children_field); + } + return fields; + }, on_loaded: function (fields_view) { var self = this; + // field name in OpenERP is kinda stupid: this is the field holding + // the ids to the children of the current node + this.children_field = fields_view['field_parent']; this.fields_view = fields_view; _(this.fields_view.arch.children).each(function (field) { if (field.attrs.modifiers) { @@ -50,43 +68,50 @@ openerp.base.TreeView = openerp.base.View.extend({ }); this.fields = fields_view.fields; - this.dataset.read_slice(_.keys(this.fields), 0, false, function (response) { + this.dataset.read_slice(this.fields_list(), 0, false, function (records) { self.$element.html(QWeb.render('TreeView', { - "first_level": response, 'title': self.fields_view.arch.attrs.string })); - - self.$element.find('#parent_id').bind('change', function(){ - self.getdata($('#parent_id').val(), false); + var $select = self.$element.find('select') + .change(function () { + var $option = $(this).find(':selected'); + self.getdata($option.val(), $option.data('children')); + }); + _(records).each(function (record) { + $('