[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
This commit is contained in:
Xavier Morel 2012-06-22 10:54:32 +02:00
parent 5179f7293c
commit 5182068b43
1 changed files with 7 additions and 4 deletions

View File

@ -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);
});
}
});