Browse Source

[IMP] use selection field to be safer, add maintainers

12.0-mig-module_prototyper_last
Sébastien BEAU 4 years ago
parent
commit
0f0576424c
  1. 1
      base_exception/__manifest__.py
  2. 14
      base_exception/models/base_exception.py
  3. 9
      base_exception/tests/purchase_test.py
  4. 4
      base_exception/tests/test_base_exception.py

1
base_exception/__manifest__.py

@ -13,6 +13,7 @@
"Odoo Community Association (OCA)", "Odoo Community Association (OCA)",
"website": "https://github.com/OCA/server-tools", "website": "https://github.com/OCA/server-tools",
"depends": ["base_setup"], "depends": ["base_setup"],
"maintainers": ["hparfr", "sebastienbeau"],
"license": "AGPL-3", "license": "AGPL-3",
"data": [ "data": [
"security/base_exception_security.xml", "security/base_exception_security.xml",

14
base_exception/models/base_exception.py

@ -39,7 +39,7 @@ class ExceptionRule(models.Model):
" are evaluated with several records", " are evaluated with several records",
) )
domain = fields.Char("Domain") domain = fields.Char("Domain")
method = fields.Char("Method", readonly=True)
method = fields.Selection(selection=[], string="Method", readonly=True)
active = fields.Boolean("Active", default=True) active = fields.Boolean("Active", default=True)
code = fields.Text( code = fields.Text(
"Python Code", "Python Code",
@ -53,10 +53,7 @@ class ExceptionRule(models.Model):
if ( if (
(rule.exception_type == "by_py_code" and not rule.code) (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_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( 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 @api.multi
def _get_domain(self): def _get_domain(self):
""" override me to customize domains according exceptions cases """ """ override me to customize domains according exceptions cases """

9
base_exception/tests/purchase_test.py

@ -3,6 +3,15 @@
from odoo import api, fields, models 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): class PurchaseTest(models.Model):
_inherit = "base.exception" _inherit = "base.exception"
_name = "base.exception.test.purchase" _name = "base.exception.test.purchase"

4
base_exception/tests/test_base_exception.py

@ -5,7 +5,7 @@ from odoo.tests import common
from odoo.exceptions import ValidationError from odoo.exceptions import ValidationError
from odoo import fields from odoo import fields
from .common import setup_test_model from .common import setup_test_model
from .purchase_test import PurchaseTest, LineTest
from .purchase_test import PurchaseTest, LineTest, ExceptionRule
import logging import logging
_logger = logging.getLogger(__name__) _logger = logging.getLogger(__name__)
@ -17,7 +17,7 @@ class TestBaseException(common.SavepointCase):
@classmethod @classmethod
def setUpClass(cls): def setUpClass(cls):
super(TestBaseException, cls).setUpClass() 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.base_exception = cls.env["base.exception"]
cls.exception_rule = cls.env["exception.rule"] cls.exception_rule = cls.env["exception.rule"]

Loading…
Cancel
Save