From 0ad071e5b132b8f24b8fccf1624ccf97778fe27b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fernanda=20Hern=C3=A1ndez?= <fernanda@vauxoo.com>
Date: Tue, 8 Nov 2022 23:34:39 +0000
Subject: [PATCH] [FIX] pos_restaurant: validate number of guest put by user

The user could make the mistake to put a large number in the `Guests`
input in the POS order and this is not validated, even an number more large
for the capacity of an integer, raising an uncontrolled error:

`psycopg2.errors.NumericValueOutOfRange: integer out of range`

this commit is adding a validation error in order to limit the number of `Guests`
with the maximum number for an integer:  2**31 - 1

closes odoo/odoo#106523

X-original-commit: 0ff14cc86980a1b9d8cb743d1e3d7cac12f4f92f
Signed-off-by: Trinh Jacky (trj) <trj@odoo.com>
---
 addons/pos_restaurant/i18n/pos_restaurant.pot | 21 +++++++++++++++++++
 .../ControlButtons/TableGuestsButton.js       | 15 ++++++++++++-
 2 files changed, 35 insertions(+), 1 deletion(-)

diff --git a/addons/pos_restaurant/i18n/pos_restaurant.pot b/addons/pos_restaurant/i18n/pos_restaurant.pot
index 2786e5b71aad..0572b1fe85ca 100644
--- a/addons/pos_restaurant/i18n/pos_restaurant.pot
+++ b/addons/pos_restaurant/i18n/pos_restaurant.pot
@@ -218,6 +218,13 @@ msgstr ""
 msgid "Bill Splitting"
 msgstr ""
 
+#. module: pos_restaurant
+#. openerp-web
+#: code:addons/pos_restaurant/static/src/js/Screens/ProductScreen/ControlButtons/TableGuestsButton.js:0
+#, python-format
+msgid "Blocked action"
+msgstr ""
+
 #. module: pos_restaurant
 #. openerp-web
 #: code:addons/pos_restaurant/static/src/xml/Screens/FloorScreen/EditBar.xml:0
@@ -286,6 +293,13 @@ msgstr ""
 msgid "Config Settings"
 msgstr ""
 
+#. module: pos_restaurant
+#. openerp-web
+#: code:addons/pos_restaurant/static/src/js/ChromeWidgets/TicketButton.js:0
+#, python-format
+msgid "Connection Error"
+msgstr ""
+
 #. module: pos_restaurant
 #: model:ir.model.fields,field_description:pos_restaurant.field_restaurant_floor__create_uid
 #: model:ir.model.fields,field_description:pos_restaurant.field_restaurant_printer__create_uid
@@ -1387,6 +1401,13 @@ msgstr ""
 msgid "Yellow"
 msgstr ""
 
+#. module: pos_restaurant
+#. openerp-web
+#: code:addons/pos_restaurant/static/src/js/Screens/ProductScreen/ControlButtons/TableGuestsButton.js:0
+#, python-format
+msgid "You cannot put a number that exceeds %s "
+msgstr ""
+
 #. module: pos_restaurant
 #: code:addons/pos_restaurant/models/pos_restaurant.py:0
 #, python-format
diff --git a/addons/pos_restaurant/static/src/js/Screens/ProductScreen/ControlButtons/TableGuestsButton.js b/addons/pos_restaurant/static/src/js/Screens/ProductScreen/ControlButtons/TableGuestsButton.js
index 962db9d6545a..0929b23e2dcd 100644
--- a/addons/pos_restaurant/static/src/js/Screens/ProductScreen/ControlButtons/TableGuestsButton.js
+++ b/addons/pos_restaurant/static/src/js/Screens/ProductScreen/ControlButtons/TableGuestsButton.js
@@ -26,7 +26,20 @@ odoo.define('pos_restaurant.TableGuestsButton', function(require) {
             });
 
             if (confirmed) {
-                this.env.pos.get_order().setCustomerCount(parseInt(inputNumber, 10) || 1);
+                const guestCount = parseInt(inputNumber, 10) || 1;
+                // Set the maximum number possible for an integer
+                const max_capacity = 2**31 - 1;
+                if (guestCount > max_capacity) {
+                    await this.showPopup('ErrorPopup', {
+                        title: this.env._t('Blocked action'),
+                        body: _.str.sprintf(
+                            this.env._t('You cannot put a number that exceeds %s '),
+                            max_capacity,
+                        ),
+                    });
+                    return;
+                }
+                this.env.pos.get_order().setCustomerCount(guestCount);
             }
         }
     }
-- 
GitLab