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

【PRO-似鸟】-人事提醒-合同到期提醒

XMLWord打印

    • Icon: Change Change
    • 解决结果: 完成
    • Icon: High High
    • 202105
    • S-似鸟-Y2021011
    • 基础通用功能
    • 隐藏

      1、合同到期提醒(NTL)

      BP_SUBMIT_STATUS = ['waiting', 'reject', 'cancel', 'rollback', 'done']
      emp_active_status_id = self.env.ref('employee_central.employee_status_active').id  # 员工在职状态ID
      today = datetime.date.today()
      reminder_day = today + datetime.timedelta(days=self.reminder_advance_days)
      
      # 1. 查询到期的合同
      domain = [
          ('employee_id.employee_status', '=', emp_active_status_id),
          ('contract_date_end', '=', reminder_day),
          ('contract_agreement_id.category', '=', 'contract'),
          ('contract_agreement_status', '=', 'current_contract'),
      ]
      
      instances = self.env['bp'].query_done(self.env['hr.contract'], domain=domain)
      if instances:
          # 2. 查找续签的(同一法人实体&同一合同类型)
          employees = instances.mapped('employee_id')
          employee_yes = []
          employee_zjgy = self.env['hr.employee'].search([('id','in', employees.ids)])
          if employee_zjgy:
              # 过滤一级部门是NTL的员工
              for employee_ in employee_zjgy:
                  department = employee_.department_id
                  while department.parent_department_id: 
                      department = department.parent_department_id
                  if department.code == '310001':
                      employee_yes.append(employee_)
                  else:
                      continue
          employee_yes_ids = [employee_.id for employee_ in employee_yes if employee_yes] 
          domain = [
              ('contract_agreement_id.category', '=', 'contract'),
              ('employee_id', 'in', employee_yes_ids),
              ('contract_date_end', '>', reminder_day)
          ]
          # 所有新合同(提交了审批的)
          renew = self.env['bp'].query_status(instances, BP_SUBMIT_STATUS, domain)
          for instance in instances:
              instances = instances - renew.filtered(lambda x: x.legal_entity_id == instance.legal_entity_id)
      
          if instances:
              # 3. 查找离职日期大于合同到期日期的审批通过的
              employees = instances.mapped('employee_id')
              registination_employees = set(employees.filtered(
                  lambda emp: emp.termination_date and emp.termination_date <= reminder_day).ids)
              instances = [instance for instance in instances if instance.employee_id.id not in registination_employees]
      
      result = {
          'instances': instances,
          'business_type': 'contract'
      }
      

      2、合同到期提醒(PT)

      BP_SUBMIT_STATUS = ['waiting', 'reject', 'cancel', 'rollback', 'done']
      emp_active_status_id = self.env.ref('employee_central.employee_status_active').id  # 员工在职状态ID
      today = datetime.date.today()
      reminder_day = today + datetime.timedelta(days=self.reminder_advance_days)
      
      # 1. 查询到期的合同
      domain = [
          ('employee_id.employee_status', '=', emp_active_status_id),
          ('contract_date_end', '=', reminder_day),
          ('contract_agreement_id.category', '=', 'contract'),
          ('contract_agreement_status', '=', 'current_contract'),
      ]
      
      instances = self.env['bp'].query_done(self.env['hr.contract'], domain=domain)
      if instances:
          # 2. 查找续签的(同一法人实体&同一合同类型)
          employees = instances.mapped('employee_id')
          employee_yes = []
          # 过滤PT类型(兼职、实习生、外包)员工
          employee_zjgy = self.env['hr.employee'].search([('job_info_id.employee_type.code','in',('ET005','ET006','ET007')),('id','in', employees.ids)])
          if employee_zjgy:
              # 过滤一级部门是NCH的员工
              for employee_ in employee_zjgy:
                  department = employee_.department_id
                  while department.parent_department_id: 
                      department = department.parent_department_id
                  if department.code == '110001':
                      employee_yes.append(employee_)
                  else:
                      continue
          employee_yes_ids = [employee_.id for employee_ in employee_yes if employee_yes] 
          domain = [
              ('contract_agreement_id.category', '=', 'contract'),
              ('employee_id', 'in', employee_yes_ids),
              ('contract_date_end', '>', reminder_day)
          ]
          # 所有新合同(提交了审批的)
          renew = self.env['bp'].query_status(instances, BP_SUBMIT_STATUS, domain)
          for instance in instances:
              instances = instances - renew.filtered(lambda x: x.legal_entity_id == instance.legal_entity_id)
      
          if instances:
              # 3. 查找离职日期大于合同到期日期的审批通过的
              employees = instances.mapped('employee_id')
              registination_employees = set(employees.filtered(
                  lambda emp: emp.termination_date and emp.termination_date <= reminder_day).ids)
              instances = [instance for instance in instances if instance.employee_id.id not in registination_employees]
      
      result = {
          'instances': instances,
          'business_type': 'contract'
      }
      

      3、合同到期提醒(派遣)

      BP_SUBMIT_STATUS = ['waiting', 'reject', 'cancel', 'rollback', 'done']
      emp_active_status_id = self.env.ref('employee_central.employee_status_active').id  # 员工在职状态ID
      today = datetime.date.today()
      reminder_day = today + datetime.timedelta(days=self.reminder_advance_days)
      
      # 查询到期的合同
      domain = [
          ('employee_id.employee_status', '=', emp_active_status_id),
          ('contract_date_end', '=', reminder_day),
          ('contract_agreement_id.category', '=', 'contract'),
          ('contract_agreement_status', '=', 'current_contract'),
      ]
      
      instances = self.env['bp'].query_done(self.env['hr.contract'], domain=domain)
      if instances:
          # 2. 查找续签的(同一法人实体&同一合同类型)
          employees = instances.mapped('employee_id')
          employee_yes = []
          # 过滤派遣类型员工
          employee_zjgy = self.env['hr.employee'].search([('job_info_id.employee_type.code','=','ET003'),('id','in', employees.ids)])
          if employee_zjgy:
              # 过滤一级部门是NCH的员工
              for employee_ in employee_zjgy:
                  department = employee_.department_id
                  while department.parent_department_id: 
                      department = department.parent_department_id
                  if department.code == '110001':
                      employee_yes.append(employee_)
                  else:
                      continue
          employee_yes_ids = [employee_.id for employee_ in employee_yes if employee_yes] 
          domain = [
              ('contract_agreement_id.category', '=', 'contract'),
              ('employee_id', 'in', employee_yes_ids),
              ('contract_date_end', '>', reminder_day)
          ]
          # 所有新合同(提交了审批的)
          renew = self.env['bp'].query_status(instances, BP_SUBMIT_STATUS, domain)
          for instance in instances:
              instances = instances - renew.filtered(lambda x: x.legal_entity_id == instance.legal_entity_id)
      
          if instances:
              # 3. 查找离职日期大于合同到期日期的审批通过的
              employees = instances.mapped('employee_id')
              registination_employees = set(employees.filtered(
                  lambda emp: emp.termination_date and emp.termination_date <= reminder_day).ids)
              instances = [instance for instance in instances if instance.employee_id.id not in registination_employees]
      
      result = {
          'instances': instances,
          'business_type': 'contract'
      }
      

      4、合同到期提醒(直接雇佣)

      BP_SUBMIT_STATUS = ['waiting', 'reject', 'cancel', 'rollback', 'done']
      emp_active_status_id = self.env.ref('employee_central.employee_status_active').id  # 员工在职状态ID
      today = datetime.date.today()
      reminder_day = today + datetime.timedelta(days=self.reminder_advance_days)
      
      # 1. 查询到期的合同
      domain = [
          ('employee_id.employee_status', '=', emp_active_status_id),
          ('contract_date_end', '=', reminder_day),
          ('contract_agreement_id.category', '=', 'contract'),
          ('contract_agreement_status', '=', 'current_contract'),
      ]
      
      instances = self.env['bp'].query_done(self.env['hr.contract'], domain=domain)
      if instances:
          # 2. 查找续签的(同一法人实体&同一合同类型)
          employees = instances.mapped('employee_id')
          employee_yes = []
          # 过滤直接雇佣类型员工
          employee_zjgy = self.env['hr.employee'].search([('job_info_id.employee_type.code','=','ET002'),('id','in', employees.ids)])
          if employee_zjgy:
              # 过滤一级部门是NCH的员工
              for employee_ in employee_zjgy:
                  department = employee_.department_id
                  while department.parent_department_id: 
                      department = department.parent_department_id
                  if department.code == '110001':
                      employee_yes.append(employee_)
                  else:
                      continue
          employee_yes_ids = [employee_.id for employee_ in employee_yes if employee_yes] 
          domain = [
              ('contract_agreement_id.category', '=', 'contract'),
              ('employee_id', 'in', employee_yes_ids),
              ('contract_date_end', '>', reminder_day)
          ]
          # 所有新合同(提交了审批的)
          renew = self.env['bp'].query_status(instances, BP_SUBMIT_STATUS, domain)
          for instance in instances:
              instances = instances - renew.filtered(lambda x: x.legal_entity_id == instance.legal_entity_id)
      
          if instances:
              # 3. 查找离职日期大于合同到期日期的审批通过的
              employees = instances.mapped('employee_id')
              registination_employees = set(employees.filtered(
                  lambda emp: emp.termination_date and emp.termination_date <= reminder_day).ids)
              instances = [instance for instance in instances if instance.employee_id.id not in registination_employees]
      
      result = {
          'instances': instances,
          'business_type': 'contract'
      }
      
      显示
      1、合同到期提醒(NTL) BP_SUBMIT_STATUS = [ 'waiting' , 'reject' , 'cancel' , 'rollback' , 'done' ] emp_active_status_id = self.env.ref( 'employee_central.employee_status_active' ).id # 员工在职状态ID today = datetime.date.today() reminder_day = today + datetime.timedelta(days=self.reminder_advance_days) # 1. 查询到期的合同 domain = [ ( 'employee_id.employee_status' , '=' , emp_active_status_id), ( 'contract_date_end' , '=' , reminder_day), ( 'contract_agreement_id.category' , '=' , 'contract' ), ( 'contract_agreement_status' , '=' , 'current_contract' ), ] instances = self.env[ 'bp' ].query_done(self.env[ 'hr.contract' ], domain=domain) if instances: # 2. 查找续签的(同一法人实体&同一合同类型) employees = instances.mapped( 'employee_id' ) employee_yes = [] employee_zjgy = self.env[ 'hr.employee' ].search([( 'id' , 'in' , employees.ids)]) if employee_zjgy: # 过滤一级部门是NTL的员工 for employee_ in employee_zjgy: department = employee_.department_id while department.parent_department_id: department = department.parent_department_id if department.code == '310001' : employee_yes.append(employee_) else : continue employee_yes_ids = [employee_.id for employee_ in employee_yes if employee_yes] domain = [ ( 'contract_agreement_id.category' , '=' , 'contract' ), ( 'employee_id' , 'in' , employee_yes_ids), ( 'contract_date_end' , '>' , reminder_day) ] # 所有新合同(提交了审批的) renew = self.env[ 'bp' ].query_status(instances, BP_SUBMIT_STATUS, domain) for instance in instances: instances = instances - renew.filtered(lambda x: x.legal_entity_id == instance.legal_entity_id) if instances: # 3. 查找离职日期大于合同到期日期的审批通过的 employees = instances.mapped( 'employee_id' ) registination_employees = set(employees.filtered( lambda emp: emp.termination_date and emp.termination_date <= reminder_day).ids) instances = [instance for instance in instances if instance.employee_id.id not in registination_employees] result = { 'instances' : instances, 'business_type' : 'contract' } 2、合同到期提醒(PT) BP_SUBMIT_STATUS = [ 'waiting' , 'reject' , 'cancel' , 'rollback' , 'done' ] emp_active_status_id = self.env.ref( 'employee_central.employee_status_active' ).id # 员工在职状态ID today = datetime.date.today() reminder_day = today + datetime.timedelta(days=self.reminder_advance_days) # 1. 查询到期的合同 domain = [ ( 'employee_id.employee_status' , '=' , emp_active_status_id), ( 'contract_date_end' , '=' , reminder_day), ( 'contract_agreement_id.category' , '=' , 'contract' ), ( 'contract_agreement_status' , '=' , 'current_contract' ), ] instances = self.env[ 'bp' ].query_done(self.env[ 'hr.contract' ], domain=domain) if instances: # 2. 查找续签的(同一法人实体&同一合同类型) employees = instances.mapped( 'employee_id' ) employee_yes = [] # 过滤PT类型(兼职、实习生、外包)员工 employee_zjgy = self.env[ 'hr.employee' ].search([( 'job_info_id.employee_type.code' , 'in' ,( 'ET005' , 'ET006' , 'ET007' )),( 'id' , 'in' , employees.ids)]) if employee_zjgy: # 过滤一级部门是NCH的员工 for employee_ in employee_zjgy: department = employee_.department_id while department.parent_department_id: department = department.parent_department_id if department.code == '110001' : employee_yes.append(employee_) else : continue employee_yes_ids = [employee_.id for employee_ in employee_yes if employee_yes] domain = [ ( 'contract_agreement_id.category' , '=' , 'contract' ), ( 'employee_id' , 'in' , employee_yes_ids), ( 'contract_date_end' , '>' , reminder_day) ] # 所有新合同(提交了审批的) renew = self.env[ 'bp' ].query_status(instances, BP_SUBMIT_STATUS, domain) for instance in instances: instances = instances - renew.filtered(lambda x: x.legal_entity_id == instance.legal_entity_id) if instances: # 3. 查找离职日期大于合同到期日期的审批通过的 employees = instances.mapped( 'employee_id' ) registination_employees = set(employees.filtered( lambda emp: emp.termination_date and emp.termination_date <= reminder_day).ids) instances = [instance for instance in instances if instance.employee_id.id not in registination_employees] result = { 'instances' : instances, 'business_type' : 'contract' } 3、合同到期提醒(派遣) BP_SUBMIT_STATUS = [ 'waiting' , 'reject' , 'cancel' , 'rollback' , 'done' ] emp_active_status_id = self.env.ref( 'employee_central.employee_status_active' ).id # 员工在职状态ID today = datetime.date.today() reminder_day = today + datetime.timedelta(days=self.reminder_advance_days) # 查询到期的合同 domain = [ ( 'employee_id.employee_status' , '=' , emp_active_status_id), ( 'contract_date_end' , '=' , reminder_day), ( 'contract_agreement_id.category' , '=' , 'contract' ), ( 'contract_agreement_status' , '=' , 'current_contract' ), ] instances = self.env[ 'bp' ].query_done(self.env[ 'hr.contract' ], domain=domain) if instances: # 2. 查找续签的(同一法人实体&同一合同类型) employees = instances.mapped( 'employee_id' ) employee_yes = [] # 过滤派遣类型员工 employee_zjgy = self.env[ 'hr.employee' ].search([( 'job_info_id.employee_type.code' , '=' , 'ET003' ),( 'id' , 'in' , employees.ids)]) if employee_zjgy: # 过滤一级部门是NCH的员工 for employee_ in employee_zjgy: department = employee_.department_id while department.parent_department_id: department = department.parent_department_id if department.code == '110001' : employee_yes.append(employee_) else : continue employee_yes_ids = [employee_.id for employee_ in employee_yes if employee_yes] domain = [ ( 'contract_agreement_id.category' , '=' , 'contract' ), ( 'employee_id' , 'in' , employee_yes_ids), ( 'contract_date_end' , '>' , reminder_day) ] # 所有新合同(提交了审批的) renew = self.env[ 'bp' ].query_status(instances, BP_SUBMIT_STATUS, domain) for instance in instances: instances = instances - renew.filtered(lambda x: x.legal_entity_id == instance.legal_entity_id) if instances: # 3. 查找离职日期大于合同到期日期的审批通过的 employees = instances.mapped( 'employee_id' ) registination_employees = set(employees.filtered( lambda emp: emp.termination_date and emp.termination_date <= reminder_day).ids) instances = [instance for instance in instances if instance.employee_id.id not in registination_employees] result = { 'instances' : instances, 'business_type' : 'contract' } 4、合同到期提醒(直接雇佣) BP_SUBMIT_STATUS = [ 'waiting' , 'reject' , 'cancel' , 'rollback' , 'done' ] emp_active_status_id = self.env.ref( 'employee_central.employee_status_active' ).id # 员工在职状态ID today = datetime.date.today() reminder_day = today + datetime.timedelta(days=self.reminder_advance_days) # 1. 查询到期的合同 domain = [ ( 'employee_id.employee_status' , '=' , emp_active_status_id), ( 'contract_date_end' , '=' , reminder_day), ( 'contract_agreement_id.category' , '=' , 'contract' ), ( 'contract_agreement_status' , '=' , 'current_contract' ), ] instances = self.env[ 'bp' ].query_done(self.env[ 'hr.contract' ], domain=domain) if instances: # 2. 查找续签的(同一法人实体&同一合同类型) employees = instances.mapped( 'employee_id' ) employee_yes = [] # 过滤直接雇佣类型员工 employee_zjgy = self.env[ 'hr.employee' ].search([( 'job_info_id.employee_type.code' , '=' , 'ET002' ),( 'id' , 'in' , employees.ids)]) if employee_zjgy: # 过滤一级部门是NCH的员工 for employee_ in employee_zjgy: department = employee_.department_id while department.parent_department_id: department = department.parent_department_id if department.code == '110001' : employee_yes.append(employee_) else : continue employee_yes_ids = [employee_.id for employee_ in employee_yes if employee_yes] domain = [ ( 'contract_agreement_id.category' , '=' , 'contract' ), ( 'employee_id' , 'in' , employee_yes_ids), ( 'contract_date_end' , '>' , reminder_day) ] # 所有新合同(提交了审批的) renew = self.env[ 'bp' ].query_status(instances, BP_SUBMIT_STATUS, domain) for instance in instances: instances = instances - renew.filtered(lambda x: x.legal_entity_id == instance.legal_entity_id) if instances: # 3. 查找离职日期大于合同到期日期的审批通过的 employees = instances.mapped( 'employee_id' ) registination_employees = set(employees.filtered( lambda emp: emp.termination_date and emp.termination_date <= reminder_day).ids) instances = [instance for instance in instances if instance.employee_id.id not in registination_employees] result = { 'instances' : instances, 'business_type' : 'contract' }

      合同到期提醒进行提醒范围的筛选:
      筛选条件1:员工类型为直接雇佣且一级部门为NCH
      筛选条件2:员工类型为派遣员工且一级部门为NCH
      筛选条件3:员工类型为PT员工且一级部门为NCH
      筛选条件4:一级部门为NTL

            chengdd 程丹丹
            lugx 卢桂香
            表决:
            0 为这个问题表决

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