[FIX] check for invalid key

pull/2399/head
KKamaa 2023-01-31 05:55:00 +03:00
parent 44c66fecb5
commit fcaf19d858
2 changed files with 16 additions and 8 deletions

View File

@ -1,11 +1,8 @@
# Copyright 2023 Sunflower IT # Copyright 2023 Sunflower IT
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
import logging from odoo import _, api, models
from odoo.exceptions import UserError
from odoo import api, models
_logger = logging.getLogger(__name__)
class ResCompany(models.Model): class ResCompany(models.Model):
@ -19,8 +16,7 @@ class ResCompany(models.Model):
) )
res = self.env.cr.fetchone() res = self.env.cr.fetchone()
except Exception as e: except Exception as e:
_logger.error("\n\n ERROR: %s \n\n", e) raise UserError(_("Error: %s" % e))
return ""
else: else:
if res: if res:
return "%s" % res return "%s" % res

View File

@ -1,7 +1,7 @@
# Copyright 2023 Sunflower IT # Copyright 2023 Sunflower IT
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo.exceptions import AccessError from odoo.exceptions import AccessError, UserError
from odoo.tests.common import TransactionCase from odoo.tests.common import TransactionCase
@ -45,3 +45,15 @@ class TestSupportBranding(TransactionCase):
self.assertEquals(value_1, value_2) self.assertEquals(value_1, value_2)
self.assertEquals(value_1, self.demo_support_company_branding_url.value) self.assertEquals(value_1, self.demo_support_company_branding_url.value)
self.assertEquals(value_2, self.demo_support_company_branding_url.value) self.assertEquals(value_2, self.demo_support_company_branding_url.value)
# check if return if key is invalid
empty_val = self.company_obj.with_user(
self.admin_user
).get_ir_config_param_data("testing")
self.assertEquals(empty_val, "")
# check if return of key if invalid
with self.assertRaises(UserError):
empty_val = self.company_obj.with_user(
self.admin_user
).get_ir_config_param_data(True)