[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
This commit is contained in:
committed by
Joren Van Onder
parent
e366ee3542
commit
dff352acdb
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user