changeset 10156791f1ed in sao:default details: https://hg.tryton.org/sao?cmd=changeset;node=10156791f1ed description: Set loaded fields first after O2M on_change calls
issue9930 review302811002 diffstat: src/model.js | 34 +++++++++++++++++++++++++++------- 1 files changed, 27 insertions(+), 7 deletions(-) diffs (72 lines): diff -r d8485f101974 -r 10156791f1ed src/model.js --- a/src/model.js Wed Feb 03 19:39:33 2021 +0100 +++ b/src/model.js Thu Feb 04 18:05:18 2021 +0100 @@ -2277,7 +2277,7 @@ if (value.add || value.update) { var context = this.get_context(record); fields = record._values[this.name].model.fields; - var field_names = {}; + var new_field_names = {}; var adding_values = []; if (value.add) { for (var i=0; i < value.add.length; i++) { @@ -2291,25 +2291,25 @@ if (!(f in fields) && (f != 'id') && (!~f.indexOf('.'))) { - field_names[f] = true; + new_field_names[f] = true; } }); }); } }); - if (!jQuery.isEmptyObject(field_names)) { + if (!jQuery.isEmptyObject(new_field_names)) { var args = { 'method': 'model.' + this.description.relation + '.fields_get', - 'params': [Object.keys(field_names), context] + 'params': [Object.keys(new_field_names), context] }; try { - fields = Sao.rpc(args, record.model.session, false); + new_fields = Sao.rpc(args, record.model.session, false); } catch (e) { return; } } else { - fields = {}; + new_fields = {}; } } @@ -2332,7 +2332,27 @@ } if (value.add || value.update) { - group.add_fields(fields); + // First set already added fields to prevent triggering a + // second on_change call + if (value.update) { + value.update.forEach(function(vals) { + if (!vals.id) { + return; + } + var record2 = group.get(vals.id); + if (record2) { + var vals_to_set = {}; + for (var key in vals) { + if (!(key in new_field_names)) { + vals_to_set[key] = vals[key]; + } + } + record2.set_on_change(vals_to_set); + } + }); + } + + group.add_fields(new_fields); if (value.add) { value.add.forEach(function(vals) { var new_record;