From 9b0e976b9f5182c38f9068307abe0bfd0a66ce2e Mon Sep 17 00:00:00 2001 From: Adrian Torres Date: Mon, 10 Feb 2020 10:53:49 +0000 Subject: [PATCH] [IMP] base: raise warning if no field in search view Before this commit, it was possible (and common) to create search views without fields and only filters, the consequence was that a search for that particular search view was not possible. (See https://github.com/odoo/enterprise/pull/7852) With this commit, a warning is raised if no field is defined within a search view, preventing these "common mistakes" from happening again. closes odoo/odoo#45058 Task-id: 2179521 Signed-off-by: Raphael Collet (rco) --- odoo/addons/base/models/ir_ui_view.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/odoo/addons/base/models/ir_ui_view.py b/odoo/addons/base/models/ir_ui_view.py index 73a4ea9cae1..10fdd4d0eb7 100644 --- a/odoo/addons/base/models/ir_ui_view.py +++ b/odoo/addons/base/models/ir_ui_view.py @@ -1120,6 +1120,12 @@ actual arch. def _validate_tag_search(self, node, name_manager, node_info): if len([c for c in node if c.tag == 'searchpanel']) > 1: self.handle_view_error(_('Search tag can only contains one search panel')) + if not list(node.iterdescendants(tag="field")): + # the field of the search view may be within a group node, which is why we must check + # for all descendants containing a node with a field tag, if this is not the case + # then a search is not possible. + self.handle_view_error( + _('Search tag requires at least one field element'), raise_exception=False) def _validate_tag_searchpanel(self, node, name_manager, node_info): for child in node.iterchildren(tag=etree.Element):