diff options
| author | Aaron Bohy <aab@odoo.com> | 2017-06-08 14:57:09 +0200 |
|---|---|---|
| committer | Aaron Bohy <aab@odoo.com> | 2017-06-13 08:24:59 +0200 |
| commit | 5c4485d182b6ab68c7d5c97161f25e67a2fa60d2 (patch) | |
| tree | 941d407b94acba6d32c2bcd39caeea841c87ed56 /addons/web/static/src | |
| parent | 76262f2043db1afd6d67a386796107dce91100e4 (diff) | |
[FIX] web: Many2one in X2Manys: quick create then save line
A problem occured with a required Many2One inside an X2Many (e.g.
order_line field in sale.order form view). If the user clicked on
'Add an item' to add a row, then typed some text in the Many2One,
then clicked on 'Create ...' to quick create a new product, and
then directly clicked on 'Add an item' to add another row (before
the name_create returned), the first row was discarded.
This was because before the name_create returns, the Many2one still
has no value, and as it is required, the row was considered invalid
and then discarded.
This rev. ensures to wait for the name_create to return before
trying to save the row and to create a new one.
Diffstat (limited to 'addons/web/static/src')
| -rw-r--r-- | addons/web/static/src/js/fields/relational_fields.js | 43 |
1 files changed, 24 insertions, 19 deletions
diff --git a/addons/web/static/src/js/fields/relational_fields.js b/addons/web/static/src/js/fields/relational_fields.js index ae3b06d3a02..3b47b8c64b0 100644 --- a/addons/web/static/src/js/fields/relational_fields.js +++ b/addons/web/static/src/js/fields/relational_fields.js @@ -619,12 +619,15 @@ var FieldX2Many = AbstractField.extend({ * @returns {Deferred} */ commitChanges: function () { + var self = this; var inEditionRecordID = this.renderer && this.renderer.viewType === "list" && this.renderer.getEditableRecordID(); if (inEditionRecordID) { - return this._saveLine(inEditionRecordID); + return this.renderer.commitChanges(inEditionRecordID).then(function () { + return self._saveLine(inEditionRecordID); + }); } return this._super.apply(this, arguments); }, @@ -767,21 +770,17 @@ var FieldX2Many = AbstractField.extend({ * did not agree to discard. */ _saveLine: function (recordID) { - var self = this; var def = $.Deferred(); - this.renderer.commitChanges(recordID).then(function () { // TODO wrong as no mutex protection - var fieldNames = self.renderer.canBeSaved(recordID); - if (fieldNames.length) { - self.trigger_up('discard_changes', { - recordID: recordID, - onSuccess: def.resolve.bind(def), - onFailure: def.reject.bind(def), - }); - } else { - self.renderer.setRowMode(recordID, 'readonly') - .done(def.resolve.bind(def)); - } - }); + var fieldNames = this.renderer.canBeSaved(recordID); + if (fieldNames.length) { + this.trigger_up('discard_changes', { + recordID: recordID, + onSuccess: def.resolve.bind(def), + onFailure: def.reject.bind(def), + }); + } else { + this.renderer.setRowMode(recordID, 'readonly').done(def.resolve.bind(def)); + } return def; }, @@ -900,9 +899,15 @@ var FieldX2Many = AbstractField.extend({ ev.stopPropagation(); this.trigger_up('mutexify', { action: function () { - return self._saveLine(ev.data.recordID) - .done(ev.data.onSuccess) - .fail(ev.data.onFailure); + return self.renderer.commitChanges(ev.data.recordID).then(function () { + self.trigger_up('mutexify', { + action: function () { + return self._saveLine(ev.data.recordID) + .done(ev.data.onSuccess) + .fail(ev.data.onFailure); + }, + }); + }); }, }); }, @@ -922,7 +927,7 @@ var FieldX2Many = AbstractField.extend({ id: rowID, data: data, }); - }) + }); }, /** * Adds field name information to the event, so that the view upstream is |
