Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to check model level groups in OpenERP

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 419
    Comment on it

    In OpenERP first we create groups in res.partner object. Then the ` parameter effectively restricts access to that field for users who do not belong to one of the explicitly allowed groups. Field decimal_places must be found in view definition before the test and then first verify the test environment.

    Use this function given below

     

     def fieldrestriction(self):
           
            original_fields = self.res_currency.fields_get(self.cr, self.demo_uid, [])
            form_view = self.res_currency.fields_view_get(self.cr, self.demo_uid, False, 'form')
            view_arch = etree.fromstring(form_view.get('arch'))
            has_group_system = self.res_users.has_group(self.cr, self.demo_uid, GROUP_SYSTEM)
            self.assertFalse(has_group_system, "`demo` user should not belong to the restricted group before the test")
            self.assertTrue('decimal_places' in 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(self.res_currency, 'decimal_places', GROUP_SYSTEM)
    
            fields = self.res_currency.fields_get(self.cr, self.demo_uid, [])
            form_view = self.res_currency.fields_view_get(self.cr, self.demo_uid, False, 'form')
            view_arch = etree.fromstring(form_view.get('arch'))
            self.assertFalse('decimal_places' in 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.write({'users': [(4, self.demo_uid)]})
            has_group_system = self.res_users.has_group(self.cr, self.demo_uid, GROUP_SYSTEM)
            fields = self.res_currency.fields_get(self.cr, self.demo_uid, [])
            form_view = self.res_currency.fields_view_get(self.cr, self.demo_uid, 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.assertTrue('decimal_places' in 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")
    
            self.erp_system_group.write({'users': [(3, self.demo_uid)]})
    

     

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: