i have project in odoo17 and i have a little bit record rules i have mine too but domain forces in them is not configured, see edit and complete my rules, also create rules for specified groups that specified to models:
<?xml version="1.0" encoding="UTF-8"?>
<odoo>
    <data noupdate="1">
        <!-- Hierarchy Record Rule for Admin -->
        <record id="rule_hierarchy_admin" model="ir.rule">
            <field name="name">Admin Hierarchy Rule</field>
            <field name="model_id" ref="model_res_users"/>
            <field name="domain_force">[(1, '=', 1)]</field>
            <field name="groups" eval="[(4, ref('mahallam.group_admin'))]"/>
            <field name="perm_read" eval="True"/>
            <field name="perm_write" eval="True"/>
            <field name="perm_create" eval="True"/>
            <field name="perm_unlink" eval="True"/>
        </record>
        
        <!-- Localization Restrictions -->
        <record id="rule_localization_group_region" model="ir.rule">
            <field name="name">Region Localization Rule</field>
            <field name="model_id" ref="model_res_partner"/>
            <field name="domain_force">[(1, '=', 1)]</field>
            <field name="groups" eval="[(4, ref('mahallam.group_region'))]"/>
            <field name="perm_read" eval="True"/>
            <field name="perm_write" eval="False"/>
            <field name="perm_create" eval="False"/>
            <field name="perm_unlink" eval="False"/>
        </record>
        
        <record id="rule_localization_group_district" model="ir.rule">
            <field name="name">District Localization Rule</field>
            <field name="model_id" ref="model_res_partner"/>
            <field name="domain_force">[(1, '=', 1)]</field>
            <field name="groups" eval="[(4, ref('mahallam.group_district'))]"/>
            <field name="perm_read" eval="True"/>
            <field name="perm_write" eval="False"/>
            <field name="perm_create" eval="False"/>
            <field name="perm_unlink" eval="False"/>
        </record>
        
        <record id="rule_localization_group_mahalla" model="ir.rule">
            <field name="name">Mahalla Localization Rule</field>
            <field name="model_id" ref="model_res_partner"/>
            <field name="domain_force">[(1, '=', 1)]</field>
            <field name="groups" eval="[(4, ref('mahallam.group_mahalla'))]"/>
            <field name="perm_read" eval="True"/>
            <field name="perm_write" eval="False"/>
            <field name="perm_create" eval="False"/>
            <field name="perm_unlink" eval="False"/>
        </record>
    </data>
</odoo>

from odoo import fields, models, api
from odoo.exceptions import AccessError


class Users(models.Model):
    _inherit = "res.users"

    position = fields.Char(string='Position')
    type = fields.Selection([
        ('admin', 'Admin'),
        ('moderator', 'Moderator'),
        ('reader', 'Reader'),
    ], string='User Type', required=True, default='reader')
    
    role = fields.Selection([
        ('republic', 'Republic'),
        ('region', 'Region'),
        ('district', 'District'),
        ('mahalla', 'Mahalla'),
    ], string='Role', default='mahalla')
    
    region_id = fields.Many2one('region', string="Region")
    district_id = fields.Many2one('district', string="District")
    mahalla_id = fields.Many2one('mahalla', string="Mahalla")
    
    allowed_group_ids = fields.Many2many(
        'res.groups',
        string='Allowed Groups',
        compute='_compute_allowed_group_ids'
    )

    @api.depends('type', 'role')
    def _compute_allowed_group_ids(self):
        current_user = self.env.user
        group_definitions = {
            'admin': 'mahallam.group_admin',
            'moderator': 'mahallam.group_moderator',
            'reader': 'mahallam.group_reader',
            'republic': 'mahallam.group_republic',
            'region': 'mahallam.group_region',
            'district': 'mahallam.group_district',
            'mahalla': 'mahallam.group_mahalla',
            'localization': 'mahallam.group_localization',
            'hierarchical': 'mahallam.group_hierarchical',
            'application': 'mahallam.group_application',
            'announcement': 'mahallam.group_announcement',
            'notification': 'mahallam.group_notification',
            'questionnaire': 'mahallam.group_questionnaire',
            'user_questionnaire': 'mahallam.group_user_questionnaire',
        }

        allowed_groups = []

        if current_user.type == 'admin':
            allowed_groups = group_definitions.values()
        elif current_user.type == 'moderator' and current_user.role == 'republic':
            allowed_groups.extend([
                group_definitions['moderator'],
                group_definitions['reader'],
                group_definitions['region'],
                group_definitions['district'],
                group_definitions['mahalla'],
                group_definitions['localization'],
                group_definitions['hierarchical'],
                group_definitions['application'],
                group_definitions['announcement'],
                group_definitions['notification'],
                group_definitions['questionnaire'],
                group_definitions['user_questionnaire'],
                ]
                )
        elif current_user.type == 'reader' and current_user.role == 'republic':
            allowed_groups.extend([
                group_definitions['moderator'],
                group_definitions['reader'],
                group_definitions['region'],
                group_definitions['district'],
                group_definitions['mahalla'],
                group_definitions['localization'],
                group_definitions['hierarchical'],
                group_definitions['application'],
                group_definitions['announcement'],
                group_definitions['notification'],
                group_definitions['questionnaire'],
                group_definitions['user_questionnaire'],]
                )
        elif current_user.type == 'moderator' and current_user.role == 'region':
            allowed_groups.extend([
                group_definitions['moderator'],
                group_definitions['reader'],
                group_definitions['region'],
                group_definitions['district'],
                group_definitions['mahalla'],
                group_definitions['application'],
                group_definitions['announcement'],
                group_definitions['notification'],
                group_definitions['questionnaire'],
                group_definitions['user_questionnaire'],]
                )
        elif current_user.type == 'reader' and current_user.role == 'region':
            allowed_groups.extend([
                group_definitions['moderator'],
                group_definitions['reader'],
                group_definitions['district'],
                group_definitions['mahalla'],
                group_definitions['application'],
                group_definitions['announcement'],
                group_definitions['notification'],
                group_definitions['questionnaire'],
                group_definitions['user_questionnaire'],]
                )
        elif current_user.type == 'moderator' and current_user.role == 'district':
            allowed_groups.extend([
                group_definitions['moderator'],
                group_definitions['reader'],
                group_definitions['mahalla'],
                group_definitions['application'],
                group_definitions['announcement'],
                group_definitions['notification'],
                group_definitions['questionnaire'],
                group_definitions['user_questionnaire'],]
                )
        elif current_user.type == 'reader' and current_user.role == 'district':
            allowed_groups.extend([
                group_definitions['moderator'],
                group_definitions['reader'],
                group_definitions['mahalla'],
                group_definitions['application'],
                group_definitions['announcement'],
                group_definitions['notification'],
                group_definitions['questionnaire'],
                group_definitions['user_questionnaire'],]
                )
        elif current_user.type == 'moderator' and current_user.role == 'mahalla':
            allowed_groups.extend([
                group_definitions['moderator'],
                group_definitions['reader'],
                group_definitions['application'],
                group_definitions['announcement'],
                group_definitions['notification'],
                group_definitions['questionnaire'],
                group_definitions['user_questionnaire'],]
                )
        elif current_user.type == 'reader' and current_user.role == 'mahalla':
            allowed_groups.extend([
                group_definitions['moderator'],
                group_definitions['reader'],
                group_definitions['application'],
                group_definitions['announcement'],
                group_definitions['notification'],
                group_definitions['questionnaire'],
                group_definitions['user_questionnaire'],]
                )

        self.allowed_group_ids = [(6, 0, [self.env.ref(group).id for group in allowed_groups if self.env.ref(group)])]

    @api.onchange('type')
    def _onchange_type(self):
        if self.type == 'admin':
            self.role = False
            self.region_id = False
            self.district_id = False
            self.mahalla_id = False
        self._update_role_visibility()
    
    @api.onchange('role')
    def _onchange_role(self):
        if self.type != 'admin':
            self._update_role_visibility()
    
    def _update_role_visibility(self):
        if self.type == 'admin':
            pass
        elif self.role == 'republic':
            pass
        elif self.role == 'region':
            self.district_id = False
            self.mahalla_id = False
        elif self.role == 'district':
            self.mahalla_id = False
        elif self.role == 'mahalla':
            pass

    def action_change_password(self):
        self.ensure_one()
        return {
            'type': 'ir.actions.act_window',
            'res_model': 'change.password.wizard',
            'view_mode': 'form',
            'view_id': self.env.ref('base.change_password_wizard_view').id,
            'target': 'new',
            'context': {'default_user_id': self.id},
        }

    def assign_group_based_on_role(self):
        self.ensure_one()

        admin_group = self.env.ref('mahallam.group_admin')
        group_republic = self.env.ref('mahallam.group_republic')
        group_region = self.env.ref('mahallam.group_region')
        group_district = self.env.ref('mahallam.group_district')
        group_mahalla = self.env.ref('mahallam.group_mahalla')
        group_mahalla = self.env.ref('mahallam.group_mahalla')
        group_reader = self.env.ref('mahallam.group_reader')
        group_moderator = self.env.ref('mahallam.group_moderator')
        group_hierarchical = self.env.ref('mahallam.group_hierarchical')
        group_localization = self.env.ref('mahallam.group_localization')
        group_application = self.env.ref('mahallam.group_application')
        group_announcement = self.env.ref('mahallam.group_announcement')
        group_notification = self.env.ref('mahallam.group_notification')
        group_questionnaire = self.env.ref('mahallam.group_questionnaire')
        group_user_questionnaire = self.env.ref('mahallam.group_user_questionnaire')

        self.groups_id = [
            (3, admin_group.id), (3, group_republic.id), (3, group_region.id),
            (3, group_district.id), (3, group_mahalla.id),
            (3, group_reader.id), (3, group_moderator.id),
            (3, group_hierarchical.id), (3, group_localization.id),
            (3, group_application.id), (3, group_announcement.id),
            (3, group_notification.id), (3, group_questionnaire.id),
            (3, group_user_questionnaire.id),
            ]
        
        if self.type == 'moderator' and self.role == 'republic':
            self.groups_id = [(4, group_moderator.id), (4, group_republic.id),(4, group_hierarchical.id)]
        elif self.type == 'reader' and self.role == 'republic':
            self.groups_id = [(4, group_reader.id), (4, group_republic.id), (4, group_hierarchical.id)]
        elif self.type == 'moderator' and self.role == 'region':
            self.groups_id = [(4, group_moderator.id), (4, group_region.id), (4, group_hierarchical.id), (4, group_localization.id)]
        elif self.type == 'reader' and self.role == 'region':
            self.groups_id = [(4, group_reader.id), (4, group_region.id), (4, group_hierarchical.id), (4, group_localization.id)]
        elif self.type == 'moderator' and self.role == 'district':
            self.groups_id = [(4, group_moderator.id), (4, group_district.id), (4, group_hierarchical.id), (4, group_localization.id)]
        elif self.type == 'reader' and self.role == 'district':
            self.groups_id = [(4, group_reader.id), (4, group_district.id), (4, group_hierarchical.id), (4, group_localization.id)]
        elif self.type == 'moderator' and self.role == 'mahalla':
            self.groups_id = [(4, group_moderator.id), (4, group_mahalla.id), (4, group_hierarchical.id), (4, group_localization.id)]
        elif self.type == 'reader' and self.role == 'mahalla':
            self.groups_id = [(4, group_reader.id), (4, group_mahalla.id), (4, group_hierarchical.id), (4, group_localization.id)]

    @api.model
    def create(self, vals):
        user = super(Users, self).create(vals)
        user.assign_group_based_on_role()
        return user

    def write(self, vals):
        res = super(Users, self).write(vals)
        if 'type' in vals or 'role' in vals:
            self.assign_group_based_on_role()
        return res

<?xml version="1.0" encoding="UTF-8"?>
<odoo>
    <data noupdate="1">
        <record id="mahallam.group_admin" model="res.groups">
            <field name="name">Group admin</field>
            <field name="category_id" ref="base.module_category_hidden"/>
        </record>
        
        <record id="mahallam.group_republic" model="res.groups">
            <field name="name">Group republic</field>
            <field name="category_id" ref="base.module_category_hidden"/>
        </record>
        
        <record id="mahallam.group_region" model="res.groups">
            <field name="name">Group region</field>
            <field name="category_id" ref="base.module_category_hidden"/>
        </record>
        
        <record id="mahallam.group_district" model="res.groups">
            <field name="name">Group district</field>
            <field name="category_id" ref="base.module_category_hidden"/>
        </record>
        
        <record id="mahallam.group_mahalla" model="res.groups">
            <field name="name">Group mahalla</field>
            <field name="category_id" ref="base.module_category_hidden"/>
        </record>
        
        <record id="mahallam.group_reader" model="res.groups">
            <field name="name">Group reader</field>
            <field name="category_id" ref="base.module_category_hidden"/>
        </record>
        
        <record id="mahallam.group_moderator" model="res.groups">
            <field name="name">Group moderator</field>
            <field name="category_id" ref="base.module_category_hidden"/>
        </record>
        
        <record id="mahallam.group_hierarchical" model="res.groups">
            <field name="name">Group hierarchical</field>
            <field name="category_id" ref="base.module_category_hidden"/>
        </record>
        
        <record id="mahallam.group_localization" model="res.groups">
            <field name="name">Group localization</field>
            <field name="category_id" ref="base.module_category_hidden"/>
        </record>
        
        <record id="mahallam.group_application" model="res.groups">
            <field name="name">Group application</field>
            <field name="category_id" ref="base.module_category_hidden"/>
        </record>
        
        <record id="mahallam.group_announcement" model="res.groups">
            <field name="name">Group announcement</field>
            <field name="category_id" ref="base.module_category_hidden"/>
        </record>
        
        <record id="mahallam.group_notification" model="res.groups">
            <field name="name">Group notification</field>
            <field name="category_id" ref="base.module_category_hidden"/>
        </record>
        
        <record id="mahallam.group_questionnaire" model="res.groups">
            <field name="name">Group questionnaire</field>
            <field name="category_id" ref="base.module_category_hidden"/>
        </record>
        
        <record id="mahallam.group_user_questionnaire" model="res.groups">
            <field name="name">Group user questionnaire</field>
            <field name="category_id" ref="base.module_category_hidden"/>
        </record>
        
        <record id="base.group_system" model="res.groups">
            <field name="name">Group system</field>
            <field name="category_id" ref="base.module_category_hidden"/>
        </record>
        
        <record id="base.group_user" model="res.groups">
            <field name="name">Group user</field>
            <field name="category_id" ref="base.module_category_hidden"/>
        </record>
        
    </data>
</odoo>