From cc6b224bb0329069e270f4f84298d8027f14a8db Mon Sep 17 00:00:00 2001 From: "Pedram (pebr)" Date: Wed, 10 Apr 2024 10:52:55 +0200 Subject: [PATCH] [FIX] point_of_sale: preserve a saved order state during sync failures If an order was validated in PoS but encountered a sync error, the order would revert to a draft state and no receipt would be printed. However, if an order was validated in PoS without internet, the receipt could still be printed. When the internet connection was restored, the system would attempt to validate the unsynced order. If a server error occurred during this process, the system would try to revert the order to a draft state and fail. This behavior is not ideal as an order with a printed receipt should not be modified or changed. This commit ensures that in the event of a sync failure, the saved orders do not revert to a draft state. opw-3858994 closes odoo/odoo#161250 Signed-off-by: Joseph Caburnay (jcb) --- addons/point_of_sale/static/src/app/store/pos_store.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/addons/point_of_sale/static/src/app/store/pos_store.js b/addons/point_of_sale/static/src/app/store/pos_store.js index e9105ef046f..757559ad230 100644 --- a/addons/point_of_sale/static/src/app/store/pos_store.js +++ b/addons/point_of_sale/static/src/app/store/pos_store.js @@ -1163,6 +1163,8 @@ export class PosStore extends Reactive { } push_orders(opts = {}) { + // The 'printedOrders' is added to prevent printed orders from being reverted to draft + opts = Object.assign({ printedOrders: true }, opts); return this.pushOrderMutex.exec(() => this._flush_orders(this.db.get_orders(), opts)); } @@ -1173,7 +1175,7 @@ export class PosStore extends Reactive { // Send validated orders to the backend. // Resolves to the backend ids of the synced orders. - async _flush_orders(orders, options) { + async _flush_orders(orders, options = {}) { try { const server_ids = await this._save_to_server(orders, options); for (let i = 0; i < server_ids.length; i++) { @@ -1182,7 +1184,7 @@ export class PosStore extends Reactive { } return server_ids; } catch (error) { - if (!(error instanceof ConnectionLostError)) { + if (!(error instanceof ConnectionLostError) && !options.printedOrders) { for (const order of orders) { const reactiveOrder = this.orders.find((o) => o.uid === order.id); reactiveOrder.finalized = false;