From 309734f4aab0467d833cdbc24924d1f19de94149 Mon Sep 17 00:00:00 2001 From: Preksha Chouhan Date: Fri, 28 Apr 2023 11:37:40 +0000 Subject: [PATCH] [FIX] point_of_sale: prevent traceback while name of coins/bill is string When we input some string in many2many field under Coins/Bills in configuration setting of point of sale module . it will give an error with the message - 'could not convert string to float' Steps to Produce:- 1. Go to Point of Sale then configuration 2. click on 'Settings' 3. Under 'Payment' input some string in Coins/Bills Trace-back will be generated. Reason - The 'name_create' method of the 'pos_bill' model generates an error when a string is provided as input for the 'name' field, since the expression 'float(name)' is unable to convert a string to a float. Applying these changes will resolve this issue. Sentry - 4122478677 closes odoo/odoo#122094 X-original-commit: 8e553f06f1a8e63dbfb4439e989ef27d577ea50f Signed-off-by: Joseph Caburnay (jcb) Signed-off-by: Preksha Chouhan (prec) --- addons/point_of_sale/i18n/point_of_sale.pot | 7 +++++++ addons/point_of_sale/models/pos_bill.py | 9 +++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/addons/point_of_sale/i18n/point_of_sale.pot b/addons/point_of_sale/i18n/point_of_sale.pot index f5c211abfc3..c7dbf838b7a 100644 --- a/addons/point_of_sale/i18n/point_of_sale.pot +++ b/addons/point_of_sale/i18n/point_of_sale.pot @@ -6397,6 +6397,13 @@ msgid "" " Please contact your manager to accept the closing difference." msgstr "" +#. module: point_of_sale +#. odoo-python +#: code:addons/point_of_sale/models/pos_bill.py:0 +#, python-format +msgid "The name of the Coins/Bills must be a number." +msgstr "" + #. module: point_of_sale #: model:ir.model.constraint,message:point_of_sale.constraint_pos_session_uniq_name msgid "The name of this POS Session must be unique!" diff --git a/addons/point_of_sale/models/pos_bill.py b/addons/point_of_sale/models/pos_bill.py index 6437be8e335..87d17c784a8 100644 --- a/addons/point_of_sale/models/pos_bill.py +++ b/addons/point_of_sale/models/pos_bill.py @@ -1,4 +1,5 @@ -from odoo import api, fields, models +from odoo import api, fields, models, _ +from odoo.exceptions import UserError class Bill(models.Model): @@ -12,5 +13,9 @@ class Bill(models.Model): @api.model def name_create(self, name): - result = super().create({"name": name, "value": float(name)}) + try: + value = float(name) + except: + raise UserError(_("The name of the Coins/Bills must be a number.")) + result = super().create({"name": name, "value": value}) return result.name_get()[0]