From a0b1d64e441841cdcad70bb1659529348298e05b Mon Sep 17 00:00:00 2001 From: C?dric Krier Date: Wed, 13 Jan 2016 21:04:20 +0100 Subject: [PATCH] Record.defaut_get must return a promise which resolves with values The promise doesn't always return the values if there is any autocomplete and the promise is resolved before the set_default is called. So we use our custom deferred that will be resolved after the call to set_default and the autocomplete promises. issue5222 review19721002 --- src/model.js | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/model.js b/src/model.js index 932910a..3217c2a 100644 --- a/src/model.js +++ b/src/model.js @@ -766,11 +766,12 @@ this.model.fields[name].set_client(this, value, force_change); }, default_get: function() { + var dfd = jQuery.Deferred(); var promises = []; if (!jQuery.isEmptyObject(this.model.fields)) { var prm = this.model.execute('default_get', [Object.keys(this.model.fields)], this.get_context()); - var force_parent = function(values) { + prm.then(function(values) { if (this.group.parent && this.group.parent_name in this.group.model.fields) { var parent_field = @@ -785,13 +786,11 @@ this.group.parent.id; } } - return values; - }.bind(this); - prm = prm.pipe(force_parent).then(function(values) { this.set_default(values); - return values; + jQuery.when.apply(promises).then(function() { + dfd.resolve(values); + }); }.bind(this)); - promises.push(prm); } for (var fname in this.model.fields) { var field = this.model.fields[fname]; @@ -800,7 +799,7 @@ promises.push(this.do_autocomplete(fname)); } } - return jQuery.when.apply(promises); + return dfd; }, set_default: function(values) { var fieldnames = [];