[MIG] sale_exception_portal: migrate to 14.0

H5654
This commit is contained in:
Cedric Collins
2021-03-28 18:33:57 -05:00
parent b9e0dad10a
commit 1c8d02e628
3 changed files with 5 additions and 27 deletions

View File

@@ -1,7 +1,7 @@
{ {
'name': 'Sale Exception Portal', 'name': 'Sale Exception Portal',
'summary': 'Display sale exceptions on customer portal', 'summary': 'Display sale exceptions on customer portal',
'version': '13.0.1.0.0', 'version': '14.0.1.0.0',
'author': "Hibou Corp.", 'author': "Hibou Corp.",
'category': 'Sale', 'category': 'Sale',
'license': 'AGPL-3', 'license': 'AGPL-3',

View File

@@ -1,6 +1,4 @@
import time
from odoo import fields, models from odoo import fields, models
from odoo.tools.safe_eval import safe_eval
class ExceptionRule(models.Model): class ExceptionRule(models.Model):
@@ -13,27 +11,7 @@ class SaleOrder(models.Model):
_inherit = 'sale.order' _inherit = 'sale.order'
def _check_sale_order_exceptions(self): def _check_sale_order_exceptions(self):
so_exceptions = self.env['exception.rule'].search([('active', '=', True), exception_ids = self.detect_exceptions()
('model', '=', 'sale.order'), exceptions = self.env['exception.rule'].browse(exception_ids)
('exception_type', '=', 'by_py_code')]) reasons = [{'title': ex.name, 'description': ex.website_description or ex.description} for ex in exceptions]
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
return reasons return reasons

View File

@@ -25,7 +25,7 @@ class TestCheckSOExceptions(TransactionCase):
'order_line': [(0, 0, { 'order_line': [(0, 0, {
'product_id': self.sale_product.id, 'product_id': self.sale_product.id,
'product_uom_qty': 1.0, 'product_uom_qty': 1.0,
'price_unit': 50.0, # Set lower than 100.0 to trigger the exception 'price_unit': 50.0,
})], })],
}) })