diff --git a/yuthon_holiday/models/inherit_hr_leave.py b/yuthon_holiday/models/inherit_hr_leave.py
index 699c004e4..bd5aa2b34 100644
--- a/yuthon_holiday/models/inherit_hr_leave.py
+++ b/yuthon_holiday/models/inherit_hr_leave.py
@@ -144,18 +144,24 @@ class HolidaysRequestBatch(models.Model):
self.leave_ids.action_validate()
self.hour_leave_ids.action_validate()
- # @api.onchange('leave_line_ids')
- # def _onchange_name(self):
- # if self.leave_line_ids:
- # for leave in self.leave_line_ids:
- # employee_name = leave.employee_id.name
- # leave_types = [leave.leave_type_id.name]
- # if leave.leave_type_id.name:
- # self.name = f"{employee_name}的{'、'.join(leave_types)}"
- # else:
- # self.name = f"{employee_name}的休假"
- # else:
- # self.name = '休假'
+ @api.onchange('leave_ids', 'hour_leave_ids')
+ def _onchange_name(self):
+ employee_name = self.users_id.name
+ if self.leave_ids or self.hour_leave_ids:
+ leave_types = []
+ for leave in self.leave_ids:
+ if leave.number_of_days_display:
+ leave_types.append(f"{leave.holiday_status_id.name}({leave.number_of_days_display}天)")
+ else:
+ leave_types.append(f"{leave.holiday_status_id.name}")
+ for leave in self.hour_leave_ids:
+ if leave.number_of_hours_display:
+ leave_types.append(f"{leave.holiday_status_id.name}({leave.number_of_hours_text})")
+ else:
+ leave_types.append(f"{leave.holiday_status_id.name}")
+ self.name = f"{employee_name}的{'、'.join(leave_types)}"
+ else:
+ self.name = f'{employee_name}的休假'
class HrLeaveLine(models.Model):
diff --git a/yuthon_hr_attendance/__manifest__.py b/yuthon_hr_attendance/__manifest__.py
index d3635ed8e..440d4f17b 100644
--- a/yuthon_hr_attendance/__manifest__.py
+++ b/yuthon_hr_attendance/__manifest__.py
@@ -44,6 +44,7 @@
'views/yuthon_shift_approval_views.xml',
'views/plan_views.xml',
'views/card_remind_form.xml',
+ 'views/yuthon_customer_planning_views.xml',
'views/all_attendance_menu.xml',
],
diff --git a/yuthon_hr_attendance/models/__init__.py b/yuthon_hr_attendance/models/__init__.py
index 214d80596..1cd4aa8ae 100644
--- a/yuthon_hr_attendance/models/__init__.py
+++ b/yuthon_hr_attendance/models/__init__.py
@@ -21,6 +21,7 @@ from . import yuthon_abnormal_approval
from . import yuthon_abnormal_setting
from . import yuthon_shift_approval
from . import yuthon_special_approval
+from . import yuthon_customer_planning
diff --git a/yuthon_hr_attendance/models/yuthon_customer_planning.py b/yuthon_hr_attendance/models/yuthon_customer_planning.py
new file mode 100644
index 000000000..7d48c6b24
--- /dev/null
+++ b/yuthon_hr_attendance/models/yuthon_customer_planning.py
@@ -0,0 +1,80 @@
+from odoo import api, fields, models, tools, _
+from datetime import datetime, timedelta ,time
+from odoo.exceptions import UserError
+
+
+class YuthonCustomerPlanning(models.Model):
+ _name = 'yuthon.customer.planning'
+ _description = '客户排班计划'
+
+ name = fields.Char(string='计划名称', required=True)
+ start_index_time = fields.Date(string='生效时间', default=fields.Date.today())
+ end_index_time = fields.Date(string='失效时间')
+ is_enable = fields.Boolean(string="启用", default=True)
+ plan_line_ids = fields.One2many('customer.plan.line', 'customer_plan_id', string='关联计划明细')
+ notice = fields.Text(string='计划说明')
+ select_time = fields.Selection([('1', '一月'), ('2', '二月'), ('3', '三月'), ('4', '四月'),
+ ('5', '五月'), ('6', '六月'), ('7', '七月'), ('8', '八月'),
+ ('9', '九月'), ('10', '十月'), ('11', '十一月'),
+ ('12', '十二月')], string='选择月份')
+
+ def auto_customer_plan(self, next_date=False):
+ selected_month = int(self.select_time)
+ year = datetime.now().year
+ 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 = (selected_month % 12) + 1
+ next_year = year + (1 if next_month == 1 else 0)
+ start_date = datetime(next_year, next_month, 1)
+ 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)
+
+ 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)])
+ current_date = start_date
+ while current_date <= end_date:
+ day_of_week = current_date.weekday()
+ if day_of_week < 6:
+ if day_of_week < 5:
+ for employee in self.plan_line_ids:
+ self.create_planning_slot(employee, role_a, role_template_a, current_date)
+ elif day_of_week == 5:
+ current_employee = self.plan_line_ids[current_date.day % len(self.plan_line_ids)]
+ self.create_planning_slot(current_employee, role_a, role_template_b, current_date)
+ current_date += timedelta(days=1)
+
+ def customer_next_plan(self):
+ self.auto_customer_plan(next_date=True)
+
+ def create_planning_slot(self, record, role, role_template, current_date):
+ start_hour = int(role_template.start_time)
+ end_hour = int(role_template.end_time)
+ current_datetime = datetime.combine(current_date, time(0, 0, 0))
+ start_time = current_datetime.replace(hour=start_hour) + timedelta(hours=16) - timedelta(days=1)
+ if role_template.end_time < role_template.start_time:
+ end_time = current_datetime.replace(hour=end_hour) + timedelta(days=1, hours=16) - timedelta(days=1)
+ else:
+ end_time = current_datetime.replace(hour=end_hour) + timedelta(hours=16) - timedelta(days=1)
+ self.env['planning.slot'].create({
+ 'resource_id': record.employee_id.resource_id.id,
+ 'template_id': role_template.id,
+ 'role_id': role.id,
+ 'start_datetime': start_time,
+ 'end_datetime': end_time,
+ 'allocated_hours': 8,
+ })
+
+class CustomerPlanLine(models.Model):
+ _name = 'customer.plan.line'
+ _description = '客户排班计划明细'
+
+ sequence = fields.Char(string='序号', store=True)
+ customer_plan_id = fields.Many2one('yuthon.customer.planning', string='关联计划名称')
+ employee_id = fields.Many2one('hr.employee', string='值班人员')
diff --git a/yuthon_hr_attendance/models/yuthon_duty_plan.py b/yuthon_hr_attendance/models/yuthon_duty_plan.py
index 8ed990c3c..d0fb862fb 100644
--- a/yuthon_hr_attendance/models/yuthon_duty_plan.py
+++ b/yuthon_hr_attendance/models/yuthon_duty_plan.py
@@ -15,10 +15,10 @@ class YuthonDutyPlan(models.Model):
plan_line_ids = fields.One2many('duty.plan.line', 'duty_plan_id', string='关联计划明细')
white_line_ids = fields.One2many('white.plan.line', 'duty_plan_id', string='关联计划明细')
notice = fields.Text(string='计划说明')
- select_time = fields.Selection([('January', '一月'), ('February', '二月'), ('March', '三月'), ('April', '四月'),
- ('May', '五月'), ('June', '六月'), ('July', '七月'), ('August', '八月'),
- ('September', '九月'), ('October', '十月'), ('November', '十一月'),
- ('December', '十二月')], string='选择月份')
+ select_time = fields.Selection([('1', '一月'), ('2', '二月'), ('3', '三月'), ('4', '四月'),
+ ('5', '五月'), ('6', '六月'), ('7', '七月'), ('8', '八月'),
+ ('9', '九月'), ('10', '十月'), ('11', '十一月'),
+ ('12', '十二月')], string='选择月份')
# default = lambda self: self._default_month()
# @api.model
# def _default_month(self):
@@ -26,14 +26,7 @@ class YuthonDutyPlan(models.Model):
# return current_month
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)
+ selected_month = int(self.select_time)
year = datetime.now().year
if not next_date:
first_day_of_month = datetime(year, selected_month, 1)
@@ -42,12 +35,13 @@ class YuthonDutyPlan(models.Model):
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_month = (selected_month % 12) + 1
+ next_year = year + (1 if next_month == 1 else 0)
+ first_day_of_month = datetime(next_year, next_month, 1)
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)])
@@ -100,7 +94,6 @@ class YuthonDutyPlan(models.Model):
if week == 5 or week == 6:
i.sudo().unlink()
-
other_data = {}
for other in self.white_line_ids:
if other.employee_id:
diff --git a/yuthon_hr_attendance/models/yuthon_run_planning.py b/yuthon_hr_attendance/models/yuthon_run_planning.py
index 81cb0bd17..5ed3c714e 100644
--- a/yuthon_hr_attendance/models/yuthon_run_planning.py
+++ b/yuthon_hr_attendance/models/yuthon_run_planning.py
@@ -15,21 +15,13 @@ class YuthonRunPlanning(models.Model):
all_run_ids = fields.One2many('yuthon.all.run.line', 'engineering_planning_id', string='关联综合部排班明细')
other_run_ids = fields.One2many('yuthon.other.line', 'engineering_planning_id', string='关联其他明细')
department_id = fields.Many2one("hr.department", string="部门", required=True)
- select_time = fields.Selection([('January', '一月'), ('February', '二月'), ('March', '三月'), ('April', '四月'),
- ('May', '五月'), ('June', '六月'), ('July', '七月'), ('August', '八月'),
- ('September', '九月'), ('October', '十月'), ('November', '十一月'),
- ('December', '十二月')], string='选择月份')
-
+ select_time = fields.Selection([('1', '一月'), ('2', '二月'), ('3', '三月'), ('4', '四月'),
+ ('5', '五月'), ('6', '六月'), ('7', '七月'), ('8', '八月'),
+ ('9', '九月'), ('10', '十月'), ('11', '十一月'),
+ ('12', '十二月')], string='选择月份')
# 运行班
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)
+ selected_month = int(self.select_time)
year = datetime.now().year
if not next_date:
first_day_of_month = datetime(year, selected_month, 1)
@@ -38,12 +30,13 @@ class YuthonRunPlanning(models.Model):
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_month = (selected_month % 12) + 1
+ next_year = year + (1 if next_month == 1 else 0)
+ first_day_of_month = datetime(next_year, next_month, 1)
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)
@@ -128,14 +121,7 @@ class YuthonRunPlanning(models.Model):
}
# 高压班
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)
+ selected_month = int(self.select_time)
year = datetime.now().year
if not next_date:
first_day_of_month = datetime(year, selected_month, 1)
@@ -144,9 +130,9 @@ class YuthonRunPlanning(models.Model):
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_month = (selected_month % 12) + 1
+ next_year = year + (1 if next_month == 1 else 0)
+ first_day_of_month = datetime(next_year, next_month, 1)
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)
@@ -212,14 +198,7 @@ class YuthonRunPlanning(models.Model):
}
# 综合班
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)
+ selected_month = int(self.select_time)
year = datetime.now().year
if not next_date:
first_day_of_month = datetime(year, selected_month, 1)
@@ -228,9 +207,9 @@ class YuthonRunPlanning(models.Model):
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_month = (selected_month % 12) + 1
+ next_year = year + (1 if next_month == 1 else 0)
+ first_day_of_month = datetime(next_year, next_month, 1)
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)
diff --git a/yuthon_hr_attendance/models/yuthon_shift_planning.py b/yuthon_hr_attendance/models/yuthon_shift_planning.py
index a24cc292d..95ce364c7 100644
--- a/yuthon_hr_attendance/models/yuthon_shift_planning.py
+++ b/yuthon_hr_attendance/models/yuthon_shift_planning.py
@@ -14,20 +14,13 @@ class YuthonShiftPlanning(models.Model):
planning_c_ids = fields.One2many('yuthon.shift.planning.c.line', 'shift_planning_id', string='关联C组')
planning_ever_white_ids = fields.One2many('yuthon.shift.ever.white.line', 'shift_planning_id', string='关联常白班')
planning_ever_noon_ids = fields.One2many('yuthon.shift.ever.noon.line', 'shift_planning_id', string='关联常中班')
- select_time = fields.Selection([('January', '一月'), ('February', '二月'), ('March', '三月'), ('April', '四月'),
- ('May', '五月'), ('June', '六月'), ('July', '七月'), ('August', '八月'),
- ('September', '九月'), ('October', '十月'), ('November', '十一月'),
- ('December', '十二月')], string='选择月份')
+ select_time = fields.Selection([('1', '一月'), ('2', '二月'), ('3', '三月'), ('4', '四月'),
+ ('5', '五月'), ('6', '六月'), ('7', '七月'), ('8', '八月'),
+ ('9', '九月'), ('10', '十月'), ('11', '十一月'),
+ ('12', '十二月')], string='选择月份', default=lambda self: self._get_default_month())
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)
+ selected_month = int(self.select_time)
year = datetime.now().year
if not next_date:
start_date = datetime(year, selected_month, 1)
@@ -36,9 +29,9 @@ class YuthonShiftPlanning(models.Model):
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_month = (selected_month % 12) + 1
+ next_year = year + (1 if next_month == 1 else 0)
+ start_date = datetime(next_year, next_month, 1)
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)
@@ -166,6 +159,10 @@ class YuthonShiftPlanning(models.Model):
for data in white_data:
record.planning_ever_noon_ids = [(0, 0, data)]
+ def _get_default_month(self):
+ current_month = datetime.now().month
+ return str(current_month) # 返回字符串类型的月份
+
class YuthonShiftPlanningALine(models.Model):
_name = 'yuthon.shift.planning.a.line'
_description = '排班安排A组'
diff --git a/yuthon_hr_attendance/security/ir.model.access.csv b/yuthon_hr_attendance/security/ir.model.access.csv
index 99aeafbf3..e88f13794 100644
--- a/yuthon_hr_attendance/security/ir.model.access.csv
+++ b/yuthon_hr_attendance/security/ir.model.access.csv
@@ -32,4 +32,6 @@ access_yuthon_abnormal_approval,yuthon.abnormal.approval,model_yuthon_abnormal_a
access_yuthon_abnormal_setting,yuthon.abnormal.setting,model_yuthon_abnormal_setting,base.group_user,1,1,1,1
access_yuthon_shift_approval,yuthon.shift.approval,model_yuthon_shift_approval,base.group_user,1,1,1,1
access_yuthon_special_approval,yuthon.special.approval,model_yuthon_special_approval,base.group_user,1,1,1,1
-access_card_remind_form,card.remind.form,model_card_remind_form,base.group_user,1,1,1,1
\ No newline at end of file
+access_card_remind_form,card.remind.form,model_card_remind_form,base.group_user,1,1,1,1
+access_yuthon_customer_planning,yuthon.customer.planning,model_yuthon_customer_planning,base.group_user,1,1,1,1
+access_customer_plan_line,customer.plan.line,model_customer_plan_line,base.group_user,1,1,1,1
\ No newline at end of file
diff --git a/yuthon_hr_attendance/views/hr_attendance_views.xml b/yuthon_hr_attendance/views/hr_attendance_views.xml
index 0f0ffe6c7..0db0c285c 100644
--- a/yuthon_hr_attendance/views/hr_attendance_views.xml
+++ b/yuthon_hr_attendance/views/hr_attendance_views.xml
@@ -126,6 +126,38 @@
+
+