diff --git a/sale_exception_portal/__manifest__.py b/sale_exception_portal/__manifest__.py index 4846e95f..9002214e 100644 --- a/sale_exception_portal/__manifest__.py +++ b/sale_exception_portal/__manifest__.py @@ -1,7 +1,7 @@ { 'name': 'Sale Exception Portal', 'summary': 'Display sale exceptions on customer portal', - 'version': '13.0.1.0.0', + 'version': '14.0.1.0.0', 'author': "Hibou Corp.", 'category': 'Sale', 'license': 'AGPL-3', diff --git a/sale_exception_portal/models/sale.py b/sale_exception_portal/models/sale.py index 03c88689..76874b3c 100644 --- a/sale_exception_portal/models/sale.py +++ b/sale_exception_portal/models/sale.py @@ -1,6 +1,4 @@ -import time from odoo import fields, models -from odoo.tools.safe_eval import safe_eval class ExceptionRule(models.Model): @@ -13,27 +11,7 @@ class SaleOrder(models.Model): _inherit = 'sale.order' def _check_sale_order_exceptions(self): - so_exceptions = self.env['exception.rule'].search([('active', '=', True), - ('model', '=', 'sale.order'), - ('exception_type', '=', 'by_py_code')]) - - reasons = [] - - for ex in so_exceptions: - # Globals won't expose modules used in exception rules python code. - # They will have to be manually passed through params. ex [time] - # Locals() can be used instead of defined params, but can also cause buggy behavior on return - params = {'sale': self, 'exception': ex, 'time': time} - try: - safe_eval(ex.code, - params, - mode='exec', - nocopy=True) # nocopy allows to return 'result' - if params.get('failed', False): - desc = ex.website_description or ex.description - message = {'title': ex.name, 'description': desc} - reasons.append(message) - except: - pass - + exception_ids = self.detect_exceptions() + exceptions = self.env['exception.rule'].browse(exception_ids) + reasons = [{'title': ex.name, 'description': ex.website_description or ex.description} for ex in exceptions] return reasons diff --git a/sale_exception_portal/tests/test_check_so_exceptions.py b/sale_exception_portal/tests/test_check_so_exceptions.py index 870ad1be..daf7d1af 100644 --- a/sale_exception_portal/tests/test_check_so_exceptions.py +++ b/sale_exception_portal/tests/test_check_so_exceptions.py @@ -25,7 +25,7 @@ class TestCheckSOExceptions(TransactionCase): 'order_line': [(0, 0, { 'product_id': self.sale_product.id, 'product_uom_qty': 1.0, - 'price_unit': 50.0, # Set lower than 100.0 to trigger the exception + 'price_unit': 50.0, })], })