diff options
| author | Diep Huu Hoang <mr.diephuuhoang@gmail.com> | 2017-01-24 04:01:14 +0700 |
|---|---|---|
| committer | Joren Van Onder <jov@odoo.com> | 2017-01-27 16:12:36 -0800 |
| commit | dff352acdb8b15b59bb4257814e62c4e46798739 (patch) | |
| tree | ebbdd3f3564c578e60404976a0170e8a8ae049e7 /addons | |
| parent | e366ee354285571efc8b4e76ce4be0572d566199 (diff) | |
[FIX] point_of_sale: prevent losing orders when validating during sync
When validating a new order in between the create_from_ui RPC call and
the corresponding callback this new order was lost. There were two
reasons for this.
First of all, the Mutex supposed to prevent multiple create_from_ui RPC
calls from happening at the same time did not return a Deferred. This is
problematic because this function gets passed to jQuery.when() which
will consider functions that do not return a Deferred to be resolved
upon return.
Secondly, the resolved callback of the create_from_ui RPC call naively
deleted all paid orders, assuming they were all successfully sent to the
backend. This is not the case when an order is added to the orders array
in between the RPC call and the callback.
Closes #15190
Diffstat (limited to 'addons')
| -rw-r--r-- | addons/point_of_sale/static/src/js/models.js | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/addons/point_of_sale/static/src/js/models.js b/addons/point_of_sale/static/src/js/models.js index 3880049e6d3..819dd4a5ee8 100644 --- a/addons/point_of_sale/static/src/js/models.js +++ b/addons/point_of_sale/static/src/js/models.js @@ -682,6 +682,8 @@ exports.PosModel = Backbone.Model.extend({ flushed.always(function(ids){ pushed.resolve(); }); + + return flushed; }); return pushed; }, @@ -782,6 +784,11 @@ exports.PosModel = Backbone.Model.extend({ var self = this; var timeout = typeof options.timeout === 'number' ? options.timeout : 7500 * orders.length; + // Keep the order ids that are about to be sent to the + // backend. In between create_from_ui and the success callback + // new orders may have been added to it. + var order_ids_to_sync = _.pluck(orders, 'id'); + // we try to send the order. shadow prevents a spinner if it takes too long. (unless we are sending an invoice, // then we want to notify the user that we are waiting on something ) var posOrderModel = new Model('pos.order'); @@ -796,8 +803,8 @@ exports.PosModel = Backbone.Model.extend({ timeout: timeout } ).then(function (server_ids) { - _.each(orders, function (order) { - self.db.remove_order(order.id); + _.each(order_ids_to_sync, function (order_id) { + self.db.remove_order(order_id); }); self.set('failed',false); return server_ids; |
