changeset 35975ddc2b87 in sao:4.8
details: https://hg.tryton.org/sao?cmd=changeset;node=35975ddc2b87
description:
        Return rejected promise when creation fails

        issue8168
        review51631002
        (grafted from cfc42be09a25768dacb1242c530b62c6d5e62368)
diffstat:

 src/model.js  |   7 ++++++-
 src/screen.js |  10 ++--------
 2 files changed, 8 insertions(+), 9 deletions(-)

diffs (44 lines):

diff -r f5229fde9ba4 -r 35975ddc2b87 src/model.js
--- a/src/model.js      Thu May 16 17:46:33 2019 +0200
+++ b/src/model.js      Wed May 01 21:58:01 2019 +0200
@@ -502,7 +502,12 @@
             if ((this.id < 0) || !jQuery.isEmptyObject(values)) {
                 if (this.id < 0) {
                     // synchronous call to avoid multiple creation
-                    this.id = this.model.execute('create', [[values]], 
context,  false)[0];
+                    try {
+                        this.id = this.model.execute(
+                            'create', [[values]], context,  false)[0];
+                    } catch (e) {
+                        return jQuery.Deferred().reject(e);
+                    }
                 } else {
                     if (!jQuery.isEmptyObject(values)) {
                         context._timestamp = this.get_timestamp();
diff -r f5229fde9ba4 -r 35975ddc2b87 src/screen.js
--- a/src/screen.js     Thu May 16 17:46:33 2019 +0200
+++ b/src/screen.js     Wed May 01 21:58:01 2019 +0200
@@ -1296,8 +1296,7 @@
                     }
                 }.bind(this));
             }
-            var dfd = jQuery.Deferred();
-            prm.then(function(current_record) {
+            return prm.then(function(current_record) {
                 if (path && current_record && current_record.id) {
                     path.splice(-1, 1,
                             [path[path.length - 1][0], current_record.id]);
@@ -1305,12 +1304,7 @@
                 return this.group.get_by_path(path).then(function(record) {
                     this.set_current_record(record);
                 }.bind(this));
-            }.bind(this)).then(function() {
-                this.display().always(dfd.resolve);
-            }.bind(this), function() {
-                this.display().always(dfd.reject);
-            }.bind(this));
-            return dfd.promise();
+            }.bind(this)).always(this.display.bind(this));
         },
         set_cursor: function(new_, reset_view) {
             if (!this.current_view) {

Reply via email to