'Check that model-level ``groups`` parameter effectively restricts access to that
field for users who do not belong to one of the explicitly allowed groups'

def test_field_visibility_restriction(self):

    currency = self.env['res.currency'].sudo(self.demo_user)
    original_fields = currency.fields_get([])
    form_view = currency.fields_view_get(False, 'form')
    view_arch = etree.fromstring(form_view.get('arch'))
    has_group_system = self.demo_user.has_group(GROUP_SYSTEM)
    self.assertFalse(has_group_system, '`demo`    user    should    not    belong    to    the    restricted    group    before    the    test')
    self.assertIn('decimal_places', original_fields, "'decimal_places'    field    must    be    properly    visible    before    the    test")
    self.assertNotEquals(view_arch.xpath("//field[@name='decimal_places']"), [], "Field    'decimal_places'    must    be    found    in    view    definition    before    the    test")
    self._set_field_groups(currency, 'decimal_places', GROUP_SYSTEM)
    fields = currency.fields_get([])
    form_view = currency.fields_view_get(False, 'form')
    view_arch = etree.fromstring(form_view.get('arch'))
    self.assertNotIn('decimal_places', fields, "'decimal_places'    field    should    be    gone")
    self.assertEquals(view_arch.xpath("//field[@name='decimal_places']"), [], "Field    'decimal_places'    must    not    be    found    in    view    definition")
    self.erp_system_group.users += self.demo_user
    has_group_system = self.demo_user.has_group(GROUP_SYSTEM)
    fields = currency.fields_get([])
    form_view = currency.fields_view_get(False, 'form')
    view_arch = etree.fromstring(form_view.get('arch'))
    self.assertTrue(has_group_system, '`demo`    user    should    now    belong    to    the    restricted    group')
    self.assertIn('decimal_places', fields, "'decimal_places'    field    must    be    properly    visible    again")
    self.assertNotEquals(view_arch.xpath("//field[@name='decimal_places']"), [], "Field    'decimal_places'    must    be    found    in    view    definition    again")
