@@ -18,24 +18,32 @@ 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)])
|
||||
role_template_b = self.env['planning.slot.template'].search([('planning_name', '=', '白值'), ('role_id', '=', role_a.id)])
|
||||
current_date = first_day_of_month
|
||||
while current_date <= last_day_of_month:
|
||||
for line in self.plan_line_ids:
|
||||
@@ -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'
|
||||
|
||||
@@ -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 = '运行班计划明细'
|
||||
|
||||
@@ -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组'
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
<form string="排版规则">
|
||||
<header>
|
||||
<button name="auto_duty_plan" type="object" string="安排值班" class="oe_highlight"/>
|
||||
<button name="duty_next_plan" type="object" string="安排下个月值班" class="oe_highlight"/>
|
||||
</header>
|
||||
<sheet>
|
||||
<div class="oe_title">
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
<sheet>
|
||||
<header>
|
||||
<button name="run_confirm" type="object" string="排班" class="oe_highlight"/>
|
||||
<button name="run_next_planning" type="object" string="安排下个月排班" class="oe_highlight"/>
|
||||
</header>
|
||||
<group>
|
||||
<field name="name"/>
|
||||
@@ -68,6 +69,7 @@
|
||||
<sheet>
|
||||
<header>
|
||||
<button name="integrated_confirm" type="object" string='排班' class="oe_highlight"/>
|
||||
<button name="comprehensive_next_planning" type="object" string="安排下个月排班" class="oe_highlight"/>
|
||||
</header>
|
||||
<group>
|
||||
<field name="name"/>
|
||||
@@ -107,6 +109,7 @@
|
||||
<sheet>
|
||||
<header>
|
||||
<button name="high_confirm" type="object" string="排班" class="oe_highlight"/>
|
||||
<button name="high_next_planning" type="object" string="安排下个月排班" class="oe_highlight"/>
|
||||
</header>
|
||||
<group>
|
||||
<field name="name"/>
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
<sheet>
|
||||
<header>
|
||||
<button name="confirm" type="object" string="排班" class="oe_highlight"/>
|
||||
<button name="shift_next_planing" type="object" string="安排下个月排班" class="oe_highlight"/>
|
||||
</header>
|
||||
<group>
|
||||
<field name="name"/>
|
||||
|
||||
Reference in New Issue
Block a user