From 5182068b43ce8683f56d2e60d09c8b1197890a89 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Fri, 22 Jun 2012 10:54:32 +0200 Subject: [PATCH 1/3] [FIX] ensure containing form is saved when triggering an action from an editable o2m list After opening a record with a list o2m, editing said list o2m and saving a row, clicking the action button would lose all data explicitly changed: the o2m would just call the action without saving the form's current state, so the corresponding server method would only be able to use data previously saved. Fixed by overriding do_button_action, and only calling the _super() method after the parent form has announced it is saved (either because nothing was changed or because it did indeed save itself). bzr revid: xmo@openerp.com-20120622085432-mh3977uygua5bypn --- addons/web/static/src/js/view_form.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/addons/web/static/src/js/view_form.js b/addons/web/static/src/js/view_form.js index fe8448f4dcc..d9badd9ba6a 100644 --- a/addons/web/static/src/js/view_form.js +++ b/addons/web/static/src/js/view_form.js @@ -479,7 +479,7 @@ openerp.web.FormView = openerp.web.View.extend( /** @lends openerp.web.FormView# * record or saving an existing one depending on whether the record * already has an id property. * - * @param {Function} success callback on save success + * @param {Function} [success] callback on save success * @param {Boolean} [prepend_on_create=false] if ``do_save`` creates a new record, should that record be inserted at the start of the dataset (by default, records are added at the end) */ do_save: function(success, prepend_on_create) { @@ -2609,7 +2609,7 @@ openerp.web.form.One2ManyListView = openerp.web.ListView.extend({ var button_result = self.o2m.dataset.call_button.apply(self.o2m.dataset, arguments); self.o2m.reload_current_view(); return button_result; - } + }; pop.on_write.add(function(id, data) { self.o2m.dataset.write(id, data, {}, function(r) { self.o2m.reload_current_view(); @@ -2618,8 +2618,11 @@ openerp.web.form.One2ManyListView = openerp.web.ListView.extend({ }, do_button_action: function (name, id, callback) { var self = this; - var def = $.Deferred().then(callback).then(function() {self.o2m.view.reload();}); - return this._super(name, id, _.bind(def.resolve, def)); + var _super = _.bind(this._super, this); + + this.o2m.view.do_save().then(function () { + _super(name, id, callback); + }); } }); From 9e134c9afa77cf7dc54650da13240bc1ed59916d Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Fri, 22 Jun 2012 15:50:15 +0200 Subject: [PATCH 2/3] [IMP] move ListView.List#reload_record to ListView bzr revid: xmo@openerp.com-20120622135015-dsvjblv1rd4oezcp --- addons/web/static/src/js/view_list.js | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/addons/web/static/src/js/view_list.js b/addons/web/static/src/js/view_list.js index 6d613f3892d..6a824243a0e 100644 --- a/addons/web/static/src/js/view_list.js +++ b/addons/web/static/src/js/view_list.js @@ -479,6 +479,19 @@ openerp.web.ListView = openerp.web.View.extend( /** @lends openerp.web.ListView# reload: function () { return this.reload_content(); }, + reload_record: function (record) { + return this.dataset.read_ids( + [record.get('id')], + _.pluck(_(this.columns).filter(function (r) { + return r.tag === 'field'; + }), 'name') + ).then(function (records) { + _(records[0]).each(function (value, key) { + record.set(key, value, {silent: true}); + }); + record.trigger('change', record); + }); + }, do_load_state: function(state, warm) { var reload = false; @@ -1018,17 +1031,7 @@ openerp.web.ListView.List = openerp.web.Class.extend( /** @lends openerp.web.Lis * @returns {$.Deferred} promise to the finalization of the reloading */ reload_record: function (record) { - return this.dataset.read_ids( - [record.get('id')], - _.pluck(_(this.columns).filter(function (r) { - return r.tag === 'field'; - }), 'name') - ).then(function (records) { - _(records[0]).each(function (value, key) { - record.set(key, value, {silent: true}); - }); - record.trigger('change', record); - }); + return this.view.reload_record(record); }, /** * Renders a list record to HTML From d64f983fce0245961ba8851f922962b3106ccc11 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Fri, 22 Jun 2012 17:01:17 +0200 Subject: [PATCH 3/3] [FIX] correctly reload an o2m list *after* triggering an action from a row being edited bzr revid: xmo@openerp.com-20120622150117-w04eibub93ve81mo --- addons/web/static/src/js/view_form.js | 29 ++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/addons/web/static/src/js/view_form.js b/addons/web/static/src/js/view_form.js index d9badd9ba6a..edee9bfec74 100644 --- a/addons/web/static/src/js/view_form.js +++ b/addons/web/static/src/js/view_form.js @@ -2617,12 +2617,39 @@ openerp.web.form.One2ManyListView = openerp.web.ListView.extend({ }); }, do_button_action: function (name, id, callback) { - var self = this; var _super = _.bind(this._super, this); this.o2m.view.do_save().then(function () { _super(name, id, callback); }); + }, + reload_content: function () { + var self = this; + return this._super().then(function () { + _.each(self.groups.children, self.proxy('hook_form_action')); + }); + }, + /** + * Goes through all the lists in order to override their form's + * execute_action to perform a simple reload_record after the action is + * done. + * + * Goes through ListView.List.save_row to do so, to ensure it has a valid + * form as there are no other hook points + */ + hook_form_action: function (list) { + var self = this; + var _save_row = list.save_row; + list.save_row = function () { + var _execute_action = this.edition_form.do_execute_action; + this.edition_form.do_execute_action = function (action, dataset, record_id, _callback) { + return _execute_action.call(this, action, dataset, record_id, function () { + self.reload_record( + self.records.get(record_id)); + }); + }; + return _save_row.apply(this, arguments); + } } });