diff --git a/sao/src/model.js b/sao/src/model.js index 3687dd1ad0..fc81cd5875 100644 --- a/sao/src/model.js +++ b/sao/src/model.js @@ -223,7 +223,7 @@ } else { this.parent.modified_fields[this.child_name] = true; this.parent.model.fields[this.child_name].changed(this.parent); - this.parent.validate(null, true, false, true); + this.parent.validate(null, true, false); this.parent.group.record_modified(); } }; @@ -597,12 +597,16 @@ } return prm; }, - reload: function(fields) { + reload: function(fields, async=true) { if (this.id < 0) { - return jQuery.when(); + return async? jQuery.when() : null; } if (!fields) { - return this.load('*'); + return this.load('*', async); + } else if (!async) { + for (let field of fields) { + this.load(field, async); + } } else { var prms = fields.map(field => this.load(field)); return jQuery.when.apply(jQuery, prms); @@ -866,7 +870,7 @@ fieldnames.push(name); } if (validate) { - this.validate(fieldnames, true, false, false); + this.validate(fieldnames, true, false); } if (modified) { this.set_modified(); @@ -1283,38 +1287,25 @@ return values[0].rec_name; }); }, - validate: function(fields, softvalidation, pre_validate, sync) { - const validate_fields = () => { - var result = true; - for (var fname in this.model.fields) { - // Skip not loaded fields if sync and record is not new - if (sync && this.id >= 0 && !(fname in this._loaded)) { - continue; - } - if (!this.model.fields.hasOwnProperty(fname)) { - continue; - } - var field = this.model.fields[fname]; - if (fields && !~fields.indexOf(fname)) { - continue; - } - if (field.description.readonly) { - continue; - } - if (fname == this.group.exclude_field) { - continue; - } - if (!field.validate(this, softvalidation, pre_validate)) { - result = false; - } + validate: function(fields, softvalidation, pre_validate) { + this._check_load(fields); + var result = true; + for (var fname in this.model.fields) { + var field = this.model.fields[fname]; + if (fields && !~fields.indexOf(fname)) { + continue; + } + if (field.description.readonly) { + continue; + } + if (fname == this.group.exclude_field) { + continue; + } + if (!field.validate(this, softvalidation, pre_validate)) { + result = false; } - return result; - }; - if (sync) { - return validate_fields(); - } else { - return this._check_load(fields).then(validate_fields); } + return result; }, pre_validate: function() { if (jQuery.isEmptyObject(this.modified_fields)) { @@ -1336,9 +1327,8 @@ }, _check_load: function(fields) { if (!this.get_loaded(fields)) { - return this.reload(fields); + this.reload(fields, false); } - return jQuery.when(); }, get_loaded: function(fields) { if (!jQuery.isEmptyObject(fields)) { @@ -1587,11 +1577,11 @@ this.set(record, value); if (this._has_changed(previous_value, this.get(record))) { this.changed(record); - record.validate(null, true, false, true); + record.validate(null, true, false); record.set_modified(this.name); } else if (force_change) { this.changed(record); - record.validate(null, true, false, true); + record.validate(null, true, false); record.set_modified(); } }, @@ -2378,11 +2368,11 @@ this._set_value(record, value, false, modified); if (modified) { this.changed(record); - record.validate(null, true, false, true); + record.validate(null, true, false); record.set_modified(this.name); } else if (force_change) { this.changed(record); - record.validate(null, true, false, true); + record.validate(null, true, false); record.set_modified(); } }, @@ -2599,7 +2589,7 @@ !pre_validate) { continue; } - if (!record2.validate(null, softvalidation, ldomain, true)) { + if (!record2.validate(null, softvalidation, ldomain)) { invalid = 'children'; } } diff --git a/tryton/tryton/gui/window/view_form/model/record.py b/tryton/tryton/gui/window/view_form/model/record.py index 42da12a667..efd7fd659d 100644 --- a/tryton/tryton/gui/window/view_form/model/record.py +++ b/tryton/tryton/gui/window/view_form/model/record.py @@ -262,15 +262,8 @@ class Record: return self.group.fields def _check_load(self, fields=None): - if fields is not None: - if not self.get_loaded(fields): - self.reload(fields) - return True - return False - if not self.loaded: - self.reload() - return True - return False + if not self.get_loaded(fields): + self.reload(fields) def get_loaded(self, fields=None): if fields: @@ -406,10 +399,7 @@ class Record: return '' def validate(self, fields=None, softvalidation=False, pre_validate=None): - if isinstance(fields, list) and fields: - self._check_load(fields) - elif fields is None: - self._check_load() + self._check_load() res = True for field_name, field in list(self.group.fields.items()): if fields is not None and field_name not in fields: