From ee20d563570fcf3b3eabb90d82dd5f1c5164f1a9 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Thu, 5 Jul 2012 16:37:21 +0200 Subject: [PATCH] [FIX] Create new records as a bunch of empty (false) fields, otherwise Bad Things Happen ~/projects/tiny/web/current namely, if the list view fields have e.g. attributes associated, the computation of the domains blow up also, always create an editor in the listview (if the editable listview module has been installed), avoids blowing up 'safety' calls to #ensureSaved. An alternative would be to fix #ensureSaved not to blow up if there's no editor, but that means third parties which *know* there may be an editor in the list view can't easily hook up to it. Things will have to change anyway as currently toggling a list view from not-editable to editable after on_loaded has been called will not work correctly (it won't start the editor), which is shitty. bzr revid: xmo@openerp.com-20120705143721-4fiz64k7fka4052k --- addons/web/static/src/js/view_list_editable.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/addons/web/static/src/js/view_list_editable.js b/addons/web/static/src/js/view_list_editable.js index 8f0a036b1b9..ab02ef49093 100644 --- a/addons/web/static/src/js/view_list_editable.js +++ b/addons/web/static/src/js/view_list_editable.js @@ -12,6 +12,8 @@ openerp.web.list_editable = function (instance) { var self = this; this._super.apply(this, arguments); + this.editor = new instance.web.list.Editor(this); + $(this.groups).bind({ 'edit': function (e, id, dataset) { self.do_edit(dataset.index, id, dataset); @@ -80,8 +82,6 @@ openerp.web.list_editable = function (instance) { this.options.editable = ! this.options.read_only && (data.arch.attrs.editable || this.options.editable); var result = this._super(data, grouped); if (this.options.editable) { - this.editor = new instance.web.list.Editor(this); - var editor_ready = this.editor.prependTo(this.$element) .then(this.proxy('setupEvents')); @@ -119,7 +119,12 @@ openerp.web.list_editable = function (instance) { startEdition: function (record) { var self = this; if (!record) { - record = new instance.web.list.Record(); + var attrs = {}; + _(this.columns).chain() + .filter(function (x) { return x.tag === 'field'}) + .pluck('name') + .each(function (field) { attrs[field] = false; }); + record = new instance.web.list.Record(attrs); this.records.add(record, { at: this.isPrependOnCreate() ? 0 : null}); }