in odoo17 i have this model from odoo import fields, models, api


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

    position = fields.Char(string='Position')
    type = fields.Selection([
        ('admin', 'Admin'),
        ('moderator', 'Moderator'),
        ('reader', 'Reader'),
    ])
    role = fields.Selection([
        ('republic', 'Republic'),
        ('region', 'Region'),
        ('district', 'District'),
        ('mahalla', 'Mahalla'),
    ], string='Role', default='mahalla', required=True)

    is_republic = fields.Boolean(string='Is Republic')
    region_id = fields.Many2one('region', string="Region", required=False)
    is_region = fields.Boolean()
    district_id = fields.Many2one('district', string="District", required=False)
    is_district = fields.Boolean()
    mahalla_id = fields.Many2one('mahalla', string="Mahalla", required=False)
    is_mahalla = fields.Boolean()

    @api.onchange('login')
    def on_change_login(self):
        if self.login:
            self.email = self.login

    @api.onchange('role')
    def on_change_role(self):
        if self.role == 'republic':
            self.is_republic = True
            self.is_region = True
            self.is_district = True
            self.is_mahalla = True
        elif self.role == 'region':
            self.is_region = False
            self.is_district = True
            self.is_republic = False
            self.is_mahalla = True
        elif self.role == 'district':
            self.is_district = False
            self.is_region = False
            self.is_republic = False
            self.is_mahalla = True
        elif self.role == 'mahalla':
            self.is_region = False
            self.is_republic = False
            self.is_district = False
            self.is_mahalla = False
    
    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},
        }

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

    def write(self, vals):
        if 'role' in vals and vals.get('role') != self.role:
            res = super(Users, self).write(vals)
            self.assign_group_based_on_role()
        else:
            res = super(Users, self).write(vals)
        return res

    def assign_group_based_on_role(self):
        republic_group = self.env.ref('mahallam.group_republic_user')
        region_group = self.env.ref('mahallam.group_region_user')
        district_group = self.env.ref('mahallam.group_district_user')
        mahalla_group = self.env.ref('mahallam.group_mahalla_user')

        self.groups_id = [(3, republic_group.id), (3, region_group.id), (3, district_group.id), (3, mahalla_group.id)]
        if self.role == 'republic':
            self.groups_id = [(4, republic_group.id)]
        elif self.role == 'mahalla':
            self.groups_id = [(4, mahalla_group.id)]
        elif self.role == 'region':
            self.groups_id = [(4, region_group.id)]
        elif self.role == 'district':
            self.groups_id = [(4, district_group.id)]


 andded these lines to it:     type = fields.Selection([
        ('admin', 'Admin'),
        ('moderator', 'Moderator'),
        ('reader', 'Reader'),
    ]),  admin is superadmin(developer), moderators are whom can crud in projectt around their scope, readers like moderators but can only read around their scope, improve functionality, create groups, improve xml that i will provide at the end of this request, moderators and readers have roles, superadmin is one so when superadmin is selected hide roles, localization fields, my xml: <?xml version="1.0" encoding="utf-8"?>
<odoo>
    <data>
        <!-- Custom Tree View for user -->
        <record id="view_user_tree_custom" model="ir.ui.view">
            <field name="name">res.users.tree</field>
            <field name="model">res.users</field>
            <field name="arch" type="xml">
                <tree string="Users"  default_order="create_date desc">
                    <field name="name"/>
                </tree>
            </field>
        </record>

        <record id="view_user_form_custom" model="ir.ui.view">
            <field name="name">res.users.form.custom</field>
            <field name="model">res.users</field>
            <field name="arch" type="xml">
                <form>
                    <header>
                        <button string="Set Password"
                                type="object" name="action_change_password" class="btn-primary"
                                invisible="id == False" />
                    </header>
                    <sheet>
                        <div class="oe_avatar_group">
                            <field name="image_1920" widget="image" class="oe_avatar"/>
                        </div>
                        <group>
                            <group>
                                <field name="name"/>
                                <field name="email" invisible="1"/>
                                <field name="login"/>
                                <field name="phone" placeholder="+998 xx xxx xx xx"/>
                                <field name="role"/>
                                <field name="region_id" invisible="is_region"/>
                                <field name="is_region" invisible="1"/>
                                <field
                                        name="district_id"
                                        invisible="is_district"
                                        domain="[('region_id', '=', region_id)]"
                                />
                                <field name="is_district" invisible="1"/>
                                <field name="mahalla_id" invisible="is_mahalla" domain="[('district_id', '=', district_id)]"/>
                                <field name="is_mahalla" invisible="1"/>

                                <field name="position"/>
                            </group>
                        </group>
                    </sheet>
                </form>
            </field>
        </record>


        <record id="view_user_kanban_custom" model="ir.ui.view">
            <field name="name">res.users.kanban</field>
            <field name="model">res.users</field>
            <field name="arch" type="xml">
                <kanban class="o_res_partner_kanban">
                    <field name="image_1920" widget="image"/>
                    <field name="name"/>
                    <field name="email"/>
                    <field name="phone"/>
                    <field name="role"/>
                    <field name="region_id"/>
                    <field name="district_id"/>
                    <field name="position"/>
                </kanban>
            </field>
        </record>


        <record id="action_user_custom" model="ir.actions.act_window">
            <field name="name">Users</field>
            <field name="res_model">res.users</field>
            <field name="view_mode">form</field>
            <field name="view_id" ref="view_user_form_custom"/>
        </record>

        <record id="action_user_list" model="ir.actions.act_window">
            <field name="name">Users</field>
            <field name="res_model">res.users</field>
            <field name="view_mode">kanban,tree</field>
            <field name="view_id" ref="view_user_tree_custom"/>
        </record>
    </data>
    <menuitem
        id="user_menu"
        name="Admin Users Menu"
        sequence="1"/>

    <menuitem
        id="user_managers_menu"
        name="User Managers"
        parent="user_menu"
        action="action_user_list"
        sequence="1"/>

    <menuitem
        id="user_add_menu"
        name="Add User"
        parent="user_menu"
        action="action_user_custom"
        sequence="2"/>
</odoo>