添加功能
This commit is contained in:
@@ -221,9 +221,84 @@ class HrAttendance(models.Model):
|
||||
|
||||
def missing_card_judgment(self):
|
||||
today = fields.Date.today()
|
||||
attend_records = self.env['hr.attendance'].search(['current_data', '=', today])
|
||||
for record in attend_records:
|
||||
record.is_no_card = not record.check_in or not record.check_out
|
||||
employee_list = []
|
||||
role_ids = self.env['planning.role'].search([
|
||||
('name', 'not in', ['厨卫(集团)', '项目运营岗'])
|
||||
])
|
||||
for role in role_ids:
|
||||
for resource_id in role.resource_ids:
|
||||
if resource_id.employee_id.id not in employee_list:
|
||||
employee_list.append(resource_id.employee_id.id)
|
||||
attend_records = self.env['hr.attendance'].search([
|
||||
('current_data', '=', today),
|
||||
('employee_id', 'not in', employee_list)
|
||||
])
|
||||
all_employees = self.env['hr.employee'].search([
|
||||
('id', 'not in', employee_list)
|
||||
])
|
||||
|
||||
# 判断是否为工作日
|
||||
is_workday = self._process_shift_days(today)
|
||||
for employee in all_employees:
|
||||
# 查找该员工当天的考勤记录
|
||||
employee_record = attend_records.filtered(
|
||||
lambda r: r.employee_id.id == employee.id
|
||||
)
|
||||
|
||||
# 工作日打卡情况判断
|
||||
if is_workday:
|
||||
if employee_record:
|
||||
is_no_card = not employee_record.check_in or not employee_record.check_out
|
||||
else:
|
||||
is_no_card = True
|
||||
else:
|
||||
is_no_card = False
|
||||
|
||||
if employee_record:
|
||||
# 更新现有记录的缺卡状态
|
||||
employee_record.write({'is_no_card': is_no_card})
|
||||
else:
|
||||
# 没有记录且需要标记为缺卡时,创建新记录
|
||||
self.env['hr.attendance'].create({
|
||||
'employee_id': employee.id,
|
||||
'current_data': today,
|
||||
'is_no_card': is_no_card,
|
||||
'check_in': False,
|
||||
'check_out': False
|
||||
})
|
||||
|
||||
def _process_shift_days(self, current_data):
|
||||
"""
|
||||
判断是否是工作日 调休日 双休
|
||||
"""
|
||||
calendar_leaves = self.env['resource.calendar.leaves'].search([("calendar_id", "=", "行政考勤工作日")])
|
||||
holidays_list = []
|
||||
shift_days_list = []
|
||||
# 提取节假日和调休日
|
||||
for leave in calendar_leaves:
|
||||
if leave.holidays:
|
||||
holidays_list.extend(leave.holidays.split(','))
|
||||
if leave.alternate_rest_day:
|
||||
holidays_list.extend(leave.alternate_rest_day.split(','))
|
||||
if leave.shift_replacement_day:
|
||||
shift_days_list.extend(leave.shift_replacement_day.split(','))
|
||||
|
||||
holidays_list = [self.remove_leading_zero(date) for date in holidays_list]
|
||||
shift_days_list = [self.remove_leading_zero(date) for date in shift_days_list]
|
||||
|
||||
if (current_data in holidays_list) or (current_data.weekday() in [5, 6]):
|
||||
return False
|
||||
elif current_data in shift_days_list:
|
||||
return True
|
||||
else:
|
||||
return True
|
||||
|
||||
def remove_leading_zero(self, date_str):
|
||||
month, day = date_str.split('月')
|
||||
month = month.lstrip('0')
|
||||
day = day.rstrip('日')
|
||||
day = day.lstrip('0')
|
||||
return f'{month}月{day}日'
|
||||
|
||||
@api.depends('employee_id', 'check_in', 'check_out')
|
||||
def _compute_display_name(self):
|
||||
|
||||
@@ -350,7 +350,7 @@ class HrAttendanceDetail(models.Model):
|
||||
employee_list.append(resource_id.employee_id.id)
|
||||
if employee.id not in employee_list:
|
||||
# 判断是否工作日
|
||||
if not self._process_shift_days(current_data):
|
||||
if self._process_shift_days(current_data):
|
||||
return is_early_card, is_late_card, is_abnormal, is_warning, absenteeism_card
|
||||
|
||||
# 迟到判断
|
||||
@@ -365,6 +365,7 @@ class HrAttendanceDetail(models.Model):
|
||||
# 迟到超过60分钟标记为旷工
|
||||
if late_delta > 60:
|
||||
absenteeism_card = True
|
||||
|
||||
# 早退判断
|
||||
if check_out and end_datetime and check_out < end_datetime:
|
||||
is_early_card = True
|
||||
|
||||
@@ -79,7 +79,7 @@
|
||||
<field name="department_ids" widget="many2many_tags" context="{'tree_view_ref':'yuthon_notice.view_yuthon_cs_tree'}" domain = "[('company_id', '=', company_id)] if is_this_company else []"/>
|
||||
</group>
|
||||
<group>
|
||||
<field name="users_role_group_ids" widget="many2many_tags"/>
|
||||
<field name="users_role_group_ids" widget="many2many_tags" domain = "[('company_id', '=', company_id)] if is_this_company else []"/>
|
||||
</group>
|
||||
<group>
|
||||
<field name="users_role_ids" widget="many2many_tags" domain = "[('company_id', '=', company_id)] if is_this_company else []"/>
|
||||
|
||||
Reference in New Issue
Block a user