Hi Feryial,
You can easily handle this one with a access rule definition,
So this example is based on your explanation:
1- Inherit res.users to compute on the fly groups
class ResUsers(models.Model):
_inherit = 'res.users'
user_group = fields.Many2one('res.groups',compute='_compute_user_group')
def _compute_user_group(self):
for user in self:
if self.env.user.has_group('my_module.group_a'):
user.user_group = self.env('res.groups').search([('name','=','Group A')])
else:
user.user_group = self.env('res.groups').search([('name','=','Group B')])
2- Define the rule;
record model="ir.rule" id="my_module_record_based_rule">
field name="name">Users can only see their records
field name="model_id" ref="model_example_form"/>
field eval="1" name="perm_unlink"/>
field eval="1" name="perm_write"/>
field eval="1" name="perm_read"/>
field eval="1" name="perm_create"/>
field name="domain_force">[('access_groups', '=',user.user_group.id)]
field name="groups"
eval="[(6, 0, [ref('proc_pre_request.group_ppr_user')])]"/>
record>