[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) <jcb@odoo.com>
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user