From fc72baaee715c3a02067d2fb3ba3730bc7db67da Mon Sep 17 00:00:00 2001 From: zhouzhou <123@qq.com> Date: Wed, 11 Dec 2024 10:13:13 +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 --- .../models/yuthon_shift_planning.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/yuthon_hr_attendance/models/yuthon_shift_planning.py b/yuthon_hr_attendance/models/yuthon_shift_planning.py index fbe335380..14eeac2e7 100644 --- a/yuthon_hr_attendance/models/yuthon_shift_planning.py +++ b/yuthon_hr_attendance/models/yuthon_shift_planning.py @@ -25,8 +25,8 @@ class YuthonShiftPlanning(models.Model): role = [role_template_a, role_template_b, role_template_c] planning_groups = { 'planning_a_ids': range(len(role)), # 默认顺序: 早 -> 中 -> 夜 - 'planning_b_ids': [1, 2, 0], # 中 -> 夜 -> 早 - 'planning_c_ids': [2, 0, 1] # 夜 -> 早 -> 中 + 'planning_c_ids': [1, 2, 0], # 中 -> 夜 -> 早 + 'planning_b_ids': [2, 0, 1], # 夜 -> 早 -> 中 } weekday_mapping = { @@ -60,12 +60,17 @@ class YuthonShiftPlanning(models.Model): if resource_id in ever_holidays and current_weekday in ever_holidays[resource_id]: pass # 跳过休息日 else: - self.create_planning_slot(record, role_a, role[role_index], current_date) + if current_date.day == 31: + self.create_planning_slot(record, role_a, role[role_index-1], current_date) + else: + self.create_planning_slot(record, role_a, role[role_index], current_date) current_date += timedelta(days=1) if current_date >= end_date: break if current_date >= end_date: break + if current_date >= end_date: # 检查是否月末且已排完当前组 + break weekday_mapping = { 'one': 6, 'two': 0, 'three': 1, 'four': 2, 'five': 3, 'six': 4, 'seven': 5 @@ -96,7 +101,7 @@ class YuthonShiftPlanning(models.Model): while current_date <= end_date: current_weekday = current_date.weekday() if resource_id in ever_holidays and current_weekday in ever_holidays[resource_id]: - pass # 跳过休息日 + pass else: self.create_planning_slot(record, role_a,role_item, current_date) # 确保这个方法存在 current_date += timedelta(days=1)