Skip to content
Permalink
Browse files

wip to reset and split

  • Loading branch information...
Xavier-Do committed Nov 8, 2019
1 parent 6e63a10 commit 90fa897643bee8876345c2e1c88f6b46ccaf1ef1
Showing with 33 additions and 4 deletions.
  1. +4 −3 odoo/addons/base/models/ir_ui_view.py
  2. +23 −0 odoo/addons/base/tests/test_views.py
  3. +6 −1 odoo/exceptions.py
@@ -386,6 +386,7 @@ def _check_xml(self):
view.postprocess_and_fields(view_doc, validate=True)
except ValueError as e:
raise ValidationError("%s\n\n%s" % (_("Error while validating view"), tools.ustr(e)))

# RNG-based validation is not possible anymore with 7.0 forms
view_docs = [view_doc]
if view_docs[0].tag == 'data':
@@ -1016,8 +1017,8 @@ def _validate_tag_field(self, node, name_manager, node_info):
msg = _('Field "%s" does not exist in model "%s"')
self.handle_view_error(msg % (node.get('name'), name_manager.Model._name))
if node.get('domain') and field.comodel_name not in self.env:
msg = _('Domain on field without comodel makes no sense for %s (domain:%s)')
self.handle_view_error(msg % (node.get('name'), node.get('domain')))
msg = _('Domain on field without comodel makes no sense for "%s" (domain:%s)'))
self.handle_view_error(msg % (node.get('name'), node.get('domain'))

for attribute in ('invisible', 'readonly', 'required'):
val = node.get(attribute)
@@ -1186,7 +1187,7 @@ def _validate_attrs(self, node, name_manager, node_info):

for attr, expr in node.items():
if attr == 'domain':
fields = self._get_server_domain_variables(expr, 'domain', Model)
fields = self._get_server_domain_variables(expr, 'domain of <%s%s> ' % (node.tag, (' name="%s"' % node.get('name')) if node.get('name') else '' ), Model)
name_manager.must_have_fields(fields)

elif attr.startswith('decoration-'):
@@ -1473,6 +1473,14 @@ def test_domain_field_searchable(self):
'arch': arch % 'xml_id', # computed, not stored, no search
})

@mute_logger('odoo.addons.base.models.ir_ui_view')
def test_domain_field_no_comodel(self):
self.assertInvalid("""
<form string="View">
<field name="name" domain="[('test', '=', 'test')]"/>
</form>
""","Domain on field without comodel makes no sense for \"name\" (domain:[('test', '=', 'test')])")

@mute_logger('odoo.addons.base.models.ir_ui_view')
def test_domain_in_subview(self):
arch = """
@@ -1717,6 +1725,21 @@ def test_domain_on_readonly_field_in_subview(self):
'arch': arch % '',
})

@mute_logger('odoo.addons.base.models.ir_ui_view')
def test_modifier_attribute_is_boolean(self):
arch = """
<form string="View">
<field name="name" readonly="%s"/>
</form>
"""
self.assertValid(arch % '1')
self.assertValid(arch % '0')
self.assertValid(arch % 'True')
self.assertInvalid(
arch % "[('model', '=', '1')]",
"Attribute readonly evalution must give a boolean, got [('model', '=', '1')] in [('model', '=', '1')]"
)

@mute_logger('odoo.addons.base.models.ir_ui_view')
def test_domain_in_filter(self):
arch = """
@@ -18,7 +18,6 @@

_logger = logging.getLogger(__name__)


# kept for backward compatibility
class except_orm(Exception):
def __init__(self, name, value=None):
@@ -29,6 +28,12 @@ def __init__(self, name, value=None):
self.value = value
self.args = (name, value)

def __str__(self):
if not self.value:
return str(self.name)
else:
return super().__str__()


class UserError(except_orm):
"""Generic error managed by the client.

0 comments on commit 90fa897

Please sign in to comment.
You can’t perform that action at this time.