165 lines
6.4 KiB
Python
165 lines
6.4 KiB
Python
from odoo import models, fields, api, _
|
|
from odoo.exceptions import ValidationError
|
|
|
|
class ServicesSettings(models.Model):
|
|
_inherit = 'services.settings' # Inherit existing model
|
|
|
|
linked_to_department = fields.Boolean(
|
|
string='Linked to Department',
|
|
help='Link the service to an HR department'
|
|
)
|
|
hr_department_id = fields.Many2one(
|
|
'hr.department', string='Linked Department', readonly=True
|
|
)
|
|
manager_id = fields.Many2one(
|
|
'hr.employee', string='Manager',
|
|
)
|
|
|
|
service_type = fields.Selection(selection_add=[
|
|
('educational_care', 'خدمة الرعاية التعليمية'),
|
|
('bachelor_service', 'خدمة البكالريوس'),
|
|
('diploma_service', 'خدمة الدبلوم'),
|
|
('bachelor_intercession', 'خدمة شفاعة البكالريوس'),
|
|
('diploma_intercession', 'خدمة شفاعة الدبلوم'),
|
|
('training_service', 'خدمة التدريب'),
|
|
('training_intercession', 'خدمة شفاعة التدريب'),
|
|
('funding_service', 'خدمة التمويل'),
|
|
('project_funding_intercession', 'خدمة شفاعة تمويل المشاريع'),
|
|
('employment_service', 'خدمة التوظيف')
|
|
])
|
|
|
|
|
|
@api.model
|
|
def create(self, vals):
|
|
service = super().create(vals)
|
|
if service.linked_to_department:
|
|
dept = self.env['hr.department'].search([('name', '=', service.service_name)], limit=1)
|
|
if not dept:
|
|
dept = self.env['hr.department'].create({
|
|
'name': service.service_name,
|
|
'department_type': 'unit',
|
|
'manager_id': service.manager_id.id,
|
|
|
|
'service_link_id': service.id
|
|
})
|
|
service.hr_department_id = dept.id
|
|
return service
|
|
|
|
def write(self, vals):
|
|
res = super().write(vals)
|
|
for service in self:
|
|
# If linked_to_department field updated
|
|
if 'linked_to_department' in vals:
|
|
if service.linked_to_department and not service.hr_department_id:
|
|
# Create department if missing
|
|
dept = self.env['hr.department'].search([('name', '=', service.service_name)], limit=1)
|
|
if not dept:
|
|
dept = self.env['hr.department'].create({
|
|
'name': service.service_name,
|
|
'department_type': 'unit',
|
|
'manager_id': service.manager_id.id,
|
|
'service_link_id': service.id
|
|
})
|
|
service.hr_department_id = dept.id
|
|
elif not service.linked_to_department and service.hr_department_id:
|
|
# Remove linked department if no dependencies (employees or requests)
|
|
hr_dept = service.hr_department_id
|
|
empowerment_request = self.env['empowerment.request'].search([('department_id', '=', hr_dept.id)], limit=1)
|
|
if hr_dept.employee_ids or empowerment_request:
|
|
raise ValidationError(_('لا يمكن فك الربط، قسم الموارد البشرية مرتبط بموظفين أو طلبات.'))
|
|
hr_dept.unlink()
|
|
service.hr_department_id = False
|
|
return res
|
|
|
|
def unlink(self):
|
|
for service in self:
|
|
if service.linked_to_department and service.hr_department_id:
|
|
hr_dept = service.hr_department_id
|
|
empowerment_request = self.env['empowerment.request'].search([('department_id', '=', hr_dept.id)], limit=1)
|
|
if hr_dept.employee_ids or empowerment_request:
|
|
raise ValidationError(_('لا يمكن حذف الخدمة، القسم مرتبط بموظفين أو طلبات.'))
|
|
hr_dept.unlink()
|
|
return super().unlink()
|
|
|
|
|
|
class HrDepartment(models.Model):
|
|
_inherit = 'hr.department'
|
|
|
|
service_link_id = fields.Many2one(
|
|
'services.settings', string='خدمة مرتبطة', readonly=True
|
|
)
|
|
|
|
|
|
|
|
|
|
class EmpowermentEducationEntity(models.Model):
|
|
_name = 'empowerment.education.entity'
|
|
_description = 'Education Entity'
|
|
|
|
name = fields.Char(string='Entity Name', required=True)
|
|
entity_type = fields.Selection(
|
|
[('university', 'University'), ('college', 'College'),
|
|
('institute', 'Institute'), ('school', 'School')],
|
|
string='Entity Type', required=True
|
|
)
|
|
study_specialization = fields.Selection(
|
|
[('bachelor', 'Bachelor'), ('diploma', 'Diploma')],
|
|
string='Study Specialization', required=True
|
|
)
|
|
specialization_id = fields.Many2one(
|
|
'empowerment.study.specialization', string='Study Specialization',
|
|
domain="[('type', '=', study_specialization)]",
|
|
)
|
|
|
|
_sql_constraints = [
|
|
('name_unique', 'unique(name)', 'اسم الجهة يجب أن يكون فريداً!'),
|
|
]
|
|
|
|
@api.onchange('entity_type')
|
|
def _onchange_entity_type(self):
|
|
if self.entity_type in ['university', 'college']:
|
|
self.study_specialization = 'bachelor'
|
|
elif self.entity_type in ['institute', 'school']:
|
|
self.study_specialization = 'diploma'
|
|
else:
|
|
self.study_specialization = False
|
|
|
|
# Reset specialization_id when entity_type changes
|
|
# self.specialization_id = False
|
|
|
|
|
|
|
|
class StudySpecialization(models.Model):
|
|
_name = 'empowerment.study.specialization'
|
|
_description = 'Study Specialization'
|
|
|
|
type = fields.Selection([
|
|
('bachelor', 'Bachelor'),
|
|
('diploma', 'Diploma')
|
|
], string='Study Type', required=True)
|
|
|
|
universities_colleges = fields.Char(string='Universities / Colleges')
|
|
institutes_schools = fields.Char(string='Institute / School Name')
|
|
|
|
class EmpowermentQualificationCourse(models.Model):
|
|
_name = 'empowerment.qualification.course'
|
|
_description = 'Qualification Course'
|
|
|
|
name = fields.Char(string='Entity Name', required=True)
|
|
|
|
|
|
class EmpowermentTrainingEntity(models.Model):
|
|
_name = 'empowerment.training.entity'
|
|
_description = 'Training Entities'
|
|
|
|
name = fields.Char(string='Entity Name', required=True)
|
|
|
|
|
|
class EmpowermentProjectFundingType(models.Model):
|
|
_name = 'empowerment.project.funding.type'
|
|
_description = 'Project Funding Type'
|
|
|
|
name = fields.Char(string='Entity Name', required=True)
|
|
|
|
|