计算字段逻辑代码如下:
起算日
x_employee_id
for record in self:
if record.x_employee_id.hire_date:
if record.x_employee_id.hire_date.day<15:
record['x_startdate_efficientcy'] = record.x_employee_id.hire_date.replace(day=1)
else:
record['x_startdate_efficientcy'] = record.x_employee_id.hire_date.replace(day=1).replace(month=record.x_employee_id.hire_date.month+1)
未参与项目天数
x_startdate_project
for record in self:
if record.x_startdate_project:
time_config = self.env['employee.time.config'].search([('employee_id','=',record.x_employee_id.id)])
work_calendar = time_config.work_calendar_id
cal_dic = {}
for line in work_calendar.work_calendar_lines:
if int(line.year) == record.x_startdate_project.year:
cal_dic[line.day.strftime('%Y-%m-%d')] = line.day_type
if record.x_startdate_project.month==int(record.x_hr_month[4:]) and record.x_startdate_project.year==int(record.x_hr_month[0:4]):
count_days = record.x_startdate_project.day - 1
for the_day in range(count_days):
cal_date = record.x_startdate_project.replace(day=the_day+1)
if cal_dic.get(cal_date.strftime('%Y-%m-%d'), False) == 'holiday':
count_days -= 1
if cal_date.weekday()>=5 and cal_dic.get(cal_date.strftime('%Y-%m-%d'), 'holiday') == 'holiday':
count_days -= 1
else:
count_days=0
record['x_days_withoutproject'] = count_days
判断值
x_employeegrade,x_startdate_efficientcy,x_hr_month
for record in self:
year_diff = int(record.x_hr_month[0:4]) - record.x_startdate_efficientcy.year
month_diff = int(record.x_hr_month[4:]) - record.x_startdate_efficientcy.month
x_month = year_diff*12 + month_diff + 1
if record.x_employeegrade == 'G1':
record['x_person_efficiency'] = 0
elif record.x_employeegrade == 'G5':
record['x_person_efficiency'] = 1
elif record.x_employeegrade == 'G2':
if x_month<2:
record['x_person_efficiency'] = 0
elif 2<=x_month<=3:
record['x_person_efficiency'] = 0.25
elif 4<=x_month<=6:
record['x_person_efficiency'] = 0.5
elif x_month==7:
record['x_person_efficiency'] = 1
elif record.x_employeegrade == 'G3':
if x_month<2:
record['x_person_efficiency'] = 0
elif 2<=x_month<=3:
record['x_person_efficiency'] = 0.5
elif 4<=x_month:
record['x_person_efficiency'] = 1
elif record.x_employeegrade == 'G4':
if x_month<2:
record['x_person_efficiency'] = 0.5
elif 2<=x_month:
record['x_person_efficiency'] = 1
实际天数
x_work_days,x_days_withoutproject,x_days_deduction,x_days_absence,x_days_leave
for record in self:
record['x_days_workinproject'] = record.x_work_days - record.x_days_withoutproject - record.x_days_deduction - record.x_days_absence - record.x_days_leave
实际人力
x_days_workinproject,x_person_efficiency,x_work_days
for record in self:
record['x_rate_efficientcy'] = round(float(record.x_days_workinproject)*float(record.x_person_efficiency)/float(record.x_work_days),3)