diff --git a/addons/web/static/src/js/view_form.js b/addons/web/static/src/js/view_form.js index 9fe8dd5a7c5f60ffe37e5a1de1ccec04111ea878..3fa9afea0bcafcd71227156e044412aba3f94d2c 100644 --- a/addons/web/static/src/js/view_form.js +++ b/addons/web/static/src/js/view_form.js @@ -103,6 +103,7 @@ instance.web.FormView = instance.web.View.extend(instance.web.form.FieldManagerM this.fields_order = []; this.datarecord = {}; this._onchange_specs = {}; + this.onchanges_defs = []; this.default_focus_field = null; this.default_focus_button = null; this.fields_registry = instance.web.form.widgets; @@ -507,7 +508,7 @@ instance.web.FormView = instance.web.View.extend(instance.web.form.FieldManagerM def = self.alive(new instance.web.Model(self.dataset.model).call( "onchange", [ids, values, trigger_field_name, onchange_specs, context])); } - return def.then(function(response) { + var onchange_def = def.then(function(response) { if (widget && widget.field['change_default']) { var fieldname = widget.name; var value_; @@ -543,6 +544,8 @@ instance.web.FormView = instance.web.View.extend(instance.web.form.FieldManagerM }).then(function(response) { return self.on_processed_onchange(response); }); + this.onchanges_defs.push(onchange_def); + return onchange_def; } catch(e) { console.error(e); instance.webclient.crashmanager.show_message(e); @@ -642,6 +645,7 @@ instance.web.FormView = instance.web.View.extend(instance.web.form.FieldManagerM * if the current record is not yet saved. It will then stay in create mode. */ to_edit_mode: function() { + this.onchanges_defs = []; this._actualize_mode("edit"); }, /** @@ -790,12 +794,14 @@ instance.web.FormView = instance.web.View.extend(instance.web.form.FieldManagerM var self = this; var save_obj = {prepend_on_create: prepend_on_create, ret: null}; this.save_list.push(save_obj); - return this._process_operations().then(function() { - if (save_obj.error) - return $.Deferred().reject(); - return $.when.apply($, save_obj.ret); - }).done(function() { - self.$el.removeClass('oe_form_dirty'); + return $.when.apply($, self.onchanges_defs).then(function(){ + return self._process_operations().then(function() { + if (save_obj.error) + return $.Deferred().reject(); + return $.when.apply($, save_obj.ret); + }).done(function() { + self.$el.removeClass('oe_form_dirty'); + }); }); }, _process_save: function(save_obj) { diff --git a/addons/web/static/test/list-editable.js b/addons/web/static/test/list-editable.js index ef2d608bc5de7ebbcd6340a4c258669909f6d966..a91d50121233a59b81c78b21469b5a6441487b8c 100644 --- a/addons/web/static/test/list-editable.js +++ b/addons/web/static/test/list-editable.js @@ -6,6 +6,9 @@ openerp.testing.section('editor', { mock('test.model:create', function () { return 42; }); + mock('test.model:onchange', function () { + return {}; + }); } }, function (test) { /** @@ -203,6 +206,9 @@ openerp.testing.section('list.edition', { arch: '<tree><field name="a"/><field name="b"/><field name="c"/></tree>', }; }); + mock('demo:onchange', function () { + return {}; + }); } }, function (test) { test('newrecord', {asserts: 6}, function (instance, $fix, mock) { @@ -311,6 +317,11 @@ openerp.testing.section('list.edition.onwrite', { dependencies: ['web.list_editable'], rpc: 'mock', templates: true, + setup: function (instance, $s, mock) { + mock('demo:onchange', function () { + return {}; + }); + } }, function (test) { test('record-to-read', {asserts: 4}, function (instance, $fix, mock) { mock('demo:fields_view_get', function () {