[FIX] base: don't fail on empty groups attribute

In 15.0 this was supported. It may be also handy when editing views to
momentarily set the groups to `""`.

Steps to reproduce:
1. Install Odoo 15 locally
2. Edit or create a view with `groups=""` for some component
3. Upgrade to 16.
It fails.

Empty groups was allowed in 15.0 we want to ensure this is not broken
unintentionally anymore, such a new test was added.

Muted logged to hide the warning (also present in 15.0):
```
2023-02-08 11:09:18,697 506777 WARNING test_16_gr odoo.addons.base.models.ir_ui_view: The group '' defined in view does not exist!
View error context:
{'file': None,
 'line': 3,
 'name': 'foo',
 'view': ir.ui.view(242,),
 'view.model': 'res.partner',
 'view.parent': ir.ui.view(),
 'xmlid': ''}
 ```

closes odoo/odoo#112246

X-original-commit: 4379dce95edcc34a8e97e73a3bdaa2e20fdc79a8
Signed-off-by: Denis Ledoux (dle) <dle@odoo.com>
This commit is contained in:
Alvaro Fuentes
2023-02-09 10:49:06 +01:00
parent 9731e9be6d
commit cec6e163c1
2 changed files with 19 additions and 1 deletions
+2 -1
View File
@@ -1061,7 +1061,8 @@ actual arch.
"""
for node in tree.xpath('//*[@groups]'):
if not self.user_has_groups(node.attrib.pop('groups')):
attrib_groups = node.attrib.pop('groups')
if attrib_groups and not self.user_has_groups(attrib_groups):
node.getparent().remove(node)
elif node.tag == 't' and (not node.attrib or node.get('postprocess_added')):
# Move content of <t groups=""> blocks
+17
View File
@@ -2969,6 +2969,23 @@ class TestViews(ViewCase):
</form>
""", valid=True)
@mute_logger('odoo.addons.base.models.ir_ui_view')
def test_empty_groups_attrib(self):
"""Ensure we allow empty groups attribute"""
view = self.View.create({
'name': 'foo',
'model': 'res.partner',
'arch': """
<form>
<field name="name" groups="" />
</form>
""",
})
arch = self.env['res.partner'].get_view(view_id=view.id)['arch']
tree = etree.fromstring(arch)
nodes = tree.xpath("//field[@name='name' and not (@groups)]")
self.assertEqual(1, len(nodes))
def test_attrs_groups_with_groups_in_model(self):
"""Tests the attrs is well processed to modifiers for a field node combining:
- a `groups` attribute on the field node in the view architecture