i have project in odoo17 enterprise, now i'm creating models,  acess rights, record rules, user groups for users that have acess to admin panel, i will provide my files so that you can understand whats going on and can figure out how to solve my problem, approach to this task as your life task, make it perfect, go with golden average between efficiency and compactness, dont respond quickly, ready up your response, double check for syntax, imoprt and all other kinds of errors and logical fkps, double check every bit of it and then remake your response with these feedbacks from double checks and improve it to perfection

[task]We have three types of users with distinct roles: Admin (Superadmin), Moderator, and Reader. Each role has specific permissions and limitations based on their localization scope. Here is a detailed breakdown of the tasks to be completed:
Roles and Permissions

    Admin (Superadmin)
        Can perform any action.
        No one can manage Superadmins except other Superadmins.
    Moderator
        Can create, read, update, and delete (CRUD) announcements of all types.
        Can CRUD users (Moderators and lower positions) within their localization scope:
            Region users can create District and Mahalla users but not users from other regions.
            District users can create Mahalla users but not Region or other District users.
            Mahalla users cannot create higher-level users.
        Can read and update applications.
        Can send notifications.
        All actions are limited to their localization scope.
    Reader
        Has read-only access to all features available to Moderators.
        Cannot make any changes.

Hierarchical User Management

    Moderators can interact with user management (CRUD of users) only in a hierarchical manner:
        They can perform actions on users in lower positions within their localization scope.
        For example, a Region user cannot create a Mahalla user for another Region; they can only manage users within their own Region, District, or Mahalla.

Settings Access Rights

    When creating new users, the creator must have the necessary rights to grant access settings.
    A user can give access rights to another user only if they themselves possess those rights.

Tasks to Complete

    Implement Role Permissions
        Ensure that each role adheres to the specified permissions and limitations.
        Implement hierarchical user management based on localization scope.
    Create rules.xml
        Define XML rules that reflect the permissions and constraints for each role.
    Update permissions.py
        Modify the permissions.py file to include the new permission structures and checks for hierarchical access control.
    Update users.xml Form
        Adjust the users.xml form to incorporate settings access rights when creating new users.
        Ensure that users can only grant access rights if they have those rights themselves.

[end of task]


[my codes]
users.py: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'),
    ], string='User Type', required=True, default='reader')
    
    role = fields.Selection([
        ('republic', 'Republic'),
        ('region', 'Region'),
        ('district', 'District'),
        ('mahalla', 'Mahalla'),
    ], string='Role', default='mahalla')

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

    @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':
            self.is_republic = False
            self.is_region = False
            self.is_district = False
            self.is_mahalla = False
        elif 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},
        }
        
    def assign_group_based_on_role(self):
        self.ensure_one()
        groups_to_remove = self.env['res.groups'].search([
            ('name', 'in', ['Super Admin', 'Moderator', 'Reader', 'Republic Moderator', 'Republic Reader'])
        ])
        self.groups_id = [(3, group.id) for group in groups_to_remove]

        if self.type == 'admin':
            self.groups_id = [(4, self.env.ref('mahallam.group_super_admin').id)]
        else:
            base_group = self.env.ref(f'mahallam.group_{self.type}')
            self.groups_id = [(4, base_group.id)]
            
            if self.role and self.type in ['moderator', 'reader']:
                role_group = self.env.ref(f'mahallam.group_{self.role}_{self.type}')
                self.groups_id = [(4, role_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.")
questionaire.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.")
profile notifications.py:
from odoo import models, fields, api
import random
import string
from odoo.exceptions import ValidationError

class Notification(models.Model):
    _name = 'profile.notifications'
    _description = 'Notification'

    notification_id = fields.Char(string='Notification ID', required=True, default=lambda self: self._generate_notification_id())
    title = fields.Char(string='Title', required=True)
    description = fields.Text(string='Description')
    date = fields.Date(string='Date', default=fields.Date.today)
    time = fields.Datetime(string='Time', default=fields.Datetime.now)
    read = fields.Boolean(string='Read', default=False)
    user_id = fields.Many2one('res.partner', string='User', required=True)
    is_session_notification = fields.Boolean(string='Session Notification', default=False)

    _sql_constraints = [
        ('notification_id_unique', 'unique(notification_id)', 'Notification ID must be unique!'),
    ]


    @api.model
    def create(self, vals):
        vals['notification_id'] = self._generate_notification_id()
        return super(Notification, self).create(vals)
    @api.depends('read')
    def _compute_unread_count(self):
        for record in self:
            record.unread_count = len(self.search([('user_id', '=', record.user_id.id), ('read', '=', False)]))

    @api.model
    def _generate_notification_id(self):
        return ''.join(random.choices(string.ascii_uppercase + string.digits, k=10))

groups.xml:
<?xml version="1.0" encoding="utf-8"?>
<odoo>
    <data>
        <!-- User Types -->
        <record id="group_super_admin" model="res.groups">
            <field name="name">Super Admin</field>
            <field name="users" eval="[(4, ref('base.user_admin'))]"/>
        </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(we need to change permissions, it was for development environment)

users.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 is_region" 
                                        required="role in ['region', 'district', 'mahalla']"
                                        />
                                
                                <field name="district_id"
                                        invisible="type == 'admin' or is_district" 
                                        required="role in ['district', 'mahalla']"
                                        domain="[('region_id', '=', region_id)]"/>
                                
                                <field name="mahalla_id" 
                                        invisible="type == 'admin' or is_mahalla" 
                                        required="role == 'mahalla'"
                                        domain="[('district_id', '=', district_id)]"/>
                                <field name="is_region" invisible="1"/>
                                <field name="is_district" invisible="1"/>
                                <field name="is_mahalla" invisible="1"/>
                            </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>

application.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')
    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')
    partner_home_mahalla_id = fields.Many2one(
        'mahalla', string='Home Mahalla', store=True, readonly=True
    )
    partner_home_district_id = fields.Many2one(
        'district', string='Home District', store=True, readonly=True
    )
    partner_home_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({
                'partner_home_mahalla_id': main_home.home_id.mahalla_id.id,
                'partner_home_district_id': main_home.home_id.district_id.id,
                'partner_home_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 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')
[end of my code snippets]

[important]
give all updates with filenames, double check for missing parts of code, give short description of what you did after updated code snippet, give clearer response, clean code, folow best practices, its for production environment so that you need to be very coutious about any missing parts and any errors, strictly follow odoo17 enterprise syntax, i have faith on you lets do it 
[/important]