From e8039d22ab97ca881ee93df561afb030801668d6 Mon Sep 17 00:00:00 2001 From: Bakry Date: Mon, 11 Nov 2024 14:03:03 +0300 Subject: [PATCH] fix attendance --- odex25_hr/attendances/i18n/ar_001.po | 17 +++++ .../models/hr_attendance_register.py | 75 ++++++++++++++----- .../security/attendance_security.xml | 7 ++ .../views/hr_attendance_register_view.xml | 24 ++++-- 4 files changed, 99 insertions(+), 24 deletions(-) diff --git a/odex25_hr/attendances/i18n/ar_001.po b/odex25_hr/attendances/i18n/ar_001.po index a6b6ed547..dbb55f199 100644 --- a/odex25_hr/attendances/i18n/ar_001.po +++ b/odex25_hr/attendances/i18n/ar_001.po @@ -689,6 +689,17 @@ msgstr "من تاريخ" msgid "Another Employee" msgstr "من موظف آخر" +#. module: attendances +#: model:ir.model.fields,field_description:attendances.field_hr_attendance_register__all_employees +#: model_terms:ir.ui.view,arch_db:attendances.hr_attendance_register_form_view +msgid "All Employees" +msgstr "لكل الموظفين" + +#. module: attendances +#: model_terms:ir.ui.view,arch_db:attendances.hr_attendance_register_form_view +msgid "Employees" +msgstr "الموظفين" + #. module: attendances #: code:addons/attendances/wizard/attendances_report_wiz.py:0 #: code:addons/attendances/wizard/attendances_report_wiz.py:0 @@ -2215,3 +2226,9 @@ msgstr "للأسف، لموافقة المدير المباشر '%s' فقط او msgid "Sorry, The Refuse For The Direct Manager '%s' Only OR HR Manager!" msgstr "للأسف، لرفض المدير المباشر '%s' فقط او مدير الموارد البشرية !" +#. module: attendances +#: code:addons/attendances/models/hr_attendance_register.py:0 +#, python-format +msgid "Sorry,You must enter the Names Of Employees!" +msgstr "للأسف، يجب ادخال اسماء الموظفين!" + diff --git a/odex25_hr/attendances/models/hr_attendance_register.py b/odex25_hr/attendances/models/hr_attendance_register.py index a5eb0e795..f333ac7dd 100644 --- a/odex25_hr/attendances/models/hr_attendance_register.py +++ b/odex25_hr/attendances/models/hr_attendance_register.py @@ -33,6 +33,15 @@ class HrAttendanceRegister(models.Model): is_branch = fields.Many2one(related='department_id.branch_name', store=True, readonly=True) + all_employees = fields.Boolean(string='All Employees',default=False) + + employee_ids = fields.Many2many('hr.employee', string='Employees') + + @api.onchange('all_employees') + def chick_all_employees(self): + if self.all_employees==False: + self.employee_ids=False + def unlink(self): for rec in self: if rec.state != 'draft': @@ -74,12 +83,17 @@ class HrAttendanceRegister(models.Model): self.state = "draft" def button_submit(self): + if self.all_employees == True and not self.employee_ids: + raise exceptions.Warning(_("Sorry,You must enter the Names Of Employees!")) self.state = "send" def direct_manager(self): for rec in self: manager = rec.sudo().employee_id.parent_id hr_manager = rec.sudo().employee_id.company_id.hr_manager_id + if rec.all_employees == True and not rec.employee_ids: + raise exceptions.Warning(_("Sorry,You must enter the Names Of Employees!")) + if manager: if (manager.user_id.id == rec.env.uid or hr_manager.user_id.id == rec.env.uid): rec.write({'state': 'direct_manager'}) @@ -102,28 +116,53 @@ class HrAttendanceRegister(models.Model): rec.refused() def hr_manager(self): - extract_date = datetime.strptime(str(self.action_date), "%Y-%m-%d %H:%M:%S").date() - self.env['attendance.attendance'].create({ - 'employee_id': self.employee_id.id, - 'name': self.action_date, - 'action': self.action_type, - 'action_date': self.action_date.date(), - 'action_type': 'manual', - }) + for rec in self: + extract_date = datetime.strptime(str(rec.action_date), "%Y-%m-%d %H:%M:%S").date() + if rec.all_employees== False: + rec.env['attendance.attendance'].create({ + 'employee_id': rec.employee_id.id, + 'name': rec.action_date, + 'action': rec.action_type, + 'action_date': rec.action_date.date(), + 'action_type': 'manual', + }) + + rec.state = "hr_manager" + rec.call_cron_function() + else: + for emp in rec.employee_ids: + rec.env['attendance.attendance'].create({ + 'employee_id': emp.id, + 'name': rec.action_date, + 'action': rec.action_type, + 'action_date': rec.action_date.date(), + 'action_type': 'manual', + }) + rec.call_cron_function() + rec.state = "hr_manager" - self.state = "hr_manager" - self.call_cron_function() def set_to_draft(self): for item in self: - attendances = self.env['attendance.attendance'].search([('action_date', '=', item.action_date), - ('employee_id', '=', item.employee_id.id)], - order="name asc") - for attendance in attendances: - if attendance.name == item.action_date: - attendance.unlink() - self.state = "draft" - self.call_cron_function() + if item.all_employees== False: + attendances = self.env['attendance.attendance'].search([('action_date', '=', item.action_date), + ('employee_id', '=', item.employee_id.id)],order="name asc") + for attendance in attendances: + if attendance.name == item.action_date: + attendance.unlink() + item.state = "draft" + item.call_cron_function() + else: + for emp in item.employee_ids: + attendances = self.env['attendance.attendance'].search([('action_date', '=', item.action_date), + ('employee_id', '=', emp.id)],order="name asc") + + for attendance in attendances: + if attendance.name == item.action_date: + attendance.unlink() + item.call_cron_function() + item.state = "draft" + def call_cron_function(self): date = datetime.strptime(str(self.action_date), "%Y-%m-%d %H:%M:%S") diff --git a/odex25_hr/attendances/security/attendance_security.xml b/odex25_hr/attendances/security/attendance_security.xml index a72563741..5c68853dc 100644 --- a/odex25_hr/attendances/security/attendance_security.xml +++ b/odex25_hr/attendances/security/attendance_security.xml @@ -25,6 +25,13 @@ + + Manager: views attendance registers all employee + + [('all_employees' ,'=', True)] + + + attendance register company rule diff --git a/odex25_hr/attendances/views/hr_attendance_register_view.xml b/odex25_hr/attendances/views/hr_attendance_register_view.xml index 4cc515b82..5bc8481a0 100644 --- a/odex25_hr/attendances/views/hr_attendance_register_view.xml +++ b/odex25_hr/attendances/views/hr_attendance_register_view.xml @@ -53,24 +53,36 @@ + - + - - - + attrs="{'readonly': ['|',('from_hr_depart','=',False),('state','!=','draft')], + 'required':[('all_employees','=',False)]}"/> + + + + + + + + + + + +