From ea3fc976cfacad2476165ae7018b509911933561 Mon Sep 17 00:00:00 2001 From: zhouzhou <123@qq.com> Date: Mon, 16 Dec 2024 17:26:09 +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_duty_plan.py | 26 +++-- .../models/yuthon_run_planning.py | 105 ++++++++++++------ .../models/yuthon_shift_planning.py | 26 +++-- .../views/yuthon_duty_plan_views.xml | 1 + .../views/yuthon_run_planning_views.xml | 3 + .../views/yuthon_shift_planning_views.xml | 1 + 6 files changed, 116 insertions(+), 46 deletions(-) diff --git a/yuthon_hr_attendance/models/yuthon_duty_plan.py b/yuthon_hr_attendance/models/yuthon_duty_plan.py index b2a57ea3a..ae73a6058 100644 --- a/yuthon_hr_attendance/models/yuthon_duty_plan.py +++ b/yuthon_hr_attendance/models/yuthon_duty_plan.py @@ -18,21 +18,29 @@ class YuthonDutyPlan(models.Model): ('September', '九月'), ('October', '十月'), ('November', '十一月'), ('December', '十二月')], string='选择月份') - def auto_duty_plan(self): + def auto_duty_plan(self,next_date=False): month_names = { 'January': 1, 'February': 2, 'March': 3, 'April': 4, 'May': 5, 'June': 6, 'July': 7, 'August': 8, 'September': 9, 'October': 10, 'November': 11, 'December': 12 } - + current_month = datetime.now().month + current_year = datetime.now().year selected_month = month_names.get(self.select_time) year = datetime.now().year - first_day_of_month = datetime(year, selected_month, 1) - - # 计算结束日期(下个月的第一天) - next_month = (selected_month % 12) + 1 - next_year = year + (1 if next_month == 1 else 0) # 如果是12月,年份加1 - last_day_of_month = datetime(next_year, next_month, 1) + if not next_date: + first_day_of_month = datetime(year, selected_month, 1) + # 计算结束日期(下个月的第一天) + next_month = (selected_month % 12) + 1 + next_year = year + (1 if next_month == 1 else 0) # 如果是12月,年份加1 + last_day_of_month = datetime(next_year, next_month, 1) + else: + next_month = (current_month % 12) + 1 + next_year = current_year + (1 if next_month == 1 else 0) + first_day_of_month = datetime(next_year, next_month, 1) # Next month's first day + next_next_month = (next_month % 12) + 1 + next_next_year = next_year + (1 if next_next_month == 1 else 0) + last_day_of_month = datetime(next_next_year, next_next_month, 1) role_a = self.env['planning.role'].search([('name', '=', '联安粮库')], limit=1) role_template_a = self.env['planning.slot.template'].search([('planning_name', '=', '白班'), ('role_id', '=', role_a.id)]) role_template_b = self.env['planning.slot.template'].search([('planning_name', '=', '值班'), ('role_id', '=', role_a.id)]) @@ -94,6 +102,8 @@ class YuthonDutyPlan(models.Model): } } + def duty_next_plan(self): + self.auto_duty_plan(next_date=True) class DutyPlanLine(models.Model): _name = 'duty.plan.line' diff --git a/yuthon_hr_attendance/models/yuthon_run_planning.py b/yuthon_hr_attendance/models/yuthon_run_planning.py index a73fd424d..55f356a82 100644 --- a/yuthon_hr_attendance/models/yuthon_run_planning.py +++ b/yuthon_hr_attendance/models/yuthon_run_planning.py @@ -1,7 +1,7 @@ from odoo import api, fields, models, tools, _ from datetime import datetime, time, timedelta from odoo.exceptions import UserError - +from datetime import date, timedelta class YuthonRunPlanning(models.Model): _name = 'yuthon.run.planning' @@ -20,19 +20,29 @@ class YuthonRunPlanning(models.Model): ('December', '十二月')], string='选择月份') # 运行班 - def run_confirm(self): + def run_confirm(self,next_date=False): month_names = { 'January': 1, 'February': 2, 'March': 3, 'April': 4, 'May': 5, 'June': 6, 'July': 7, 'August': 8, 'September': 9, 'October': 10, 'November': 11, 'December': 12 } + current_month = datetime.now().month + current_year = datetime.now().year selected_month = month_names.get(self.select_time) year = datetime.now().year - first_day_of_month = datetime(year, selected_month, 1) - # 计算结束日期(下个月的第一天) - next_month = (selected_month % 12) + 1 - next_year = year + (1 if next_month == 1 else 0) # 如果是12月,年份加1 - last_day_of_month = datetime(next_year, next_month, 1) + if not next_date: + first_day_of_month = datetime(year, selected_month, 1) + # 计算结束日期(下个月的第一天) + next_month = (selected_month % 12) + 1 + next_year = year + (1 if next_month == 1 else 0) # 如果是12月,年份加1 + last_day_of_month = datetime(next_year, next_month, 1) + else: + next_month = (current_month % 12) + 1 + next_year = current_year + (1 if next_month == 1 else 0) + first_day_of_month = datetime(next_year, next_month, 1) # Next month's first day + next_next_month = (next_month % 12) + 1 + next_next_year = next_year + (1 if next_next_month == 1 else 0) + last_day_of_month = datetime(next_next_year, next_next_month, 1) role_a = self.env['planning.role'].search([('name', '=', '工程部')], limit=1) start_time = int(self.env['planning.slot.template'].search([('role_id', '=', role_a.id), ('planning_name', '=', '白班')]).start_time) end_time = int(self.env['planning.slot.template'].search([('role_id', '=', role_a.id), ('planning_name', '=', '白班')]).end_time) @@ -51,8 +61,8 @@ class YuthonRunPlanning(models.Model): current_date += timedelta(days=1) if current_date > last_day_of_month: break - start_time2 = int(self.env['planning.slot.template'].search([('planning_name', '=', '中值夜班'), ('role_id', '=', role_a.id)]).start_time) - end_time2 = int(self.env['planning.slot.template'].search([('planning_name', '=', '中值夜班'), ('role_id', '=', role_a.id)]).end_time) + start_time2 = int(self.env['planning.slot.template'].search([('planning_name', '=', '中夜'), ('role_id', '=', role_a.id)]).start_time) + end_time2 = int(self.env['planning.slot.template'].search([('planning_name', '=', '中夜'), ('role_id', '=', role_a.id)]).end_time) all_slot = self.env['planning.slot'].search([('department_id.name', '=', '运行班')]) current_date = first_day_of_month i = -1 @@ -62,7 +72,7 @@ class YuthonRunPlanning(models.Model): slot_id = all_slot.search([('resource_id', '=', self.engineering_run_ids[employee].employee_id.resource_id.id)]).sorted('start_datetime') if i < 31: slot_id[i].write({ - 'template_id': self.env['planning.slot.template'].search([('role_id', '=', role_a.id), ('planning_name', '=', '中值夜班')]).id, + 'template_id': self.env['planning.slot.template'].search([('role_id', '=', role_a.id), ('planning_name', '=', '中夜')]).id, 'start_datetime': datetime(current_date.year, current_date.month, current_date.day,start_time2) + timedelta(hours=16) - timedelta(days=1), 'end_datetime': datetime(current_date.year, current_date.month, current_date.day,end_time2) + timedelta(days=1, hours=16) - timedelta(days=1), 'role_id': role_a.id, @@ -70,7 +80,7 @@ class YuthonRunPlanning(models.Model): }) if i + 1 < len(slot_id): slot_id[i + 1].write({ - 'template_id': self.env['planning.slot.template'].search([('role_id', '=', role_a.id), ('planning_name', '=', '白班中午值班')]).id, + 'template_id': self.env['planning.slot.template'].search([('role_id', '=', role_a.id), ('planning_name', '=', '白值')]).id, 'start_datetime': datetime(current_date.year, current_date.month, current_date.day,start_time) + timedelta(days=1, hours=16) - timedelta(days=1), 'end_datetime': datetime(current_date.year, current_date.month, current_date.day,end_time) + timedelta(days=1, hours=16) - timedelta(days=1), 'role_id': role_a.id, @@ -116,19 +126,30 @@ class YuthonRunPlanning(models.Model): } } # 高压班 - def high_confirm(self): + def high_confirm(self,next_date=False): month_names = { 'January': 1, 'February': 2, 'March': 3, 'April': 4, 'May': 5, 'June': 6, 'July': 7, 'August': 8, 'September': 9, 'October': 10, 'November': 11, 'December': 12 } + current_month = datetime.now().month + current_year = datetime.now().year selected_month = month_names.get(self.select_time) year = datetime.now().year - first_day_of_month = datetime(year, selected_month, 1) - # 计算结束日期(下个月的第一天) - next_month = (selected_month % 12) + 1 - next_year = year + (1 if next_month == 1 else 0) # 如果是12月,年份加1 - last_day_of_month = datetime(next_year, next_month, 1) + if not next_date: + first_day_of_month = datetime(year, selected_month, 1) + # 计算结束日期(下个月的第一天) + next_month = (selected_month % 12) + 1 + next_year = year + (1 if next_month == 1 else 0) # 如果是12月,年份加1 + last_day_of_month = datetime(next_year, next_month, 1) + else: + next_month = (current_month % 12) + 1 + next_year = current_year + (1 if next_month == 1 else 0) + first_day_of_month = datetime(next_year, next_month, 1) # Next month's first day + next_next_month = (next_month % 12) + 1 + next_next_year = next_year + (1 if next_next_month == 1 else 0) + last_day_of_month = datetime(next_next_year, next_next_month, 1) + role_a = self.env['planning.role'].search([('name', '=', '工程部')], limit=1) start_time = int(self.env['planning.slot.template'].search([('role_id', '=', role_a.id), ('planning_name', '=', '白班')]).start_time) end_time = int(self.env['planning.slot.template'].search([('role_id', '=', role_a.id), ('planning_name', '=', '白班')]).end_time) @@ -147,8 +168,8 @@ class YuthonRunPlanning(models.Model): current_date += timedelta(days=1) if current_date > last_day_of_month: break - start_time2 = int(self.env['planning.slot.template'].search( [('planning_name', '=', '中值夜班'), ('role_id', '=', role_a.id)]).start_time) - end_time2 = int(self.env['planning.slot.template'].search([('planning_name', '=', '中值夜班'), ('role_id', '=', role_a.id)]).end_time) + start_time2 = int(self.env['planning.slot.template'].search( [('planning_name', '=', '中夜'), ('role_id', '=', role_a.id)]).start_time) + end_time2 = int(self.env['planning.slot.template'].search([('planning_name', '=', '中夜'), ('role_id', '=', role_a.id)]).end_time) all_slot = self.env['planning.slot'].search([('department_id.name', '=', '高压班')]) current_date = first_day_of_month i = -1 @@ -161,7 +182,7 @@ class YuthonRunPlanning(models.Model): if i < 31: slot_id[i].write({ 'template_id': self.env['planning.slot.template'].search( - [('role_id', '=', role_a.id), ('planning_name', '=', '中值夜班')]).id, + [('role_id', '=', role_a.id), ('planning_name', '=', '中夜')]).id, 'start_datetime': datetime(current_date.year, current_date.month, current_date.day,start_time2) + timedelta(hours=16) - timedelta(days=1), 'end_datetime': datetime(current_date.year, current_date.month, current_date.day,end_time2) + timedelta(days=1, hours=16) - timedelta(days=1), 'role_id': role_a.id, @@ -170,7 +191,7 @@ class YuthonRunPlanning(models.Model): if i + 1 < len(slot_id): slot_id[i + 1].write({ 'template_id': self.env['planning.slot.template'].search( - [('role_id', '=', role_a.id), ('planning_name', '=', '白班中午值班')]).id, + [('role_id', '=', role_a.id), ('planning_name', '=', '白值')]).id, 'start_datetime': datetime(current_date.year, current_date.month, current_date.day,start_time) + timedelta(days=1, hours=16) - timedelta(days=1), 'end_datetime': datetime(current_date.year, current_date.month, current_date.day,end_time) + timedelta(days=1, hours=16) - timedelta(days=1), 'role_id': role_a.id, @@ -189,19 +210,30 @@ class YuthonRunPlanning(models.Model): } } # 综合班 - def integrated_confirm(self): + def integrated_confirm(self,next_date=False): month_names = { 'January': 1, 'February': 2, 'March': 3, 'April': 4, 'May': 5, 'June': 6, 'July': 7, 'August': 8, 'September': 9, 'October': 10, 'November': 11, 'December': 12 } + current_month = datetime.now().month + current_year = datetime.now().year selected_month = month_names.get(self.select_time) year = datetime.now().year - first_day_of_month = datetime(year, selected_month, 1) - # 计算结束日期(下个月的第一天) - next_month = (selected_month % 12) + 1 - next_year = year + (1 if next_month == 1 else 0) # 如果是12月,年份加1 - last_day_of_month = datetime(next_year, next_month, 1) + if not next_date: + first_day_of_month = datetime(year, selected_month, 1) + # 计算结束日期(下个月的第一天) + next_month = (selected_month % 12) + 1 + next_year = year + (1 if next_month == 1 else 0) # 如果是12月,年份加1 + last_day_of_month = datetime(next_year, next_month, 1) + else: + next_month = (current_month % 12) + 1 + next_year = current_year + (1 if next_month == 1 else 0) + first_day_of_month = datetime(next_year, next_month, 1) # Next month's first day + next_next_month = (next_month % 12) + 1 + next_next_year = next_year + (1 if next_next_month == 1 else 0) + last_day_of_month = datetime(next_next_year, next_next_month, 1) + role_a = self.env['planning.role'].search([('name', '=', '工程部')], limit=1) start_time = int(self.env['planning.slot.template'].search( [('role_id', '=', role_a.id), ('planning_name', '=', '白班')]).start_time) @@ -224,9 +256,9 @@ class YuthonRunPlanning(models.Model): if current_date > last_day_of_month: break start_time2 = int(self.env['planning.slot.template'].search( - [('planning_name', '=', '中值夜班'), ('role_id', '=', role_a.id)]).start_time) + [('planning_name', '=', '中夜'), ('role_id', '=', role_a.id)]).start_time) end_time2 = int(self.env['planning.slot.template'].search( - [('planning_name', '=', '中值夜班'), ('role_id', '=', role_a.id)]).end_time) + [('planning_name', '=', '中夜'), ('role_id', '=', role_a.id)]).end_time) all_slot = self.env['planning.slot'].search([('department_id.name', '=', '综合班')]) current_date = first_day_of_month @@ -240,7 +272,7 @@ class YuthonRunPlanning(models.Model): if i < 31: slot_id[i].write({ 'template_id': self.env['planning.slot.template'].search( - [('role_id', '=', role_a.id), ('planning_name', '=', '中值夜班')]).id, + [('role_id', '=', role_a.id), ('planning_name', '=', '中夜')]).id, 'start_datetime': datetime(current_date.year, current_date.month, current_date.day,start_time2) + timedelta(hours=16) - timedelta(days=1), 'end_datetime': datetime(current_date.year, current_date.month, current_date.day,end_time2) + timedelta(days=1, hours=16) - timedelta(days=1), 'role_id': role_a.id, @@ -249,7 +281,7 @@ class YuthonRunPlanning(models.Model): if i + 1 < len(slot_id): slot_id[i + 1].write({ 'template_id': self.env['planning.slot.template'].search( - [('role_id', '=', role_a.id), ('planning_name', '=', '白班中午值班')]).id, + [('role_id', '=', role_a.id), ('planning_name', '=', '白值')]).id, 'start_datetime': datetime(current_date.year, current_date.month, current_date.day, start_time) + timedelta(days=1, hours=16) - timedelta(days=1), 'end_datetime': datetime(current_date.year, current_date.month, current_date.day, @@ -270,6 +302,17 @@ class YuthonRunPlanning(models.Model): } } + # 安排下个月排班 + # 运行班 + def run_next_planning(self): + self.run_confirm(next_date=True) + # 高压班 + def high_next_planning(self): + self.high_confirm(next_date=True) + # 综合班 + def comprehensive_next_planning(self): + self.integrated_confirm(next_date=True) + class YuthonEngineeringRunLine(models.Model): _name = 'yuthon.engineering.run.line' _description = '运行班计划明细' diff --git a/yuthon_hr_attendance/models/yuthon_shift_planning.py b/yuthon_hr_attendance/models/yuthon_shift_planning.py index 85178fe52..9af9953e7 100644 --- a/yuthon_hr_attendance/models/yuthon_shift_planning.py +++ b/yuthon_hr_attendance/models/yuthon_shift_planning.py @@ -19,21 +19,30 @@ class YuthonShiftPlanning(models.Model): ('September', '九月'), ('October', '十月'), ('November', '十一月'), ('December', '十二月')], string='选择月份') - def confirm(self): + def confirm(self,next_date=False): month_names = { 'January': 1, 'February': 2, 'March': 3, 'April': 4, 'May': 5, 'June': 6, 'July': 7, 'August': 8, 'September': 9, 'October': 10, 'November': 11, 'December': 12 } - + current_month = datetime.now().month + current_year = datetime.now().year selected_month = month_names.get(self.select_time) year = datetime.now().year - start_date = datetime(year, selected_month, 1) + if not next_date: + start_date = datetime(year, selected_month, 1) + # 计算结束日期(下个月的第一天) + next_month = (selected_month % 12) + 1 + next_year = year + (1 if next_month == 1 else 0) # 如果是12月,年份加1 + end_date = datetime(next_year, next_month, 1) + else: + next_month = (current_month % 12) + 1 + next_year = current_year + (1 if next_month == 1 else 0) + start_date = datetime(next_year, next_month, 1) # Next month's first day + next_next_month = (next_month % 12) + 1 + next_next_year = next_year + (1 if next_next_month == 1 else 0) + end_date = datetime(next_next_year, next_next_month, 1) - # 计算结束日期(下个月的第一天) - next_month = (selected_month % 12) + 1 - next_year = year + (1 if next_month == 1 else 0) # 如果是12月,年份加1 - end_date = datetime(next_year, next_month, 1) role_a = self.env['planning.role'].search([('name', '=', '保安部')], limit=1) role_template_a = self.env['planning.slot.template'].search([('planning_name', '=', '白班'), ('role_id', '=', role_a.id)]) role_template_b = self.env['planning.slot.template'].search([('planning_name', '=', '中班'), ('role_id', '=', role_a.id)]) @@ -142,6 +151,9 @@ class YuthonShiftPlanning(models.Model): 'allocated_hours':8, }) + def shift_next_planing(self): + self.confirm(next_date=True) + class YuthonShiftPlanningALine(models.Model): _name = 'yuthon.shift.planning.a.line' _description = '排班安排A组' diff --git a/yuthon_hr_attendance/views/yuthon_duty_plan_views.xml b/yuthon_hr_attendance/views/yuthon_duty_plan_views.xml index 88172beba..6118fedeb 100644 --- a/yuthon_hr_attendance/views/yuthon_duty_plan_views.xml +++ b/yuthon_hr_attendance/views/yuthon_duty_plan_views.xml @@ -19,6 +19,7 @@
diff --git a/yuthon_hr_attendance/views/yuthon_run_planning_views.xml b/yuthon_hr_attendance/views/yuthon_run_planning_views.xml index 616de0269..8f16f78e5 100644 --- a/yuthon_hr_attendance/views/yuthon_run_planning_views.xml +++ b/yuthon_hr_attendance/views/yuthon_run_planning_views.xml @@ -19,6 +19,7 @@
@@ -68,6 +69,7 @@
@@ -107,6 +109,7 @@
diff --git a/yuthon_hr_attendance/views/yuthon_shift_planning_views.xml b/yuthon_hr_attendance/views/yuthon_shift_planning_views.xml index e94fae23d..7269beeb5 100644 --- a/yuthon_hr_attendance/views/yuthon_shift_planning_views.xml +++ b/yuthon_hr_attendance/views/yuthon_shift_planning_views.xml @@ -19,6 +19,7 @@