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

怪兽-帮忙写个按季度折算薪资档案的函数

XMLWord打印

    • Icon: Change Change
    • 解决结果: 完成
    • Icon: Block Block
    • 202010
    • Y-易路产品-
    • enmonster
    • 薪酬管理
    • 隐藏

      payslip_run_record_type = payslip_run_record.type
      unscheduled_type = ''

      unscheduled_info = {}
      if payslip_run_record_type == 'unscheduled':
      unscheduled_type = payslip_run_record.unscheduled_type
      for item in payslip_run_record.unscheduled_employee_ids:
      unscheduled_info[item.employee_id.id] =

      { 'date_start': item.start_date, 'date_end': item.end_date, }

      is_last_hire_employee_info = False
      if unscheduled_type == 'rehired':
      is_last_hire_employee_info = True

      payslip_start_date =payslip_run_record.payroll_period.date_start
      payslip_end_date =payslip_run_record.payroll_period.date_end
      if payslip_start_date[5:7] in ('01','02','03'):
      begin_date=str(payslip_start_date[0:5])+'01-01'
      end_date=str(payslip_start_date[0:5])+'03-31'
      elif payslip_start_date[5:7] in ('04','05','06'):
      begin_date=str(payslip_start_date[0:5])+'04-01'
      end_date=str(payslip_start_date[0:5])+'06-30'
      elif payslip_start_date[5:7] in ('07','08','09'):
      begin_date=str(payslip_start_date[0:5])+'07-01'
      end_date=str(payslip_start_date[0:5])+'09-30'
      elif payslip_start_date[5:7] in ('10','11','12'):
      begin_date=str(payslip_start_date[0:5])+'10-01'
      end_date=str(payslip_start_date[0:5])+'12-31'
      hr_payslip_parameters = preFuncParameterDict.get('F_ArchiveValueCal_Qua', [])
      value_dict = {}

      1. 从薪资参数中获取薪资档案实际值折算计算公式的参数
      2. code:薪资档案编码
        if hr_payslip_parameters:
        for hr_payslip_parameter in hr_payslip_parameters:
        parameters = eval(hr_payslip_parameter['func_args'])
        for parameter in parameters:
        if isinstance(parameter, tuple):
        value_dict.setdefault(tuple([eval(i) for i in parameter]), None)
        else:
        value_dict.setdefault((eval(parameter),), None)

      result = {}
      for args in value_dict.keys():
      code = args[0]
      if len(args) == 3:
      qua_type=args[2]
      else:
      qua_type=1
      employee_records = payslip_run_record.employee_ids
      date_dict = {}
      all_base_currency_amount_map = env['payroll.archive']._get_all_base_currency_amount(employee_ids=employee_records.ids, is_last_hire_employee_info=is_last_hire_employee_info)

      all_employee_payroll_archive_records = env['payroll.archive'].get_employee_archives(employee_records.ids, is_last_hire_employee_info=is_last_hire_employee_info,order=['effective_date'])

      for employee_record in employee_records:
      employee_id = employee_record.id

      1. if payslip_run_record_type == 'unscheduled':
      2. payslip_start_date = unscheduled_info.get(employee_id, {}).get('date_start')
      3. payslip_end_date = unscheduled_info.get(employee_id, {}).get('date_end')
        if employee_id not in employee_snapshot_dict:
        raise Exception('Lack of Employee Snapshot Data: %s' % employee_record.name)
      4. payroll_archive_records = employee_record.payroll_archive_ids
        payroll_archive_records = all_employee_payroll_archive_records.get(employee_id, {}) or {}
        employee_name = payroll_archive_records.pop('employee_name', '')

      result_list = []
      if payroll_archive_records:
      for payroll_archive_code, payroll_archive_record_ls in payroll_archive_records.items():
      length = len(payroll_archive_record_ls)
      for payroll_archive_record in payroll_archive_record_ls:
      effective_date = payroll_archive_record['effective_date']
      expired_date = payroll_archive_record['expired_date']

      1. 如果失效日期不存在,令其等于9999-12-31
        if not expired_date:
        expired_date = '9999-12-31'
      2. 判断薪资档案与薪资周期是否有交集
        if payroll_archive_record['code'] == code and \
        end_date >= effective_date and expired_date >= begin_date:
        date_list = [begin_date, end_date, expired_date, effective_date]
        date_list.sort()
        start_day = date_list[1]
        end_day = date_list[2]
        amount = all_base_currency_amount_map.get(payroll_archive_record['id']) or payroll_archive_record['amount']

      result_list.append(

      {'start_day': start_day, 'end_day': end_day, 'amount': amount}

      )
      result_list = sorted(result_list,key=lambda x:x['start_day'])
      if result_list:
      if qua_type == 1:
      if result_list[0]['start_day'] > begin_date:
      result_list[0]['start_day'] = begin_date
      if result_list[-1]['end_day'] < end_date:
      result_list[-1]['end_day'] = end_date
      date_dict.update(

      {employee_snapshot_dict[employee_id].employee_id.id: result_list}

      )
      result.update(

      {args: date_dict}

      )

      显示
      payslip_run_record_type = payslip_run_record.type unscheduled_type = '' unscheduled_info = {} if payslip_run_record_type == 'unscheduled': unscheduled_type = payslip_run_record.unscheduled_type for item in payslip_run_record.unscheduled_employee_ids: unscheduled_info [item.employee_id.id] = { 'date_start': item.start_date, 'date_end': item.end_date, } is_last_hire_employee_info = False if unscheduled_type == 'rehired': is_last_hire_employee_info = True payslip_start_date =payslip_run_record.payroll_period.date_start payslip_end_date =payslip_run_record.payroll_period.date_end if payslip_start_date [5:7] in ('01','02','03'): begin_date=str(payslip_start_date [0:5] )+'01-01' end_date=str(payslip_start_date [0:5] )+'03-31' elif payslip_start_date [5:7] in ('04','05','06'): begin_date=str(payslip_start_date [0:5] )+'04-01' end_date=str(payslip_start_date [0:5] )+'06-30' elif payslip_start_date [5:7] in ('07','08','09'): begin_date=str(payslip_start_date [0:5] )+'07-01' end_date=str(payslip_start_date [0:5] )+'09-30' elif payslip_start_date [5:7] in ('10','11','12'): begin_date=str(payslip_start_date [0:5] )+'10-01' end_date=str(payslip_start_date [0:5] )+'12-31' hr_payslip_parameters = preFuncParameterDict.get('F_ArchiveValueCal_Qua', []) value_dict = {} 从薪资参数中获取薪资档案实际值折算计算公式的参数 code:薪资档案编码 if hr_payslip_parameters: for hr_payslip_parameter in hr_payslip_parameters: parameters = eval(hr_payslip_parameter ['func_args'] ) for parameter in parameters: if isinstance(parameter, tuple): value_dict.setdefault(tuple( [eval(i) for i in parameter] ), None) else: value_dict.setdefault((eval(parameter),), None) result = {} for args in value_dict.keys(): code = args [0] if len(args) == 3: qua_type=args [2] else: qua_type=1 employee_records = payslip_run_record.employee_ids date_dict = {} all_base_currency_amount_map = env ['payroll.archive'] ._get_all_base_currency_amount(employee_ids=employee_records.ids, is_last_hire_employee_info=is_last_hire_employee_info) all_employee_payroll_archive_records = env ['payroll.archive'] .get_employee_archives(employee_records.ids, is_last_hire_employee_info=is_last_hire_employee_info,order= ['effective_date'] ) for employee_record in employee_records: employee_id = employee_record.id if payslip_run_record_type == 'unscheduled': payslip_start_date = unscheduled_info.get(employee_id, {}).get('date_start') payslip_end_date = unscheduled_info.get(employee_id, {}).get('date_end') if employee_id not in employee_snapshot_dict: raise Exception('Lack of Employee Snapshot Data: %s' % employee_record.name) payroll_archive_records = employee_record.payroll_archive_ids payroll_archive_records = all_employee_payroll_archive_records.get(employee_id, {}) or {} employee_name = payroll_archive_records.pop('employee_name', '') result_list = [] if payroll_archive_records: for payroll_archive_code, payroll_archive_record_ls in payroll_archive_records.items(): length = len(payroll_archive_record_ls) for payroll_archive_record in payroll_archive_record_ls: effective_date = payroll_archive_record ['effective_date'] expired_date = payroll_archive_record ['expired_date'] 如果失效日期不存在,令其等于9999-12-31 if not expired_date: expired_date = '9999-12-31' 判断薪资档案与薪资周期是否有交集 if payroll_archive_record ['code'] == code and \ end_date >= effective_date and expired_date >= begin_date: date_list = [begin_date, end_date, expired_date, effective_date] date_list.sort() start_day = date_list [1] end_day = date_list [2] amount = all_base_currency_amount_map.get(payroll_archive_record ['id'] ) or payroll_archive_record ['amount'] result_list.append( {'start_day': start_day, 'end_day': end_day, 'amount': amount} ) result_list = sorted(result_list,key=lambda x:x ['start_day'] ) if result_list: if qua_type == 1: if result_list [0] ['start_day'] > begin_date: result_list [0] ['start_day'] = begin_date if result_list [-1] ['end_day'] < end_date: result_list [-1] ['end_day'] = end_date date_dict.update( {employee_snapshot_dict[employee_id].employee_id.id: result_list} ) result.update( {args: date_dict} )

      【业务场景】
      客户有个薪资档案项是“季度绩效基数”,该项每个季度计算并发放,如果员工离职,则在离职月计算并发放。

      【特殊情况说明】
      1、如果员工的“季度绩效基数”不是季度第一天开始,则本季度第1天至第一个“季度绩效基数”也按“季度绩效基数”来算
      2、如果员工的“季度绩效基数”截止没到季度最后一天,则本季度最后一个“季度绩效基数”之后的天数也按最后一个“季度绩效基数”来算

      【举例】
      员工2020.08.10入职,季度绩效基数2000,2020.08.25号调整为3000,2020.09.04调整为4000,2020.09.28离职。
      计算分析:2020.07.01~2020.08.09:基数2000,计薪日:28
      2020.08.10~2020.08.24:基数2000,计薪日:11
      2020.08.25~2020.09.03:基数3000,计薪日:8
      2020.09.04~2020.09.28:基数4000,计薪日:18
      2020.09.29~2020.09.30:基数4000,计薪日:2

      算法1=(2000*28+2000*11+3000*8+4000*18+4000*2)/67=2716.42
      算法2=(2000*(28+11)+3000*8+4000*(18+2))/67=2716.42

      https://enmonster.peoplus.cn/

            wenqiang.liu 刘文强
            yumch 于明朝
            表决:
            0 为这个问题表决

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