[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#106817

X-original-commit: 0ad071e5b132b8f24b8fccf1624ccf97778fe27b
Signed-off-by: Trinh Jacky (trj) <trj@odoo.com>
This commit is contained in:
Fernanda Hernández
2022-11-30 11:09:01 +01:00
committed by Jacky (trj)
parent b7e06b8c37
commit f0790c63e9
2 changed files with 35 additions and 1 deletions
@@ -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
@@ -1372,6 +1386,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
@@ -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);
}
}
}