diff --git a/yuthon_hr_attendance/models/__init__.py b/yuthon_hr_attendance/models/__init__.py index 95838ccc6..3a0ccaa58 100644 --- a/yuthon_hr_attendance/models/__init__.py +++ b/yuthon_hr_attendance/models/__init__.py @@ -10,8 +10,6 @@ from . import card_approval from . import planning_template_inherit from . import overtime_page from . import inherit_planning_role -from . import inherit_planning_slot_template -from . import inherit_planning_slot from . import yuthon_shift_planning from . import yuthon_run_planning from . import duty_approval diff --git a/yuthon_hr_attendance/models/yuthon_run_planning.py b/yuthon_hr_attendance/models/yuthon_run_planning.py index 1aae6dca7..7d2d38ef2 100644 --- a/yuthon_hr_attendance/models/yuthon_run_planning.py +++ b/yuthon_hr_attendance/models/yuthon_run_planning.py @@ -9,11 +9,12 @@ class YuthonRunPlanning(models.Model): name = fields.Char(string='排班计划名称', required=True) illustrate = fields.Char(string='排班说明', default='默认轮排到下个月') - engineering_run_ids = fields.One2many('yuthon.engineering.run.line', 'engineering_planning_id', string='关联工程部排班明细') - high_run_ids = fields.One2many('yuthon.high.run.line', 'engineering_planning_id', string='关联工程部排班明细') - all_run_ids = fields.One2many('yuthon.all.run.line', 'engineering_planning_id', string='关联工程部排班明细') + engineering_run_ids = fields.One2many('yuthon.engineering.run.line', 'engineering_planning_id', string='关联运行班排班明细') + high_run_ids = fields.One2many('yuthon.high.run.line', 'engineering_planning_id', string='关联高压班排班明细') + all_run_ids = fields.One2many('yuthon.all.run.line', 'engineering_planning_id', string='关联综合部排班明细') def confirm(self): + run_lines_list = [self.engineering_run_ids, self.high_run_ids, self.all_run_ids] today = datetime.today().date() first_day_of_month = today.replace(day=1) if today.month < 12: @@ -23,48 +24,59 @@ class YuthonRunPlanning(models.Model): role_a = self.env['planning.role'].search([('name', '=', '工程部白班')], limit=1) start_time = int(self.env['planning.slot.template'].search([('role_id', '=', role_a.id)]).start_time) end_time = int(self.env['planning.slot.template'].search([('role_id', '=', role_a.id)]).end_time) - for employee in self.engineering_run_ids: + run = 0 + for run_lines in run_lines_list: + if not run_lines: + continue + run += 1 + for employee in run_lines: + current_date = first_day_of_month + while current_date <= last_day_of_month: + resource_id = employee.employee_id.resource_id + self.env['planning.slot'].create({ + 'resource_id': resource_id.id, + 'start_datetime': datetime(current_date.year, current_date.month, current_date.day, start_time) + timedelta(hours=16), + 'end_datetime': datetime(current_date.year, current_date.month, current_date.day, end_time) + timedelta(hours=16), + 'role_id': role_a.id, + 'allocated_hours': 8, + }) + current_date += timedelta(days=1) + if current_date > last_day_of_month: + break + role_b = self.env['planning.role'].search([('name', '=', '工程部中值夜班')], limit=1) + start_time2 = int(self.env['planning.slot.template'].search([('role_id', '=', role_b.id)]).start_time) + end_time2 = int(self.env['planning.slot.template'].search([('role_id', '=', role_b.id)]).end_time) + if run == 1: + all_slot = self.env['planning.slot'].search([('department_id.name', '=', '运行班')]) + elif run == 2: + all_slot = self.env['planning.slot'].search([('department_id.name', '=', '高压班')]) + elif run == 3: + all_slot = self.env['planning.slot'].search([('department_id.name', '=', '综合班')]) + current_date = first_day_of_month + i = -1 while current_date <= last_day_of_month: - resource_id = employee.employee_id.resource_id - self.env['planning.slot'].create({ - 'resource_id': resource_id.id, - 'start_datetime': datetime(current_date.year, current_date.month, current_date.day, start_time) + timedelta(hours=16), - 'end_datetime': datetime(current_date.year, current_date.month, current_date.day, end_time) + timedelta(hours=16), - 'role_id': role_a.id, - 'allocated_hours': 8, - }) - current_date += timedelta(days=1) - if current_date > last_day_of_month: - break - role_b = self.env['planning.role'].search([('name', '=', '工程部中值夜班')], limit=1) - start_time2 = int(self.env['planning.slot.template'].search([('role_id', '=', role_b.id)]).start_time) - end_time2 = int(self.env['planning.slot.template'].search([('role_id', '=', role_b.id)]).end_time) - all_slot = self.env['planning.slot'].search([('department_id.name', '=', '运行班')]) - current_date = first_day_of_month - i = -1 - while current_date <= last_day_of_month: - for employee in range(0, len(self.engineering_run_ids)): - i = i + 1 - slot_id = all_slot.search([('resource_id', '=', self.engineering_run_ids[employee].employee_id.resource_id.id)]).sorted('start_datetime')[i] - slot_id.sudo().write({ - 'template_id': self.env['planning.slot.template'].search([('role_id', '=', role_b.id)]).id, - 'start_datetime': datetime(current_date.year, current_date.month, current_date.day, - start_time2) + timedelta(hours=16), - 'end_datetime': datetime(current_date.year, current_date.month, current_date.day, - end_time2) + timedelta(days=1, hours=16), - 'role_id': role_b.id, - 'allocated_hours': 8, - }) - current_date += timedelta(days=1) - if current_date > last_day_of_month: - break + for employee in range(0, len(run_lines)): + i = i + 1 + slot_id = all_slot.search([('resource_id', '=', run_lines[employee].employee_id.resource_id.id)]).sorted('start_datetime')[i] + slot_id.sudo().write({ + 'template_id': self.env['planning.slot.template'].search([('role_id', '=', role_b.id)]).id, + 'start_datetime': datetime(current_date.year, current_date.month, current_date.day, + start_time2) + timedelta(hours=16), + 'end_datetime': datetime(current_date.year, current_date.month, current_date.day, + end_time2) + timedelta(days=1, hours=16), + 'role_id': role_b.id, + 'allocated_hours': 8, + }) + current_date += timedelta(days=1) + if current_date > last_day_of_month: + break return { 'type': 'ir.actions.client', 'tag': 'display_notification', 'params': { 'type': 'success', - 'message': '运行班已排完', + 'message': '排班安排已完成', 'sticky': False, } } diff --git a/yuthon_hr_attendance/models/yuthon_shift_planning.py b/yuthon_hr_attendance/models/yuthon_shift_planning.py index 1b772b8ff..c4bcf1d44 100644 --- a/yuthon_hr_attendance/models/yuthon_shift_planning.py +++ b/yuthon_hr_attendance/models/yuthon_shift_planning.py @@ -43,17 +43,12 @@ class YuthonShiftPlanning(models.Model): 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) + start_time = current_date.replace(hour=start_hour)+ 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) + end_time = current_date.replace(hour=end_hour)+ timedelta(days=1, hours=16) else: - end_time = current_date.replace(hour=end_hour, minute=end_minute, second=0, microsecond=0)+ timedelta(hours=16) - + end_time = current_date.replace(hour=end_hour)+ timedelta(hours=16) self.env['planning.slot'].create({ 'resource_id': record.employee_id.resource_id.id, 'role_id':role,