From b450bcff806b686d3643a9c9dfd95c47b6d283bf Mon Sep 17 00:00:00 2001
From: zhouzhou <123@qq.com>
Date: Tue, 17 Dec 2024 10:51:19 +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
---
yuthon_hr_attendance/models/hr_attendance.py | 22 +++++++++++++++++--
.../models/yuthon_shift_planning.py | 21 +++++++++++++++---
.../views/hr_attendance_views.xml | 6 ++---
.../views/yuthon_shift_planning_views.xml | 1 +
4 files changed, 42 insertions(+), 8 deletions(-)
diff --git a/yuthon_hr_attendance/models/hr_attendance.py b/yuthon_hr_attendance/models/hr_attendance.py
index 5dc655b71..f52c1281f 100644
--- a/yuthon_hr_attendance/models/hr_attendance.py
+++ b/yuthon_hr_attendance/models/hr_attendance.py
@@ -31,7 +31,8 @@ class HrAttendance(models.Model):
('four', '星期四'), ('five', '星期五'), ('six', '星期六'),
('seven', '星期日')], string='星期', compute='_compute_week', store=True)
abnormal = fields.Integer(string="异常计算")
- shift = fields.Char(string="班次")
+ shift_id = fields.Many2one('planning.slot', string="班次", compute='compute_shift_id', store=True)
+ shift_name = fields.Char(string="班次", related="shift_id.template_id.planning_name")
noon_duty = fields.Datetime(string="中值")
night_duty = fields.Datetime(string="晚值")
is_approval = fields.Boolean(string="是否审批修正", default=False)
@@ -466,7 +467,7 @@ class HrAttendance(models.Model):
self.sudo().env["wecom.apps"].sync_send_message(category='att', user_id=employee_id.wecom_userid, message=data)
def card_out_comment(self, employee_id,planning_name):
- data = f"您的班次是{planning_name},您该下班时间,记得打卡"
+ data = f"您的班次是{planning_name},您该下班了,记得打卡"
self.sudo().env["wecom.apps"].sync_send_message(category='att', user_id=employee_id.wecom_userid, message=data)
self.sudo().env["wecom.apps"].sync_send_message(category='att', user_id='18562027762', message=data)
@@ -475,6 +476,23 @@ class HrAttendance(models.Model):
self.sudo().env["wecom.apps"].sync_send_message(category='att', user_id=employee_id.wecom_userid, message=data)
self.sudo().env["wecom.apps"].sync_send_message(category='att', user_id='18562027762', message=data)
+ @api.depends('employee_id')
+ def compute_shift_id(self):
+ target_departments = ['工程部', '保安部', '联安粮库']
+ departments = self.env['hr.department'].search([('name', 'in', target_departments)])
+ all_child_departments = self.env['hr.department'].search([('id', 'child_of', departments.ids)])
+ employees = self.env['hr.employee'].search([('department_id', 'in', all_child_departments.ids)])
+
+ for employee in employees:
+ planning_slots = self.env['planning.slot'].search([('resource_id', '=', employee.resource_id.id)])
+ for slot in planning_slots:
+ start_date = slot.start_datetime.date()
+ attendance = self.env['hr.attendance'].search([
+ ('employee_id', '=', employee.id),
+ ('current_data', '=', start_date)
+ ])
+ if attendance:
+ attendance.write({'shift_id': slot.shift_id.id})
class card_remind_form(models.Model):
_name = 'card.remind.form'
diff --git a/yuthon_hr_attendance/models/yuthon_shift_planning.py b/yuthon_hr_attendance/models/yuthon_shift_planning.py
index 9173e6bf7..97f5bc415 100644
--- a/yuthon_hr_attendance/models/yuthon_shift_planning.py
+++ b/yuthon_hr_attendance/models/yuthon_shift_planning.py
@@ -49,9 +49,9 @@ class YuthonShiftPlanning(models.Model):
role_template_c = self.env['planning.slot.template'].search([('planning_name', '=', '夜班'), ('role_id', '=', role_a.id)])
role = [role_template_a, role_template_b, role_template_c]
planning_groups = {
- 'planning_a_ids': range(len(role)), # 默认顺序: 早 -> 中 -> 夜
- 'planning_c_ids': [1, 2, 0], # 中 -> 夜 -> 早
- 'planning_b_ids': [2, 0, 1], # 夜 -> 早 -> 中
+ 'planning_a_ids': [0, 2, 1], # 早 -> 夜 -> 中
+ 'planning_b_ids': [2, 1, 0], # 夜 -> 中 -> 早
+ 'planning_c_ids': [1, 0, 2], # 中 -> 早 -> 夜
}
weekday_mapping = {
@@ -154,6 +154,21 @@ class YuthonShiftPlanning(models.Model):
def shift_next_planing(self):
self.confirm(next_date=True)
+ def exchange_button(self):
+ for record in self:
+ white_lines = record.planning_ever_white_ids
+ noon_lines = record.planning_ever_noon_ids
+ white_data = [{'employee_id': line.employee_id.id, 'sequence': line.sequence,
+ 'regular_holidays': line.regular_holidays} for line in white_lines]
+ noon_data = [{'employee_id': line.employee_id.id, 'sequence': line.sequence,
+ 'regular_holidays': line.regular_holidays} for line in noon_lines]
+ white_lines.unlink()
+ noon_lines.unlink()
+ for data in noon_data:
+ record.planning_ever_white_ids = [(0, 0, data)]
+ for data in white_data:
+ record.planning_ever_noon_ids = [(0, 0, data)]
+
class YuthonShiftPlanningALine(models.Model):
_name = 'yuthon.shift.planning.a.line'
_description = '排班安排A组'
diff --git a/yuthon_hr_attendance/views/hr_attendance_views.xml b/yuthon_hr_attendance/views/hr_attendance_views.xml
index bd270776c..49f8c7563 100644
--- a/yuthon_hr_attendance/views/hr_attendance_views.xml
+++ b/yuthon_hr_attendance/views/hr_attendance_views.xml
@@ -48,7 +48,7 @@
-
+
@@ -81,7 +81,7 @@
-
+
@@ -113,7 +113,7 @@
-
+
diff --git a/yuthon_hr_attendance/views/yuthon_shift_planning_views.xml b/yuthon_hr_attendance/views/yuthon_shift_planning_views.xml
index 8b1f3ad37..4646071dd 100644
--- a/yuthon_hr_attendance/views/yuthon_shift_planning_views.xml
+++ b/yuthon_hr_attendance/views/yuthon_shift_planning_views.xml
@@ -54,6 +54,7 @@
+