From 9b1b36e2dff2d86e75b0a7625f893cdd8bb39b52 Mon Sep 17 00:00:00 2001 From: Joseph Caburnay Date: Fri, 15 Jul 2022 11:33:27 +0000 Subject: [PATCH] [FIX] point_of_sale: stuck when offline This only happens after the introduction of PosPopupController. ProductInfoPopup and ClosePosPopup manages their own error but it's not compatible with the new controller. Basically after the error in onWillStart, the renderer will attempt to render the component but there will be error which results to *not* being able to call onMounted hook which is responsible in calling error popup. Furthermore, the PosPopupController is unable to cleanup the original popup that failed. So the connection returns, all the unshown popups will show up again. In this change, we clear the problematic popup by immediately calling `cancel` and showing the proper error in the onWillStart call stack, no need for the onMounted hook. IMPROVEMENT: Perhaps it's better to delegate the management of error to the component that requests for showing the popup, such that the popup popup is more or less dumb which only receives props, and not make it's own rpc during mounting. To reproduce: https://watch.screencastify.com/v/1LE31gapmkIjTfkB7dTY closes odoo/odoo#96166 X-original-commit: f692b403213d593d7327a2cbc33bd00359fd079d Signed-off-by: Masereel Pierre Signed-off-by: Joseph Caburnay (jcb) --- .../static/src/js/Popups/ClosePosPopup.js | 15 +++------------ .../static/src/js/Popups/ProductInfoPopup.js | 14 +++----------- 2 files changed, 6 insertions(+), 23 deletions(-) diff --git a/addons/point_of_sale/static/src/js/Popups/ClosePosPopup.js b/addons/point_of_sale/static/src/js/Popups/ClosePosPopup.js index efaf7ee7e7d..377d30f8e7f 100644 --- a/addons/point_of_sale/static/src/js/Popups/ClosePosPopup.js +++ b/addons/point_of_sale/static/src/js/Popups/ClosePosPopup.js @@ -6,7 +6,7 @@ odoo.define('point_of_sale.ClosePosPopup', function(require) { const { identifyError } = require('point_of_sale.utils'); const { ConnectionLostError, ConnectionAbortedError} = require('@web/core/network/rpc_service') - const { onWillStart, onMounted, useState } = owl; + const { onWillStart, useState } = owl; /** * This popup needs to be self-dependent because it needs to be called from different place. @@ -22,7 +22,6 @@ odoo.define('point_of_sale.ClosePosPopup', function(require) { displayMoneyDetailsPopup: false, }); onWillStart(this.onWillStart); - onMounted(this.onMounted); } async onWillStart() { try { @@ -54,22 +53,14 @@ odoo.define('point_of_sale.ClosePosPopup', function(require) { } Object.assign(this.state, state); } catch (error) { - this.error = error; - } - } - /* - * Since this popup need to be self dependent, in case of an error, the popup need to be closed on its own. - */ - onMounted() { - if (this.error) { this.cancel(); - if (identifyError(this.error) instanceof ConnectionLostError) { + if (identifyError(error) instanceof ConnectionLostError) { this.showPopup('ErrorPopup', { title: this.env._t('Network Error'), body: this.env._t('Please check your internet connection and try again.'), }); } else { - throw this.error; + throw error; } } } diff --git a/addons/point_of_sale/static/src/js/Popups/ProductInfoPopup.js b/addons/point_of_sale/static/src/js/Popups/ProductInfoPopup.js index b29a9531b05..a066cc7db11 100644 --- a/addons/point_of_sale/static/src/js/Popups/ProductInfoPopup.js +++ b/addons/point_of_sale/static/src/js/Popups/ProductInfoPopup.js @@ -3,6 +3,7 @@ odoo.define('point_of_sale.ProductInfoPopup', function(require) { const AbstractAwaitablePopup = require('point_of_sale.AbstractAwaitablePopup'); const Registries = require('point_of_sale.Registries'); + const { identifyError } = require('point_of_sale.utils'); const { ConnectionLostError } = require('@web/core/network/rpc_service') /** @@ -17,7 +18,6 @@ odoo.define('point_of_sale.ProductInfoPopup', function(require) { setup() { super.setup(); owl.onWillStart(this.onWillStart); - owl.onMounted(this.onMounted); } async onWillStart() { const order = this.env.pos.get_order(); @@ -48,22 +48,14 @@ odoo.define('point_of_sale.ProductInfoPopup', function(require) { this.orderMarginCurrency = this.env.pos.format_currency(orderMargin); this.orderMarginPercent = orderPriceWithoutTax ? Math.round(orderMargin/orderPriceWithoutTax * 10000) / 100 : 0; } catch (error) { - this.error = error; - } - } - /* - * Since this popup need to be self dependent, in case of an error, the popup need to be closed on its own. - */ - onMounted() { - if (this.error) { this.cancel(); - if (this.error.message instanceof ConnectionLostError) { + if (identifyError(error) instanceof ConnectionLostError) { this.showPopup('ErrorPopup', { title: this.env._t('Network Error'), body: this.env._t('Cannot access product information screen if offline.'), }); } else { - throw this.error; + throw error; } } }