From b2b9545cf38855fdb97e992aa2883cdab6909e96 Mon Sep 17 00:00:00 2001 From: Yannick Tivisse Date: Mon, 1 Oct 2018 17:28:56 +0200 Subject: [PATCH] [IMP] ir_ui_view: Log warning on incorrect 'groups' attribute Purpose ======= They are a lot of places where we set an attribute 'groups' on a view element and: - The group doesn't exist anymore - The group xmlid is not correct - The group xmlid exists but the modularity is not respected (example: group_stock_user used in a view in the 'product' module). Where it happens, nothing warns the user or the developer. The element is just never rendered. Specification ============= In the method _check_xml, log a warning if a 'groups' attribute is set and if a group doesn't not exist at that moment. --- odoo/addons/base/models/ir_ui_view.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/odoo/addons/base/models/ir_ui_view.py b/odoo/addons/base/models/ir_ui_view.py index 04464f981c0..96e0593cbc1 100644 --- a/odoo/addons/base/models/ir_ui_view.py +++ b/odoo/addons/base/models/ir_ui_view.py @@ -320,6 +320,12 @@ actual arch. self.raise_view_error(message, self.id) return True + def _check_groups_validity(self, view, view_name): + for node in view.xpath('//*[@groups]'): + for group in node.get('groups').replace('!', '').split(','): + if not self.env.ref(group.strip(), raise_if_not_found=False): + _logger.warning("The group %s defined in view %s does not exist!", group, view_name) + @api.constrains('arch_db') def _check_xml(self): # Sanity checks: the view should not break anything upon rendering! @@ -332,6 +338,7 @@ actual arch. view_arch_utf8 = view_def['arch'] if view.type != 'qweb': view_doc = etree.fromstring(view_arch_utf8) + self._check_groups_validity(view_doc, view.name) # verify that all fields used are valid, etc. self.postprocess_and_fields(view.model, view_doc, view.id) # RNG-based validation is not possible anymore with 7.0 forms