上传的图像用于项目: 'CST技术支持'
  1. CST技术支持
  2. SLAL2-1605

Pro 【夏尔天逸】涉及计算字段的自定义模型

XMLWord打印

    • Icon: 任务 任务
    • 解决结果: 完成
    • Icon: High High
    • 202101
    • X-成都夏尔-Y2020042
    • xiaertest
    • 基础通用功能
    • 隐藏

      计算字段逻辑代码如下:
      起算日
      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)

      显示
      计算字段逻辑代码如下: 起算日 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)

      自定义模型包含逻辑和计算字段,字段定义如下:
      1.员工
      2.人力月份:手动输入,格式yyyyMM
      3.起算日:计算,1. 入职日期<15日,则等于入职当月初;2. 入职日期>15日,则等于入职下月初;3. =15日,业务上规避入职
      4.当月工作日:手动输入,数字
      5.制作项目开始时间:手动输入,格式yyyyMMdd
      6.未参与项目天数:计算项,根据【制作项目开始时间】计算未参与时间,排除节假日和周末
      7.人力职级:selection,导入,岗前/实习/试用初级及以下/试用中级及以上/正式
      8.判断值:计算项,见附件图
      ​9.人天扣减:手动输入,数字
      ​10.缺勤天数:手动输入,数字
      11​.请假天数:手动输入,数字
      ​12.实际天数:计算项,=当月工作日-未参与项目天数-人天扣减-​缺勤天数-请假天数
      13​.实际人力:计算项,= (实际天数*判断值)/当月工作日

        1. 11.png
          11.png
          71 kB
        2. 2222.png
          2222.png
          80 kB
        3. 3333.png
          3333.png
          41 kB

            grant.yang 杨光磊
            luoj 罗军
            表决:
            0 为这个问题表决

              创建日期:
              已更新:
              已解决: