From e83c3fac559cb4924a3d290205c2dcd6f1822210 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Fri, 9 Oct 2015 20:52:44 +0200 Subject: [PATCH] Reload and call written only if record has something to save --- src/model.js | 42 ++++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/src/model.js b/src/model.js index 33c2e9b3c6..645eb48e61 100644 --- a/src/model.js +++ b/src/model.js @@ -431,29 +431,31 @@ var context = this.get_context(); var prm = jQuery.when(); var values = this.get(); - if (this.id < 0) { - prm = this.model.execute('create', [[values]], context); - var created = function(ids) { - this.id = ids[0]; - }; - prm.done(created.bind(this)); - } else { - if (!jQuery.isEmptyObject(values)) { - context._timestamp = this.get_timestamp(); - prm = this.model.execute('write', [[this.id], values], - context); + if ((this.id < 0) || !jQuery.isEmptyObject(values)) { + if (this.id < 0) { + prm = this.model.execute('create', [[values]], context); + var created = function(ids) { + this.id = ids[0]; + }; + prm.done(created.bind(this)); + } else { + if (!jQuery.isEmptyObject(values)) { + context._timestamp = this.get_timestamp(); + prm = this.model.execute('write', [[this.id], values], + context); + } } - } - prm = prm.done(function() { - this.cancel(); - if (force_reload) { - return this.reload(); - } - }.bind(this)); - if (this.group) { prm = prm.done(function() { - return this.group.written(this.id); + this.cancel(); + if (force_reload) { + return this.reload(); + } }.bind(this)); + if (this.group) { + prm = prm.done(function() { + return this.group.written(this.id); + }.bind(this)); + } } if (this.group.parent) { delete this.group.parent._changed[this.group.child_name];