添加功能
This commit is contained in:
@@ -62,47 +62,26 @@ class HrAttendance(models.Model):
|
||||
record.is_late_card = False
|
||||
record.is_early_card = False
|
||||
if not record.employee_id.resource_id.calendar_id.attendance_ids:
|
||||
department_ids = self.env['hr.department'].search([('name', 'in', ['保安部', '班组A', '班组B', '班组C'])]).ids
|
||||
employee_ids = list(set(self.env['hr.attendance'].search([
|
||||
('employee_id.department_id', 'in', department_ids)
|
||||
]).mapped('employee_id').ids))
|
||||
for employee_id in self.env['hr.employee'].browse(employee_ids):
|
||||
department_names = ['保安部', '班组A', '班组B', '班组C', '工程部', '运行班', '高压班', '综合班']
|
||||
department_ids = self.env['hr.department'].search([('name', 'in', department_names)]).ids
|
||||
employee_ids = self.env['hr.employee'].search([('department_id', 'in', department_ids)])
|
||||
for employee_id in employee_ids:
|
||||
planning_ids = self.env['planning.slot'].search([('resource_id', '=', employee_id.resource_id.id)])
|
||||
for planning_id in planning_ids:
|
||||
start_date = planning_id.start_datetime.date()
|
||||
attendance_id = self.env['hr.attendance'].search([('employee_id', '=', employee_id.id),
|
||||
('current_data', '=', start_date)])
|
||||
attendance_id = self.env['hr.attendance'].search(
|
||||
[('employee_id', '=', employee_id.id), ('current_data', '=', start_date)])
|
||||
if attendance_id:
|
||||
if attendance_id.check_in:
|
||||
if attendance_id.check_in > planning_id.start_datetime:
|
||||
attendance_id.write({'is_early_card': True})
|
||||
check_in = record.check_in + timedelta(hours=8)
|
||||
attendance_id.is_late_card = check_in > planning_id.start_datetime
|
||||
else:
|
||||
attendance_id.write({'is_no_card': True})
|
||||
attendance_id.is_no_card = True
|
||||
if attendance_id.check_out:
|
||||
if attendance_id.check_out < planning_id.end_datetime:
|
||||
attendance_id.write({'is_late_card': True})
|
||||
check_in = record.check_in + timedelta(hours=8)
|
||||
attendance_id.is_early_card = planning_id.end_datetime > check_in
|
||||
else:
|
||||
attendance_id.write({'is_no_card': True})
|
||||
department_ids = self.env['hr.department'].search([('name', 'in',['工程部', '运行班', '高压班','综合班'])]).ids
|
||||
employee_ids = list(set(self.env['hr.attendance'].search([('employee_id.department_id', 'in', department_ids)
|
||||
]).mapped('employee_id').ids))
|
||||
for employee_id in self.env['hr.employee'].browse(employee_ids):
|
||||
planning_ids = self.env['planning.slot'].search([('resource_id', '=', employee_id.resource_id.id)])
|
||||
for planning_id in planning_ids:
|
||||
start_date = planning_id.start_datetime.date()
|
||||
attendance_id = self.env['hr.attendance'].search([('employee_id', '=', employee_id.id),
|
||||
('current_data', '=', start_date)])
|
||||
if attendance_id:
|
||||
if attendance_id.check_in:
|
||||
if attendance_id.check_in > planning_id.start_datetime:
|
||||
attendance_id.write({'is_early_card': True})
|
||||
else:
|
||||
attendance_id.write({'is_no_card': True})
|
||||
if attendance_id.check_out:
|
||||
if attendance_id.check_out < planning_id.end_datetime:
|
||||
attendance_id.write({'is_late_card': True})
|
||||
else:
|
||||
attendance_id.write({'is_no_card': True})
|
||||
attendance_id.is_no_card = True
|
||||
else:
|
||||
min_hour_from = record.employee_id.resource_id.calendar_id.attendance_ids[0].hour_from
|
||||
min_hour = int(min_hour_from)
|
||||
@@ -122,6 +101,14 @@ class HrAttendance(models.Model):
|
||||
record.is_early_card = will_datetime_end > check_out
|
||||
else:
|
||||
record.is_no_card = True
|
||||
if record.employee_id in record.employee_id.resource_id.calendar_id.resource_user_ids:
|
||||
if record.check_in or record.check_out:
|
||||
record.write({
|
||||
'is_abnormal': False,
|
||||
'is_late_card': False,
|
||||
'is_early_card': False,
|
||||
'is_no_card': False
|
||||
})
|
||||
|
||||
def add_comment(self):
|
||||
self.ensure_one()
|
||||
@@ -352,20 +339,5 @@ class HrAttendance(models.Model):
|
||||
self.card_in_comment(resource.employee_id)
|
||||
elif datetime.now() >= today_slots_id.end_datetime+timedelta(hours=8):
|
||||
self.card_out_comment(resource.employee_id)
|
||||
def button_correct_approval(self):
|
||||
for record in self:
|
||||
year = record.current_data.year
|
||||
month = record.current_data.month
|
||||
day = record.current_data.day
|
||||
current_date = datetime.today()
|
||||
min_hour_from = record.employee_id.resource_id.calendar_id.attendance_ids[0].hour_from
|
||||
min_hour = int(min_hour_from)
|
||||
min_minute = int(min_hour_from * 10 % min_hour_from)
|
||||
will_datetime_start = current_date.replace(year=year, month=month, day=day, hour=min_hour, minute=min_minute) - timedelta(hours=8)
|
||||
record.write({'check_in': will_datetime_start, 'is_approval': True})
|
||||
max_hour_to = record.employee_id.resource_id.calendar_id.attendance_ids[-1].hour_to
|
||||
max_hour = int(max_hour_to)
|
||||
max_minute = int(max_hour_to * 10 % max_hour_to)
|
||||
will_datetime_end = current_date.replace(year=year, month=month, day=day, hour=max_hour, minute=max_minute) - timedelta(hours=8)
|
||||
record.write({'check_out': will_datetime_end, 'is_approval': True})
|
||||
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ class YuthonRunPlanning(models.Model):
|
||||
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)
|
||||
for employee in self.engineering_run_ids:
|
||||
for employee in self.engineering_run_ids.sorted('sequence'):
|
||||
current_date = first_day_of_month
|
||||
while current_date <= last_day_of_month:
|
||||
resource_id = employee.employee_id.resource_id
|
||||
@@ -76,7 +76,7 @@ class YuthonRunPlanning(models.Model):
|
||||
other_resource_id = other.employee_id.resource_id
|
||||
regular_holiday = other.regular_holidays
|
||||
weekday_mapping = {
|
||||
'one': 7, 'two': 1, 'three': 2, 'four': 3, 'five': 4, 'six': 5, 'seven': 6
|
||||
'one': 7, 'two': 1, 'three':2, 'four': 3, 'five': 4, 'six': 5, 'seven': 6
|
||||
}
|
||||
weekday_number = weekday_mapping.get(regular_holiday)
|
||||
other_data[other_resource_id.id] = weekday_number
|
||||
|
||||
Reference in New Issue
Block a user