diff options
| author | Christophe Simonis <chs@odoo.com> | 2018-04-16 19:50:50 +0200 |
|---|---|---|
| committer | Christophe Simonis <chs@odoo.com> | 2018-04-16 19:50:50 +0200 |
| commit | 74033eb007749c88b84ea883b006a5877355306e (patch) | |
| tree | 8f8b6cb22cc2bf6046ba04e388ea29855a33c597 /addons/web/static/src/js/fields/relational_fields.js | |
| parent | 71cdefd9f41881d9720433d5fc7732759098f9a4 (diff) | |
| parent | 90f8f17fb4fc795c2c12d68d21900e81f3d7a223 (diff) | |
[MERGE] forward port branch saas-11.2 up to 90f8f17fb4f
Diffstat (limited to 'addons/web/static/src/js/fields/relational_fields.js')
| -rw-r--r-- | addons/web/static/src/js/fields/relational_fields.js | 31 |
1 files changed, 23 insertions, 8 deletions
diff --git a/addons/web/static/src/js/fields/relational_fields.js b/addons/web/static/src/js/fields/relational_fields.js index 93c924fad4c..c3df03fcff9 100644 --- a/addons/web/static/src/js/fields/relational_fields.js +++ b/addons/web/static/src/js/fields/relational_fields.js @@ -1059,7 +1059,7 @@ var FieldX2Many = AbstractField.extend({ */ _onEditLine: function (ev) { ev.stopPropagation(); - this.trigger_up('freeze_order', {id: this.value.id}); + this.trigger_up('edited_list', { id: this.value.id }); var editedRecord = this.value.data[ev.data.index]; this.renderer.setRowMode(editedRecord.id, 'edit') .done(ev.data.onSuccess); @@ -1147,7 +1147,7 @@ var FieldX2Many = AbstractField.extend({ _onResequence: function (event) { event.stopPropagation(); var self = this; - this.trigger_up('freeze_order', {id: this.value.id}); + this.trigger_up('edited_list', { id: this.value.id }); var rowIDs = event.data.rowIDs.slice(); var rowID = rowIDs.pop(); var defs = _.map(rowIDs, function (rowID, index) { @@ -1300,7 +1300,7 @@ var FieldOne2Many = FieldX2Many.extend({ } } else if (!this.creatingRecord) { this.creatingRecord = true; - this.trigger_up('freeze_order', {id: this.value.id}); + this.trigger_up('edited_list', { id: this.value.id }); this._setValue({ operation: 'CREATE', position: this.editable, @@ -1330,12 +1330,27 @@ var FieldOne2Many = FieldX2Many.extend({ // we don't want interference with the components upstream. ev.stopPropagation(); + var self = this; var id = ev.data.id; - // trigger an empty 'UPDATE' operation when the user clicks on 'Save' in - // the dialog, to notify the main record that a subrecord of this - // relational field has changed (those changes will be already stored on - // that subrecord, thanks to the 'Save'). - var onSaved = this._setValue.bind(this, { operation: 'UPDATE', id: id }, {}); + var onSaved = function (record, hasChanged) { + if (!hasChanged) { + return; + } + if (_.some(self.value.data, {id: record.id})) { + // the record already exists in the relation, so trigger an + // empty 'UPDATE' operation when the user clicks on 'Save' in + // the dialog, to notify the main record that a subrecord of + // this relational field has changed (those changes will be + // already stored on that subrecord, thanks to the 'Save'). + self._setValue({ operation: 'UPDATE', id: record.id }); + } else { + // the record isn't in the relation yet, so add it ; this can + // happen if the user clicks on 'Save & New' in the dialog (the + // opened record will be updated, and other records will be + // created) + self._setValue({ operation: 'ADD', id: record.id }); + } + }; this._openFormDialog({ id: id, on_saved: onSaved, |
