From 18651864dd3bf27fd1c910888f5dbbed4046d42b Mon Sep 17 00:00:00 2001 From: Joseph Caburnay Date: Mon, 22 Jun 2020 11:55:04 +0000 Subject: [PATCH] [FIX] pos_restaurant: selectedTable can change during user input In this commit, we make sure that the selectedTable doesn't change even during the popup is shown to the user. During testing, there might be rouge clicks that click the .floor-map element which deselects the selected floor, making the value of this.selectedTable to be false, causing runtime error. --- .../src/js/Screens/FloorScreen/FloorScreen.js | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/addons/pos_restaurant/static/src/js/Screens/FloorScreen/FloorScreen.js b/addons/pos_restaurant/static/src/js/Screens/FloorScreen/FloorScreen.js index 1a4a1a2f14d..587fe6e2d7c 100644 --- a/addons/pos_restaurant/static/src/js/Screens/FloorScreen/FloorScreen.js +++ b/addons/pos_restaurant/static/src/js/Screens/FloorScreen/FloorScreen.js @@ -87,17 +87,18 @@ odoo.define('pos_restaurant.FloorScreen', function (require) { } } async _changeSeatsNum() { - if (!this.selectedTable) return; + const selectedTable = this.selectedTable + if (!selectedTable) return; const { confirmed, payload: inputNumber } = await this.showPopup('NumberPopup', { - startingValue: this.selectedTable.seats, + startingValue: selectedTable.seats, cheap: true, title: this.env._t('Number of Seats ?'), }); if (!confirmed) return; - const newSeatsNum = parseInt(inputNumber, 10) || this.selectedTable.seats; - if (newSeatsNum !== this.selectedTable.seats) { - this.selectedTable.seats = newSeatsNum; - await this._save(this.selectedTable); + const newSeatsNum = parseInt(inputNumber, 10) || selectedTable.seats; + if (newSeatsNum !== selectedTable.seats) { + selectedTable.seats = newSeatsNum; + await this._save(selectedTable); } } async _changeShape() { @@ -107,15 +108,16 @@ odoo.define('pos_restaurant.FloorScreen', function (require) { await this._save(this.selectedTable); } async _renameTable() { - if (!this.selectedTable) return; + const selectedTable = this.selectedTable; + if (!selectedTable) return; const { confirmed, payload: newName } = await this.showPopup('TextInputPopup', { - startingValue: this.selectedTable.name, + startingValue: selectedTable.name, title: this.env._t('Table Name ?'), }); if (!confirmed) return; - if (newName !== this.selectedTable.name) { - this.selectedTable.name = newName; - await this._save(this.selectedTable); + if (newName !== selectedTable.name) { + selectedTable.name = newName; + await this._save(selectedTable); } } async _setTableColor({ detail: color }) {