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

        issue8168
        review51631002
diffstat:

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

diffs (44 lines):

diff -r 6ec86ad09550 -r cfc42be09a25 src/model.js
--- a/src/model.js      Wed May 01 18:05:27 2019 +0200
+++ b/src/model.js      Wed May 01 21:58:01 2019 +0200
@@ -513,7 +513,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 6ec86ad09550 -r cfc42be09a25 src/screen.js
--- a/src/screen.js     Wed May 01 18:05:27 2019 +0200
+++ b/src/screen.js     Wed May 01 21:58:01 2019 +0200
@@ -1437,8 +1437,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]);
@@ -1446,12 +1445,7 @@
                 return this.group.get_by_path(path).then(function(record) {
                     this.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