diff --git a/app_common/__manifest__.py b/app_common/__manifest__.py
index e5e118cf..376bf4da 100644
--- a/app_common/__manifest__.py
+++ b/app_common/__manifest__.py
@@ -33,7 +33,7 @@
{
'name': "Sunpop Odooapp Common Func",
- 'version': '13.21.06.13',
+ 'version': '13.21.08.03',
'author': 'Sunpop.cn',
'category': 'Base',
'website': 'https://www.sunpop.cn',
diff --git a/app_common/models/__init__.py b/app_common/models/__init__.py
index dd546b43..b806789e 100644
--- a/app_common/models/__init__.py
+++ b/app_common/models/__init__.py
@@ -24,6 +24,6 @@
from . import base
from . import fields
-# from . import validator
+from . import view_validation
from . import ir_ui_view
diff --git a/app_common/models/validator_old.py b/app_common/models/validator_old.py
deleted file mode 100644
index 2724e05c..00000000
--- a/app_common/models/validator_old.py
+++ /dev/null
@@ -1,78 +0,0 @@
-# -*- coding: utf-8 -*-
-
-from odoo import tools, _
-from odoo.modules.module import get_resource_path
-from odoo.tools import view_validation
-from odoo.tools.view_validation import validate, _validators
-from lxml import etree
-import logging
-
-
-_logger = logging.getLogger(__name__)
-
-_relaxng_cache = view_validation._relaxng_cache
-_relaxng_cache['tree'] = None
-with tools.file_open(get_resource_path('app_common', 'rng', 'tree_view.rng')) as frng:
- try:
- text = frng.read()
- # with tools.file_open('addons/base/rng/common.rng') as common_rng:
- # common_txt = common_rng.read()
- # start_pos = common_txt.find('', start_pos)
- # end_pos = common_txt.find('')
- # common_content = common_txt[start_pos + 1: end_pos]
- #
- # # 从14中学习,最新 common
- # #
- # old_content = '''
- #
- # '''
- # new_content = '''
- #
- #
- #
- #
- #
- #
- #
- #
- #
- #
- #
- #
- #
- # '''
- # common_content = common_content.replace(old_content, new_content)
- # # common 替代
- # text = text.replace('', common_content)
- # # tree 替代
- # old_content = ''''''
- # new_content = '''
- #
- #
- #
- #
- # '''
- # text = text.replace(old_content, new_content)
- # # 增加 fx_tree_table 支持
- # text = text.replace('',
- # '')
-
- tmp_doc = etree.fromstring(text.encode('utf-8'))
- _relaxng_cache['tree'] = etree.RelaxNG(tmp_doc)
- _logger.warning('=========new tree done: %s' % _relaxng_cache['tree'])
- except Exception as error:
- _logger.error('Failed to load RelaxNG XML schema for views validation, {error}'.format(
- error=error))
- _relaxng_cache['tree'] = None
-
-
-@validate('tree')
-def app_valid_field_in_tree(arch, **kwargs):
- # 增加 header
- return all(
- child.tag in ('field', 'button', 'control', 'groupby', 'header')
- for child in arch.xpath('/tree/*')
- )
-
-view_validation.valid_field_in_tree = app_valid_field_in_tree
diff --git a/app_common/models/view_validation.py b/app_common/models/view_validation.py
new file mode 100644
index 00000000..7bfa746e
--- /dev/null
+++ b/app_common/models/view_validation.py
@@ -0,0 +1,45 @@
+# -*- coding: utf-8 -*-
+
+import ast
+from odoo.tools import view_validation
+from odoo.tools.view_validation import get_attrs_field_names as old_gafn
+import logging
+
+_logger = logging.getLogger(__name__)
+
+ATTRS_WITH_FIELD_NAMES2 = {
+ 'context',
+ 'domain',
+ 'decoration-bf',
+ 'decoration-it',
+ 'decoration-danger',
+ 'decoration-info',
+ 'decoration-muted',
+ 'decoration-primary',
+ 'decoration-success',
+ 'decoration-warning',
+ 'bg-danger',
+ 'bg-info',
+ 'bg-muted',
+ 'bg-primary',
+ 'bg-success',
+ 'bg-warning',
+}
+
+def app_get_attrs_field_names(env, arch, model, editable):
+ result = []
+
+ def add_bg(node, model, editable, get=old_gafn.get_name):
+ for key, val in node.items():
+ if not val:
+ continue
+ if key in ATTRS_WITH_FIELD_NAMES2:
+ old_gafn.process_expr(val, get, key, val)
+
+ res = old_gafn(arch, model, editable)
+ add_bg(arch, model, editable)
+ res += result
+ return res
+
+# 使用猴子补丁方式更新
+view_validation.get_attrs_field_names = app_get_attrs_field_names
diff --git a/app_common/rng/common.rng b/app_common/rng/common.rng
index a62f159a..75914955 100644
--- a/app_common/rng/common.rng
+++ b/app_common/rng/common.rng
@@ -268,6 +268,7 @@
+
@@ -276,7 +277,12 @@
-
+
+
+
+
+
+
diff --git a/app_common/rng/tree_view.rng b/app_common/rng/tree_view.rng
index f295cdf7..5a6ab2fb 100644
--- a/app_common/rng/tree_view.rng
+++ b/app_common/rng/tree_view.rng
@@ -46,6 +46,12 @@
+
+
+
+
+
+