i'm developing and app in odoo17 enterprise and i needed your help because you're the best one for this job
Project in odoo17 enterprise, project is in prod, 
i have mobile app in that users are res_partner and i have moderator/reader/admin users that are res_users, they have access to admin panel and i wanna manage them
my module called "mahalla" user type "admin" is superadmin in our case, it can do anything without any restriction
1. extend my user groups and creating groups like i created to all models that i provided, for every model-user_type(excluding admin user he has all rights possible)-user_roles combinations
2. as you can see i managed users groups in my user model in my way, implement these groups to my user creation logic, remove all general groups by localization(region, district, r republic, mahalla) and make them for every model and when user type and role is selected add user to all necessary groups and remove from others
3. implement hierarchical user crud, like admin can crud all types of users, district can crud only mahalla users and such hierarchy for user groups when creation, one can give groups accesses if its in lower localization class than user itself(like district user can give its mahalla accesses, not district accesses while create/updating users).
4. user can operate only on their localization scopes, like if i texas region user i cannot crud on new york region, i can operate only in my localization scope
Extend User Groups: create groups for every model-user_type(excluding admin user he has all rights possible)-user_roles combinations
Implement User Creation Logic: Modify the res.users model to include the necessary fields for user type, role, and location (region, district, mahalla). Create an assign_group_based_on_role method that assigns the appropriate groups to the user based on their type and role.
Implement Hierarchical User CRUD: Use the user type, role, and location fields to control user access and permissions. For example, a "Super Admin" can perform CRUD operations on any user, while a "Region Moderator" can only perform CRUD on district and mahalla users .
Apply Location-based Access Controls: Leverage the location-based fields (region, district, mahalla) to restrict user access to data and functionality based on their location. You can use Odoo's record rules and access control lists (ACLs) to implement these restrictions.
Update Access CSV: Modify the access.csv file to grant the appropriate permissions to all user groups
Consider Using Security Groups: Instead of directly assigning groups to users, you could consider using security groups to manage user permissions. This would allow you to more easily maintain and update the permission structure over time.
5. create rules for these needs and update access csv file of mine 
6. give me complete code without missing parts, all with filenames, very few short comments and following best practices

heres my codes:
user_group.xml:<?xml version="1.0" encoding="utf-8"?>
<odoo>
    <data noupdate="1">
        <!-- User Types -->
        <record id="group_super_admin" model="res.groups">
            <field name="name">Super Admin</field>
            <field name="implied_ids" eval="[(4, ref('base.group_system'))]"/>
        </record>

        <record id="group_moderator" model="res.groups">
            <field name="name">Moderator</field>
        </record>

        <record id="group_reader" model="res.groups">
            <field name="name">Reader</field>
        </record>

        <!-- Role-based Groups -->
        <record id="group_republic_moderator" model="res.groups">
            <field name="name">Republic Moderator</field>
            <field name="implied_ids" eval="[(4, ref('group_moderator'))]"/>
        </record>

        <record id="group_republic_reader" model="res.groups">
            <field name="name">Republic Reader</field>
            <field name="implied_ids" eval="[(4, ref('group_reader'))]"/>
        </record>

        <record id="group_region_moderator" model="res.groups">
            <field name="name">Region Moderator</field>
            <field name="implied_ids" eval="[(4, ref('group_moderator'))]"/>
        </record>

        <record id="group_region_reader" model="res.groups">
            <field name="name">Region Reader</field>
            <field name="implied_ids" eval="[(4, ref('group_reader'))]"/>
        </record>

        <record id="group_district_moderator" model="res.groups">
            <field name="name">District Moderator</field>
            <field name="implied_ids" eval="[(4, ref('group_moderator'))]"/>
        </record>

        <record id="group_district_reader" model="res.groups">
            <field name="name">District Reader</field>
            <field name="implied_ids" eval="[(4, ref('group_reader'))]"/>
        </record>

        <record id="group_mahalla_moderator" model="res.groups">
            <field name="name">Mahalla Moderator</field>
            <field name="implied_ids" eval="[(4, ref('group_moderator'))]"/>
        </record>

        <record id="group_mahalla_reader" model="res.groups">
            <field name="name">Mahalla Reader</field>
            <field name="implied_ids" eval="[(4, ref('group_reader'))]"/>
        </record>
    </data>
</odoo>

access.csv:
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
access_card_user,access.card.user,model_card,base.group_user,1,1,1,1
access_announcement_user,access.announcement.user,model_announcement,base.group_user,1,1,1,1
access_gift_user,access.gift.user,model_gift,base.group_user,1,1,1,1
access_notification,access.notification,model_notification,base.group_user,1,1,1
access_option,access.option,model_option,base.group_user,1,1,1,1
access_questionnaire,access.questionnaire,model_questionnaire,base.group_user,1,1,1,1
access_user_question_option,access.user.question.option,model_user_question_option,base.group_user,1,1,1,1
access_res_partner,access.res.partner,model_res_partner,base.group_user,1,1,1,1
access_question,access.question,model_question,base.group_user,1,1,1,1
mahallam.access_user_question,access_user_question,mahallam.model_user_question,base.group_user,1,1,1,1
mahallam.access_user_questionnaire,access_user_questionnaire,mahallam.model_user_questionnaire,base.group_user,1,1,1,1
mahallam.access_mahallam_application,access_mahallam_application,mahallam.model_mahallam_application,base.group_user,1,1,1,1
mahallam.access_paylov_transaction_history,access.paylov.transaction.history,model_paylov_transaction_history,base.group_user,1,1,1,1
mahallam.access_model_history_manager,model.history manager,model_model_history,base.group_system,1,1,1,1
mahallam.access_mobile_translation,access_mobile_translation,mahallam.model_mobile_translation,base.group_user,1,1,1,1
mahallam.access_mahallam_application_media,access_mahallam_application_media,mahallam.model_mahallam_application_media,base.group_user,1,1,1,1
mahallam.access_mahallam_application_category,access_mahallam_application_category,mahallam.model_mahallam_application_category,base.group_user,1,1,1,1
mahallam.access_user_device,access_user_device,mahallam.model_user_device,base.group_user,1,1,1,1

mahallam.access_mahallam_contact_info,acess.contact.info,model_contact_info,base.group_user,1,0,0,0
mahallam.access_mahallam_contact_info_admin,acess.contact.info,model_contact_info,base.group_system,1,1,1,1
mahallam.access_mahallam_faq,access.faq,model_faq,base.group_user,1,0,0,0
mahallam.access_mahallam_faq_admin,access.faq,model_faq,base.group_system,1,1,1,1
mahallam.access_mobile_onboarding,access_mobile_onboarding,mahallam.model_mobile_onboarding,base.group_user,1,0,0,0
mahallam.access_mobile_onboarding,access_mobile_onboarding,mahallam.model_mobile_onboarding,base.group_system,1,1,1,1


mahallam.access_mobile_onboarding_image,access_mobile_onboarding_image,mahallam.model_mobile_onboarding_image,base.group_user,1,0,0,0
mahallam.access_mobile_onboarding_image,access_mobile_onboarding_image,mahallam.model_mobile_onboarding_image,base.group_system,1,1,1,1

mahallam.profile_notifications,access_profile_notifications,model_profile_notifications,base.group_user,1,1,1,1
mahallam.profile_notifications_admin,access_profile_notifications,model_profile_notifications,base.group_system,1,1,1,1

mahallam.application_state,access_tashabbuskor_state,model_mahallam_application_state,base.group_user,1,1,1,1
mahallam.application_media,access_tashabbuskor_media,model_mahallam_application_media,base.group_user,1,1,1,1
mahallam.application_category,access_tashabbuskor_category,model_mahallam_application_category,base.group_user,1,1,1,1
mahallam.application_subcategory,access_tashabbuskor_subcategory,model_mahallam_application_subcategory,base.group_user,1,1,1,1
users.py:
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")
    
    @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()

        super_admin_group = self.env.ref('mahallam.group_super_admin')
        moderator_group = self.env.ref('mahallam.group_moderator')
        reader_group = self.env.ref('mahallam.group_reader')
        republic_moderator_group = self.env.ref('mahallam.group_republic_moderator')
        republic_reader_group = self.env.ref('mahallam.group_republic_reader')
        region_moderator_group = self.env.ref('mahallam.group_region_moderator')
        region_reader_group = self.env.ref('mahallam.group_region_reader')
        district_moderator_group = self.env.ref('mahallam.group_district_moderator')
        district_reader_group = self.env.ref('mahallam.group_district_reader')
        mahalla_moderator_group = self.env.ref('mahallam.group_mahalla_moderator')
        mahalla_reader_group = self.env.ref('mahallam.group_mahalla_reader')

        self.groups_id = [(3, super_admin_group.id), (3, moderator_group.id), (3, reader_group.id),
                            (3, republic_moderator_group.id), (3, republic_reader_group.id),
                            (3, region_moderator_group.id), (3, region_reader_group.id),
                            (3, district_moderator_group.id), (3, district_reader_group.id),
                            (3, mahalla_moderator_group.id), (3, mahalla_reader_group.id)]

        if self.type == 'admin':
            self.groups_id = [(4, super_admin_group.id)]
        elif self.type == 'moderator':
            self.groups_id = [(4, moderator_group.id)]
            if self.role == 'republic':
                self.groups_id = [(4, republic_moderator_group.id)]
            elif self.role == 'region':
                self.groups_id = [(4, region_moderator_group.id)]
            elif self.role == 'district':
                self.groups_id = [(4, district_moderator_group.id)]
            elif self.role == 'mahalla':
                self.groups_id = [(4, mahalla_moderator_group.id)]
        elif self.type == 'reader':
            self.groups_id = [(4, reader_group.id)]
            if self.role == 'republic':
                self.groups_id = [(4, republic_reader_group.id)]
            elif self.role == 'region':
                self.groups_id = [(4, region_reader_group.id)]
            elif self.role == 'district':
                self.groups_id = [(4, district_reader_group.id)]
            elif self.role == 'mahalla':
                self.groups_id = [(4, mahalla_reader_group.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
announcement.py:
from odoo import models, fields, api , _
from odoo.exceptions import ValidationError


class Announcement(models.Model):
    _name = 'announcement'
    _description = 'Yangiliklar , Elonlar va Mahhallada nima gap'

    name = fields.Char(string=_('Name'), translate=True)
    description = fields.Text(string=_("Description"), translate=True)
    content = fields.Html(string=_('Content (HTML)'), translate=True)
    image = fields.Binary(string=_('Image'))
    type = fields.Selection(
        [("mahallada_nima_gap", _('Mahallada Nima Gap')), ('announcement', _('Announcement')), ('news', _('News'))])
    views_count = fields.Integer(string=_("Views"), readonly=True, compute='_compute_views_count', store=True)
    is_country_based = fields.Boolean(default=False)
    user_is_read = fields.Many2many('res.partner', string=_('Read Users'))
    created_at = fields.Datetime(default=fields.Datetime.now, string=_('Created Date'))
    location_type = fields.Selection([
        ('all', _('All')),
        ('region', _('Region')),
        ('district', _('District')),
        ('mahalla', _('Mahalla'))
    ], string=_('Location Type'), required=True, default='all')

    to_all = fields.Boolean(string=_('Is Republic'))
    region_id = fields.Many2many('region', string=_("Region"), required=False)
    to_region = fields.Boolean()
    district_id = fields.Many2many('district', string=_("District"), required=False)
    to_district = fields.Boolean()
    mahalla_id = fields.Many2many('mahalla', string=_("Mahalla"), required=False)
    to_mahalla = fields.Boolean()

    _sql_constraints = [
        ('unique_home_utility_type', 'unique(home_id, type)',
        'Each home can have only one utility of each type.')
    ]

    def create(self, vals):
        record = super().create(vals)
        partners = self.env['res.partner'].search([('mahalla_id', 'in', record.mahalla_id.ids)]).ids
        self.env['mobile.app.push.notification'].create({
            'name': f"New {record.type}",
            'body': record.name,
            'notification_type': 'announcement',
            'model_name': 'announcement',
            'object_id': record.id,
            'send_notification_to': 'to_partner',
            'partner_ids': [(6, 0, partners)]
        })
        return record

    @api.depends('user_is_read')
    def _compute_views_count(self):
        for rec in self:
            rec.views_count = len(rec.user_is_read)

    @api.onchange('to_all')
    def _onchange_to_all(self):
        if self.to_all:
            domain = []
            mahallas = self.env['mahalla'].search(domain)
            self.mahalla_id = [(6, 0, mahallas.ids)]
            self.region_id = False
            self.district_id = False
        else:
            self.mahalla_id = False

    @api.onchange('region_id', 'region_id')
    def _onchange_region_selection(self):
        if self.to_region and self.region_id:
            districts = self.env['district'].search([('region_id', 'in', self.region_id.ids)])
            mahallas = self.env['mahalla'].search([('district_id', 'in', districts.ids)])
            self.mahalla_id = [(6, 0, mahallas.ids)]
            self.district_id = False
        elif not self.to_region:
            if not self.to_all and not self.to_district:
                self.mahalla_id = False

    @api.onchange('to_district', 'district_id')
    def _onchange_district_selection(self):
        if not self.to_district and self.district_id:
            mahallas = self.env['mahalla'].search([('district_id', 'in', self.district_id.ids)])
            self.mahalla_id = [(6, 0, mahallas.ids)]
        elif not self.to_district:
            if not self.to_all and not self.to_region:
                self.mahalla_id = False

    @api.onchange('location_type')
    def on_change_location_type(self):
        if self.location_type == 'all':
            self.to_all = True
            self.to_region = True
            self.to_district = True
            self.to_mahalla = True
            self._onchange_to_all()
        elif self.location_type == 'region':
            self.to_all = True
            self.to_region = False
            self.to_district = True
            self.to_mahalla = True
            self._onchange_region_selection()
        elif self.location_type == 'district':
            self.to_all = True
            self.to_region = False
            self.to_district = False
            self.to_mahalla = True
            self._onchange_district_selection()
        elif self.location_type == 'mahalla':
            self.to_all = True
            self.to_region = False
            self.to_district = False
            self.to_mahalla = False

    @api.constrains('location_type', 'region_id', 'district_id', 'mahalla_id')
    def _check_location_requirements(self):
        for record in self:
            if record.location_type == 'region' and not record.region_id:
                raise ValidationError("Specify the region for the announcement.")
            elif record.location_type == 'district':
                if not record.region_id:
                    raise ValidationError("Specify the region for the district announcement.")
                if not record.district_id:
                    raise ValidationError("Specify the district for the announcement.")
            elif record.location_type == 'mahalla':
                if not record.region_id:
                    raise ValidationError("Specify the region for the mahalla announcement.")
                if not record.district_id:
                    raise ValidationError("Specify the district for the mahalla announcement.")
                if not record.mahalla_id:
                    raise ValidationError("Specify the mahalla for the announcement.")
application_tashabbuskor.py:
from odoo import models, fields, api, _
import datetime


class Application(models.Model):
    _name = 'mahallam.application'
    _description = 'Application'

    name = fields.Char(string=_('Nomi'))
    partner_id = fields.Many2one('res.partner', string=_('Partner'), required=True, default=lambda self: self.env.user.partner_id)
    category_id = fields.Many2one('mahallam.application.category', string=_('Category'))
    subcategory_id = fields.Many2one('mahallam.application.subcategory', string=_('Subcategory'))
    description = fields.Text(string=_('Description'), required=True)
    image_ids = fields.One2many('mahallam.application.media', 'application_id', string=_('Images'))
    count_media = fields.Integer(string=_('Count Media'), compute='_compute_count_media')
    status = fields.Selection(
        [
            ('created', _('Created')),
            ('completed', _('Completed')),
            ('in_progress', _('In Progress')),
            ('rejected', _('Rejected')),
            ('cancelled', _('Cancelled')),
        ],
        default="created"
    )
    state_id = fields.One2many('mahallam.application.state', 'application_id', string=_('Status'))
    mahalla_id = fields.Many2one(
        'mahalla', string=_('Home Mahalla'), store=True, readonly=True
    )
    district_id = fields.Many2one(
        'district', string=_('Home District'), store=True, readonly=True
    )
    region_id = fields.Many2one(
        'region', string=_('Home Region'), store=True, readonly=True
    )
    created_at = fields.Datetime(string=_('Created At'), default=datetime.datetime.now())
    latitude = fields.Float(string=_('Latitude'))
    longitude = fields.Float(string=_('Latitude'))


    @api.model
    def write(self, vals):
        partner = self.env.user.partner_id
        main_home = partner.home_ids.filtered(lambda h: h.is_main_home)
        if main_home:
            vals.update({
                'mahalla_id': main_home.home_id.mahalla_id.id,
                'district_id': main_home.home_id.district_id.id,
                'region_id': main_home.home_id.region_id.id,
            })
        return super().write(vals)

    def write(self, vals):
        res = super().write(vals)
        if 'status' in vals:
            self.env['mobile.app.push.notification'].create({
                'name': 'Application Status Update',
                'body': f'Your application #{self.id} status changed to {vals["status"]}',
                'notification_type': 'application_status',
                'model_name': 'mahallam.application',
                'object_id': self.id,
                'send_notification_to': 'to_partner',
                'partner_ids': [(6, 0, [self.create_uid.partner_id.id])]
            })
        return res

    def _compute_count_media(self):
        for application in self:
            application.count_media = len(application.image_ids)


class ApplicationMedia(models.Model):
    _name = 'mahallam.application.media'
    _description = 'Application Media'

    application_id = fields.Many2one('mahallam.application', string='Application', required=True, ondelete='cascade')
    media = fields.Binary(string=_('Media'))
    media_name = fields.Char(string=_('Name'))


class ApplicationCategory(models.Model):
    _name = 'mahallam.application.category'
    _description = 'Application Categories'

    name = fields.Char(string=_('Nomi'))


class ApplicationSubcategory(models.Model):
    _name = 'mahallam.application.subcategory'
    _description = 'Application Subcategories'
    
    name = fields.Char(string=_('Nomi'))
    category_id = fields.Many2one('mahallam.application.category', string=_('Category'))


class ApplicationState(models.Model):
    _name = 'mahallam.application.state'
    _description = 'Application States'

    name = fields.Selection(
        [
            ('created', _('Application Created')),
            ('application_sent', _('Application Sent')),
            ('started_work', _('Department Started Work')),
            ('ended_work', _('Department Ended Work')),
            ('message_sent', _('Message Sent')),
            ('was_addressed', _('Was Addressed')),
        ],
        default="created"
    )
    description = fields.Char(string=_('Description'))
    application_id = fields.Many2one('mahallam.application', string=_('Application'))
questionnaire.py:
from odoo import models, fields, api, _
from odoo.exceptions import ValidationError


class Questionnaire(models.Model):
    _name = 'questionnaire'
    _description = "So'rovnomalar"

    name = fields.Char(string=_('Name'), translate=True)
    is_finished = fields.Boolean(default=False, store=True)
    user_id = fields.Many2one('res.partner', string=_('User'))
    image = fields.Binary(string=_('Image'))
    question_ids = fields.One2many('question', 'questionnaire_id', string=_('Questions'))
    start_date = fields.Date(string=_('Start Date'), default=fields.Date.today)
    end_date = fields.Date(string=_('End Date'), default=fields.Date.today)
    
    location_type = fields.Selection([
        ('all', _('All')),
        ('region', _('Region')),
        ('district', _('District')),
        ('mahalla', _('Mahalla'))
    ], string=_('Location Type'), required=True, default='all')

    to_all = fields.Boolean(string=_('Is Republic'))
    region_id = fields.Many2many('region', string=_("Region"), required=False)
    to_region = fields.Boolean()
    district_id = fields.Many2many('district', string=_("District"), required=False)
    to_district = fields.Boolean()
    mahalla_id = fields.Many2many('mahalla', string=_("Mahalla"), required=False)
    to_mahalla = fields.Boolean()

    @api.onchange('to_all')
    def _onchange_to_all(self):
        if self.to_all:
            domain = []
            mahallas = self.env['mahalla'].search(domain)
            self.mahalla_id = [(6, 0, mahallas.ids)]
            self.region_id = False
            self.district_id = False
        else:
            self.mahalla_id = False

    @api.onchange('to_region', 'region_id')
    def _onchange_region_selection(self):
        if self.to_region and self.region_id:
            districts = self.env['district'].search([('region_id', 'in', self.region_id.ids)])
            mahallas = self.env['mahalla'].search([('district_id', 'in', districts.ids)])
            self.mahalla_id = [(6, 0, mahallas.ids)]
            self.district_id = False
        elif not self.to_region:
            if not self.to_all and not self.to_district:
                self.mahalla_id = False

    @api.onchange('to_district', 'district_id')
    def _onchange_district_selection(self):
        if self.to_district and self.district_id:
            mahallas = self.env['mahalla'].search([('district_id', 'in', self.district_id.ids)])
            self.mahalla_id = [(6, 0, mahallas.ids)]
        elif not self.to_district:
            if not self.to_all and not self.to_region:
                self.mahalla_id = False

    @api.onchange('location_type')
    def on_change_location_type(self):
        if self.location_type == 'all':
            self.to_all = True
            self.to_region = True
            self.to_district = True
            self.to_mahalla = True
            self._onchange_to_all()
        elif self.location_type == 'region':
            self.to_all = True
            self.to_region = False
            self.to_district = True
            self.to_mahalla = True
            self._onchange_region_selection()
        elif self.location_type == 'district':
            self.to_all = False
            self.to_region = False
            self.to_district = False
            self.to_mahalla = True
            self._onchange_district_selection()
        elif self.location_type == 'mahalla':
            self.to_all = False
            self.to_region = False
            self.to_district = False
            self.to_mahalla = False

    @api.constrains('location_type', 'region_id', 'district_id', 'mahalla_id')
    def _check_location_requirements(self):
        for record in self:
            if record.location_type == 'region' and not record.region_id:
                raise ValidationError("Specify the region for the announcement.")
            elif record.location_type == 'district':
                if not record.region_id:
                    raise ValidationError("Specify the region for the district announcement.")
                if not record.district_id:
                    raise ValidationError("Specify the district for the announcement.")
            elif record.location_type == 'mahalla':
                if not record.region_id:
                    raise ValidationError("Specify the region for the mahalla announcement.")
                if not record.district_id:
                    raise ValidationError("Specify the district for the mahalla announcement.")
                if not record.mahalla_id:
                    raise ValidationError("Specify the mahalla for the announcement.")
    
    @api.constrains('start_date', 'end_date')
    def _check_date_range(self):
        for record in self:
            if record.start_date > record.end_date:
                raise ValidationError("Start date cannot be higher than end date.")
user_question_option.py:
from odoo import models, fields, api, _


class UserQuestionnaire(models.Model):
    _name = 'user.questionnaire'
    _description = 'Tracking Questionnaire for Users'

    questionnaire_id = fields.Many2one('questionnaire', string=_("So'rovnoma"))
    user_id = fields.Many2one('res.partner', string=_("So'rovnoma Qatnashuvchisi"))
    is_finished = fields.Boolean(string=_('Tugatilganmi'), default=False)
    progress = fields.Float(string=_('Progress'), default=0)

    user_question_ids = fields.One2many(
        'user.question', 'user_questionnaire_id', string=_("Questions")
    )

    # Compute methods remain unchanged
    def _compute_progress(self):
        for rec in self:
            total_questions = self.env['question'].search_count([
                ('questionnaire_id', '=', rec.questionnaire_id.id)
            ])
            answered_questions = self.env['user.question'].search_count([
                ('user_questionnaire_id', '=', rec.id),
                ('is_answered', '=', True)
            ])
            rec.progress = (answered_questions / total_questions) * 100 if total_questions > 0 else 0

    def _compute_is_finished(self):
        for rec in self:
            rec.is_finished = rec.progress > 90


class UserQuestion(models.Model):
    _name = 'user.question'
    _description = 'Savollar Foydalanuvchiga'

    user_questionnaire_id = fields.Many2one('user.questionnaire', string=_('User Questionnaire'))
    question_id = fields.Many2one('question', string=_('Savol'))
    is_answered = fields.Boolean(string=_('Javob berganmi?'))

    # Add this field to establish the relationship with user question options
    user_question_option_ids = fields.One2many(
        'user.question.option', 'user_question_id', string=_("Answer Options")
    )


class UserQuestionOption(models.Model):
    _name = 'user.question.option'
    _description = 'Foydalanuvchi Javoplari'

    user_question_id = fields.Many2one('user.question', string=_('Savol'))
    option_id = fields.Many2one('option', string=_('tanlov'))
users_manager.xml:
<?xml version="1.0" encoding="utf-8"?>
<odoo>
    <data>
        <!-- Tree View -->
        <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"/>
                    <field name="type"/>
                    <field name="role"/>
                    <field name="position"/>
                    <field name="login"/>
                    <field name="phone"/>
                </tree>
            </field>
        </record>
        <!-- Form View -->
        <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="priority" eval="1"/>
            <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" required="1"/>
                                <field name="email" invisible="1"/>
                                <field name="login" required="1"/>
                                <field name="phone" placeholder="+998 xx xxx xx xx"/>
                                <field name="type" required="1"/>
                                <field name="position" invisible="type == 'admin'"/>
                                <field name="role" 
                                        invisible="type == 'admin'" 
                                        required="type != 'admin'"/>
                                
                                <field name="region_id" 
                                        invisible="type == 'admin' or role != 'region' and role != 'district' and role != 'mahalla'" 
                                        required="role in ['region', 'district', 'mahalla']"
                                        />
                                
                                <field name="district_id"
                                        invisible="type == 'admin' or role != 'district' and role != 'mahalla'" 
                                        required="role in ['district', 'mahalla']"
                                        domain="[('region_id', '=', region_id)]"/>
                                
                                <field name="mahalla_id" 
                                        invisible="type == 'admin' or role != 'mahalla'" 
                                        required="role == 'mahalla'"
                                        domain="[('district_id', '=', district_id)]"/>
                                <separator string="Access Rights" colspan="4" invisible="type == 'admin'"/>
                                <field name="groups_id" widget="many2many_checkboxes" options="{'no_create': True}">
                                    <tree editable="bottom">
                                        <field name="name"/>
                                        <field name="category_id"/>
                                    </tree>
                                </field>
                            </group>
                        </group>
                    </sheet>
                </form>
            </field>
        </record>

        <!-- Kanban View -->
        <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>
                    <field name="id"/>
                    <field name="image_1920"/>
                    <field name="name"/>
                    <field name="type"/>
                    <field name="role"/>
                    <field name="position"/>
                    <templates>
                        <t t-name="kanban-box">
                            <div class="oe_kanban_global_click o_kanban_record_has_image_fill o_res_partner_kanban">
                                <div class="o_kanban_image_fill_left d-none d-md-block"
                                    t-attf-style="background-image:url(#{kanban_image('res.users', 'image_128', record.id.raw_value)})"
                                    role="img"/>
                                <div class="oe_kanban_details">
                                    <strong class="o_kanban_record_title">
                                        <field name="name"/>
                                    </strong>
                                    <div>
                                        <strong>Type: </strong><field name="type"/>
                                    </div>
                                    <div t-if="record.role.raw_value">
                                        <strong>Role: </strong><field name="role"/>
                                    </div>
                                    <div t-if="record.position.raw_value">
                                        <strong>Position: </strong><field name="position"/>
                                    </div>
                                </div>
                            </div>
                        </t>
                    </templates>
                </kanban>
            </field>
        </record>

        <!-- Actions -->
        <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>

        <!-- Menus -->
        <menuitem
            id="user_menu"
            name="User Management"
            sequence="1"/>

        <menuitem
            id="user_managers_menu"
            name="Users"
            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"/>
    </data>
</odoo>