From 9c9683ebb0ed271ee2584b514b0455574b9c3f1e Mon Sep 17 00:00:00 2001 From: Hpar Date: Fri, 27 Apr 2018 13:13:38 +0200 Subject: [PATCH] [10][FIX] Protect crash at runtime if oca-decorator not installed (#254) Fail silently if @foreach not loaded --- pos_pricelist/__init__.py | 7 ++++++- pos_pricelist/models/pos_config.py | 6 +----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/pos_pricelist/__init__.py b/pos_pricelist/__init__.py index 10e21b51..5919be3a 100644 --- a/pos_pricelist/__init__.py +++ b/pos_pricelist/__init__.py @@ -2,4 +2,9 @@ # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl). from .hooks import post_init_hook -from . import models +try: + from . import models +except ImportError: # pragma: no-cover + import logging + _logger = logging.getLogger(__name__) + _logger.warn("Missing dependency", exc_info=True) diff --git a/pos_pricelist/models/pos_config.py b/pos_pricelist/models/pos_config.py index e30b03af..a6da8a69 100644 --- a/pos_pricelist/models/pos_config.py +++ b/pos_pricelist/models/pos_config.py @@ -4,15 +4,11 @@ from odoo import _, api, fields, models from odoo.exceptions import ValidationError +from oca.decorators import foreach # pylint: disable=W7935 import logging _logger = logging.getLogger(__name__) -try: - from oca.decorators import foreach -except ImportError: # pragma: no-cover - _logger.warn("Missing dependency", exc_info=True) - class PosConfig(models.Model): _inherit = 'pos.config'