From 9f59706f8a9bb3063eec77ac47b9a2ccecc3bffb Mon Sep 17 00:00:00 2001 From: zhouzhou <123@qq.com> Date: Mon, 2 Dec 2024 22:36:10 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- yuthon_contract/models/inherit_hr_contract.py | 16 ++- .../views/inherit_hr_contract_views.xml | 19 ++++ yuthon_holiday/__manifest__.py | 2 +- yuthon_hr_attendance/models/go_approval.py | 12 ++- yuthon_hr_attendance/models/hr_attendance.py | 1 - .../models/yuthon_run_planning.py | 35 ++++++- .../models/yuthon_shift_planning.py | 97 ++++++++++++++++++- .../inherit_planning_slot_template_views.xml | 22 +++-- .../views/inherit_planning_slot_views.xml | 2 +- .../views/yuthon_shift_planning_views.xml | 10 +- .../models/yuthon_hr_employee.py | 3 +- .../views/inherit_hr_job_views.xml | 2 +- 12 files changed, 199 insertions(+), 22 deletions(-) diff --git a/yuthon_contract/models/inherit_hr_contract.py b/yuthon_contract/models/inherit_hr_contract.py index c6d77bb98..6a11cecb5 100644 --- a/yuthon_contract/models/inherit_hr_contract.py +++ b/yuthon_contract/models/inherit_hr_contract.py @@ -8,9 +8,23 @@ class HrContract(models.Model): _description = "员工合同拓展" code = fields.Char(string="编号", default=lambda self: self.env['ir.sequence'].next_by_code('contract_code')) + name = fields.Char(string="合同名称", compute='_compute_name') resource_calendar_id = fields.Many2one('resource.calendar', string='考勤时间表') + date_of_entry = fields.Date(string="入职时间", default=lambda self: self._default_date_of_entry()) work_entry_source = fields.Selection([ ('calendar', '考勤安排'), ('attendance', 'Attendances'), - ('planning', '特殊排版')]) \ No newline at end of file + ('planning', '特殊排版')]) + + @api.model + def _default_date_of_entry(self): + return self.date_start or fields.Date.today() + + @api.depends('contract_type_id') + def _compute_name(self): + for record in self: + if record.contract_type_id: + record.name = record.contract_type_id.name + else: + record.name = ' ' \ No newline at end of file diff --git a/yuthon_contract/views/inherit_hr_contract_views.xml b/yuthon_contract/views/inherit_hr_contract_views.xml index 32e8b46b3..dfa18b82b 100644 --- a/yuthon_contract/views/inherit_hr_contract_views.xml +++ b/yuthon_contract/views/inherit_hr_contract_views.xml @@ -1,5 +1,21 @@ + + inherit.hr.contract.yuthon.tree + hr.contract + + + + + + + 1 + + + 合同名称 + + + inherit.hr.contract.yuthon.form hr.contract @@ -8,6 +24,9 @@ + + 职级 + diff --git a/yuthon_holiday/__manifest__.py b/yuthon_holiday/__manifest__.py index 4e588ec01..dbfb90e32 100644 --- a/yuthon_holiday/__manifest__.py +++ b/yuthon_holiday/__manifest__.py @@ -17,7 +17,7 @@ 'wizard/yuthon_fixes_wizard_views.xml', ], 'demo': [], - 'depends': ['hr_holidays', 'planning', 'hr', 'yuthon_hr_employee', 'base', 'yuthon_issue', 'documents', 'mail'], + 'depends': ['hr_holidays', 'planning', 'hr', 'yuthon_hr_employee', 'base', 'yuthon_issue', 'documents', 'mail', 'soong_workflow'], 'installable': True, 'application': True, } diff --git a/yuthon_hr_attendance/models/go_approval.py b/yuthon_hr_attendance/models/go_approval.py index 6eb0cd925..1247eea24 100644 --- a/yuthon_hr_attendance/models/go_approval.py +++ b/yuthon_hr_attendance/models/go_approval.py @@ -27,7 +27,17 @@ class GoApprovals(models.Model): if rec.go_approval_ids: first_line = rec.go_approval_ids[0] if first_line.date_start and first_line.date_end: - rec.duration = (first_line.date_end - first_line.date_start).total_seconds() / 3600 + start_date = first_line.date_start + end_date = first_line.date_end + total_duration = end_date - start_date + current_date = start_date + while current_date < end_date: + if current_date.weekday() == 5: + total_duration -= timedelta(days=2) + current_date += timedelta(days=2) + else: + current_date += timedelta(days=1) + rec.duration = total_duration.total_seconds() / 3600 else: rec.duration = 0.0 else: diff --git a/yuthon_hr_attendance/models/hr_attendance.py b/yuthon_hr_attendance/models/hr_attendance.py index 2d66fac01..bcc9370d0 100644 --- a/yuthon_hr_attendance/models/hr_attendance.py +++ b/yuthon_hr_attendance/models/hr_attendance.py @@ -139,7 +139,6 @@ class HrAttendance(models.Model): 'default_actual_punch': self.current_data, 'default_replacement_time': replacement_time, 'default_users_id': self.employee_id.user_id.id, - 'default_replacement_time': replacement_time, } } diff --git a/yuthon_hr_attendance/models/yuthon_run_planning.py b/yuthon_hr_attendance/models/yuthon_run_planning.py index 80cca9d24..ef8b20fb7 100644 --- a/yuthon_hr_attendance/models/yuthon_run_planning.py +++ b/yuthon_hr_attendance/models/yuthon_run_planning.py @@ -11,6 +11,39 @@ class YuthonRunPlanning(models.Model): illustrate = fields.Char(string='排班说明', default='默认轮排到下个月') engineering_run_ids = fields.One2many('yuthon.engineering.run.line', 'engineering_planning_id', string='关联运行班排班明细') + def confirm(self): + start_date = datetime.now().replace(day=1, hour=0, minute=0, second=0, microsecond=0) # 获取本月第一天零点 + end_date = (start_date + timedelta(days=32)).replace(day=1) # 获取下个月第一天零点 + role_a = self.env['planning.role'].search([('name', '=', '运行班白班')], limit=1) + role_b = self.env['planning.role'].search([('name', '=', '运行班中值夜班')], limit=1) + department_id = self.env['hr.department'].search([('name', '=', '运行班')]) + if department_id: + employee_ids = self.env['hr.employee'].search([('department_id', '=', department_id.id)]) + else: + employee_ids = self.env['hr.employee'] + if not role_a: + resource_list = [] + for employee in employee_ids: + resource_id = self.env['resource.resource'].search([('name', '=', employee.name)], + limit=1) + resource_list.append(resource_id.id) + role_a = self.env['planning.role'].create({ + 'resource_ids': resource_list, + 'name': '运行班白班', + 'department_id': department_id.id + }) + + if not role_b: + resource_list = [] + for employee in employee_ids: + resource_ids = self.env['resource.resource'].search([('name', '=', employee.name)], + limit=1) + resource_list.append(resource_ids.id) + role_b = self.env['planning.role'].create({ + 'resource_ids': resource_list, + 'name': '运行班中值夜班', + 'department_id': department_id.id + }) class YuthonEngineeringRunLine(models.Model): _name = 'yuthon.engineering.run.line' @@ -19,4 +52,4 @@ class YuthonEngineeringRunLine(models.Model): employee_id = fields.Many2one('hr.employee', string='人员', domain=lambda self: [('department_id.name', '=', '运行班')]) sequence = fields.Integer(string='序号') - engineering_planning_id = fields.Many2one('yuthon.engineering.planning', string='关联运行班排班计划') + engineering_planning_id = fields.Many2one('yuthon.run.planning', string='关联运行班排班计划') diff --git a/yuthon_hr_attendance/models/yuthon_shift_planning.py b/yuthon_hr_attendance/models/yuthon_shift_planning.py index 872f72a46..c77bccb07 100644 --- a/yuthon_hr_attendance/models/yuthon_shift_planning.py +++ b/yuthon_hr_attendance/models/yuthon_shift_planning.py @@ -8,19 +8,108 @@ class YuthonShiftPlanning(models.Model): name = fields.Char(string='排班名称', required=True) illustrate = fields.Char(string='排班说明', default='默认按ABC三组轮排到下个月') + number_of_shifts = fields.Integer(string='轮班次数', default=0) planning_a_ids = fields.One2many('yuthon.shift.planning.a.line', 'shift_planning_id', string='关联A组') planning_b_ids = fields.One2many('yuthon.shift.planning.b.line', 'shift_planning_id', string='关联B组') planning_c_ids = fields.One2many('yuthon.shift.planning.c.line', 'shift_planning_id', string='关联C组') def confirm(self): - pass + start_date = datetime.now().replace(day=1, hour=0, minute=0, second=0, microsecond=0) # 获取本月第一天零点 + end_date = (start_date + timedelta(days=32)).replace(day=1) # 获取下个月第一天零点 + role_a = self.env['planning.role'].search([('name', '=', '保安部白班')], limit=1) + role_b = self.env['planning.role'].search([('name', '=', '保安部中班')], limit=1) + role_c = self.env['planning.role'].search([('name', '=', '保安部夜班')], limit=1) + department_id = self.env['hr.department'].search([('name', '=', '保安部')], limit=1) + department_ids = self.env['hr.department'].search([('name', 'in', ['保安部', '班组A', '班组B', '班组C'])]) + if department_ids: + employee_ids = self.env['hr.employee'].search([('department_id', 'in', department_ids.ids)]) + else: + employee_ids = self.env['hr.employee'] + if not role_a: + resource_list = [] + for employee in employee_ids: + resource_id = self.env['resource.resource'].search([('name', '=', employee.name)], + limit=1) + resource_list.append(resource_id.id) + role_a = self.env['planning.role'].create({ + 'resource_ids': resource_list, + 'name':'保安部白班', + 'department_id':department_id.id + }) + + if not role_b: + resource_list = [] + for employee in employee_ids: + resource_ids = self.env['resource.resource'].search([('name', '=', employee.name)], + limit=1) + resource_list.append(resource_ids.id) + role_b = self.env['planning.role'].create({ + 'resource_ids': resource_list, + 'name': '保安部中班', + 'department_id': department_id.id + }) + + if not role_c: + resource_list = [] + for employee in employee_ids: + resource_ids = self.env['resource.resource'].search([('name', '=', employee.name)], + limit=1) + resource_list.append(resource_ids.id) + role_c = self.env['planning.role'].create({ + 'resource_ids': resource_list, + 'name': '保安部夜班', + 'department_id': department_id.id + }) + + role = [role_a, role_b, role_c] + planning_groups = { + 'planning_a_ids': range(len(role)), # 默认顺序: 早 -> 中 -> 夜 + 'planning_b_ids': [1, 2, 0], # 中 -> 夜 -> 早 + 'planning_c_ids': [2, 1, 0] # 夜 -> 中 -> 早 + } + + for planning_group, role_order in planning_groups.items(): + for record in getattr(self, planning_group): + current_date = start_date + while current_date < end_date: + for role_index in role_order: + for _ in range(self.number_of_shifts): + role_template = self.env['planning.slot.template'].search( + [('role_id', '=', role[role_index].id)], limit=1) + self.create_planning_slot(record, role[role_index].id, role_template, current_date) + current_date += timedelta(days=1) + if current_date >= end_date: # 防止超出 end_date + break + if current_date >= end_date: + break + + def create_planning_slot(self, record,role,role_template,current_date): + start_hour = int(role_template.start_time) + start_minute = int(round((role_template.start_time - start_hour) * 60)) + end_hour = int(role_template.end_time) + end_minute = int(round((role_template.end_time - end_hour) * 60)) + + start_time = current_date.replace(hour=start_hour, minute=start_minute, second=0, microsecond=0)+ timedelta(hours=16) + if role_template.end_time < role_template.start_time: + end_time = (current_date + timedelta(days=1)).replace(hour=end_hour, minute=end_minute, second=0, + microsecond=0)+ timedelta(hours=16) + else: + end_time = current_date.replace(hour=end_hour, minute=end_minute, second=0, microsecond=0)+ timedelta(hours=16) + + self.env['planning.slot'].create({ + 'resource_id': record.employee_id.resource_id.id, + 'role_id':role, + 'start_datetime': start_time, + 'end_datetime': end_time, + 'allocated_hours':8, + }) class YuthonShiftPlanningALine(models.Model): _name = 'yuthon.shift.planning.a.line' _description = '排班安排A组' employee_id = fields.Many2one('hr.employee', string='人员', - domain=lambda self: [('department_id.name', '=', '保安部')]) + domain=lambda self: [('department_id.name', 'in', ['保安部', '班组A', '班组B','班组C'])]) sequence = fields.Integer(string='序号') shift_planning_id = fields.Many2one('yuthon.shift.planning', string='关联排班安排') @@ -30,7 +119,7 @@ class YuthonShiftPlanningBLine(models.Model): _description = '排班安排B组' employee_id = fields.Many2one('hr.employee', string='人员', - domain=lambda self: [('department_id.name', '=', '保安部')]) + domain=lambda self: [('department_id.name', 'in', ['保安部', '班组A', '班组B','班组C'])]) sequence = fields.Integer(string='序号') shift_planning_id = fields.Many2one('yuthon.shift.planning', string='关联排班安排') @@ -40,7 +129,7 @@ class YuthonShiftPlanningCLine(models.Model): _description = '排班安排C组' employee_id = fields.Many2one('hr.employee', string='人员', - domain=lambda self: [('department_id.name', '=', '保安部')]) + domain=lambda self: [('department_id.name', 'in', ['保安部', '班组A', '班组B','班组C'])]) sequence = fields.Integer(string='序号') shift_planning_id = fields.Many2one('yuthon.shift.planning', string='关联排班安排') diff --git a/yuthon_hr_attendance/views/inherit_planning_slot_template_views.xml b/yuthon_hr_attendance/views/inherit_planning_slot_template_views.xml index b3f9f2e3d..9b5503f40 100644 --- a/yuthon_hr_attendance/views/inherit_planning_slot_template_views.xml +++ b/yuthon_hr_attendance/views/inherit_planning_slot_template_views.xml @@ -1,7 +1,17 @@ - + planning.slot.template.tree.inherit planning.slot.template + + + + + + + + + planning.slot.template.form.inherit + planning.slot.template @@ -12,25 +22,25 @@ 班次模板 planning.slot.template - tree - [('department_id.name', '=', '保安部')] + tree,form + [('department_id.name','in',['保安部', '班组A', '班组B','班组C'])] 班次模板 planning.slot.template - tree + tree,form [('department_id.name', '=', '运行班')] 班次模板 planning.slot.template - tree + tree,form [('department_id.name', '=', '高压班')] 班次模板 planning.slot.template - tree + tree,form [('department_id.name', '=', '综合班')] \ No newline at end of file diff --git a/yuthon_hr_attendance/views/inherit_planning_slot_views.xml b/yuthon_hr_attendance/views/inherit_planning_slot_views.xml index c90e029b9..4da841f91 100644 --- a/yuthon_hr_attendance/views/inherit_planning_slot_views.xml +++ b/yuthon_hr_attendance/views/inherit_planning_slot_views.xml @@ -14,7 +14,7 @@ planning.slot gantt,calendar,tree,form,kanban,pivot,graph {'planning_expand_resource': 1, 'planning_expand_role': 1} - [('department_id.name','=','保安部')] + [('department_id.name','in',['保安部', '班组A', '班组B','班组C'])] 排班计划 diff --git a/yuthon_hr_attendance/views/yuthon_shift_planning_views.xml b/yuthon_hr_attendance/views/yuthon_shift_planning_views.xml index 0c3c47cef..e1f42a102 100644 --- a/yuthon_hr_attendance/views/yuthon_shift_planning_views.xml +++ b/yuthon_hr_attendance/views/yuthon_shift_planning_views.xml @@ -7,6 +7,7 @@ + @@ -22,11 +23,12 @@ + - + @@ -34,15 +36,15 @@ - + - + - + diff --git a/yuthon_hr_employee/models/yuthon_hr_employee.py b/yuthon_hr_employee/models/yuthon_hr_employee.py index be7325d98..9283c674d 100644 --- a/yuthon_hr_employee/models/yuthon_hr_employee.py +++ b/yuthon_hr_employee/models/yuthon_hr_employee.py @@ -30,7 +30,8 @@ class YuthonHrEmployee(models.Model): number = fields.Char(string="序号", store=True) user_number = fields.Char(string="员工编号", default=lambda self: self.env['ir.sequence'].next_by_code('employee_code')) - use_user_type = fields.Selection([('formal', '正式合同'), ('labor', '劳务协议'), + use_user_type = fields.Selection([('formal_one', '正式合同(一签)'), ('labor', '劳务协议'), ('formal_two', '正式合同(二签)'), + ('formal_none', '正式合同(无固定)'), ('part_time', '兼职协议'), ('employment', '用工协议'), ('internship', '实习协议')], string="用工形式") contract_company = fields.Selection([('thtz', '天河投资集团'), ('thwg', '天河物管'), diff --git a/yuthon_hr_employee/views/inherit_hr_job_views.xml b/yuthon_hr_employee/views/inherit_hr_job_views.xml index 43e196b65..9b524f82c 100644 --- a/yuthon_hr_employee/views/inherit_hr_job_views.xml +++ b/yuthon_hr_employee/views/inherit_hr_job_views.xml @@ -21,7 +21,7 @@ 1 - +