From 0f0576424c58bb377c522add9029b462f330ed52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20BEAU?= Date: Tue, 11 Aug 2020 10:14:27 +0200 Subject: [PATCH] [IMP] use selection field to be safer, add maintainers --- base_exception/__manifest__.py | 1 + base_exception/models/base_exception.py | 14 ++------------ base_exception/tests/purchase_test.py | 9 +++++++++ base_exception/tests/test_base_exception.py | 4 ++-- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/base_exception/__manifest__.py b/base_exception/__manifest__.py index e8c448b4b..0833fbf05 100644 --- a/base_exception/__manifest__.py +++ b/base_exception/__manifest__.py @@ -13,6 +13,7 @@ "Odoo Community Association (OCA)", "website": "https://github.com/OCA/server-tools", "depends": ["base_setup"], + "maintainers": ["hparfr", "sebastienbeau"], "license": "AGPL-3", "data": [ "security/base_exception_security.xml", diff --git a/base_exception/models/base_exception.py b/base_exception/models/base_exception.py index 45c153276..acf8f667d 100644 --- a/base_exception/models/base_exception.py +++ b/base_exception/models/base_exception.py @@ -39,7 +39,7 @@ class ExceptionRule(models.Model): " are evaluated with several records", ) domain = fields.Char("Domain") - method = fields.Char("Method", readonly=True) + method = fields.Selection(selection=[], string="Method", readonly=True) active = fields.Boolean("Active", default=True) code = fields.Text( "Python Code", @@ -53,10 +53,7 @@ class ExceptionRule(models.Model): if ( (rule.exception_type == "by_py_code" and not rule.code) or (rule.exception_type == "by_domain" and not rule.domain) - or ( - rule.exception_type == "by_method" - and not self._check_method_valid(rule.method, rule.model) - ) + or (rule.exception_type == "by_method" and not rule.method) ): raise ValidationError( _( @@ -66,13 +63,6 @@ class ExceptionRule(models.Model): ) ) - def _check_method_valid(self, method_name, model_name): - model = self.env[model_name] - method = getattr(model, method_name) - if method and callable(method): - return True - return False - @api.multi def _get_domain(self): """ override me to customize domains according exceptions cases """ diff --git a/base_exception/tests/purchase_test.py b/base_exception/tests/purchase_test.py index c7c4dfe4d..ace5342ce 100644 --- a/base_exception/tests/purchase_test.py +++ b/base_exception/tests/purchase_test.py @@ -3,6 +3,15 @@ from odoo import api, fields, models +class ExceptionRule(models.Model): + _inherit = "exception.rule" + _name = "exception.rule" + + method = fields.Selection( + selection_add=[('exception_method_no_zip', 'Purchase exception no zip')] + ) + + class PurchaseTest(models.Model): _inherit = "base.exception" _name = "base.exception.test.purchase" diff --git a/base_exception/tests/test_base_exception.py b/base_exception/tests/test_base_exception.py index 55c215d29..d56df7ed6 100644 --- a/base_exception/tests/test_base_exception.py +++ b/base_exception/tests/test_base_exception.py @@ -5,7 +5,7 @@ from odoo.tests import common from odoo.exceptions import ValidationError from odoo import fields from .common import setup_test_model -from .purchase_test import PurchaseTest, LineTest +from .purchase_test import PurchaseTest, LineTest, ExceptionRule import logging _logger = logging.getLogger(__name__) @@ -17,7 +17,7 @@ class TestBaseException(common.SavepointCase): @classmethod def setUpClass(cls): super(TestBaseException, cls).setUpClass() - setup_test_model(cls.env, [PurchaseTest, LineTest]) + setup_test_model(cls.env, [PurchaseTest, LineTest, ExceptionRule]) cls.base_exception = cls.env["base.exception"] cls.exception_rule = cls.env["exception.rule"]