2017-09-21 9 views
3

에서 전체 출석을 확인하면 직원의 급여는 작업 표 출석을 기준으로합니다. 그래서 가능하게하기 위해, 나는 payroll.py 에서 openerp (7) 코드를 정확하게 변경했습니다. 미리보기 코드는 "contract.working_hours"를 기반으로합니다. 시간은 총 시간이 걸리고 pyaslip.number_of_hours에 넣습니다.근로자 사회의 출퇴근 시간 기록 용지

def get_worked_day_lines(self, cr, uid, contract_ids, date_from, date_to, context=None): 
    """ 
    @param contract_ids: list of contract id 
    @return: returns a list of dict containing the input that should be applied for the given contract between date_from and date_to 
    """ 
    def was_on_leave(employee_id, datetime_day, context=None): 
     res = False 
     day = datetime_day.strftime("%Y-%m-%d") 
     holiday_ids = self.pool.get('hr.holidays').search(cr, uid, [('state','=','validate'),('employee_id','=',employee_id),('type','=','remove'),('date_from','<=',day),('date_to','>=',day)]) 
     if holiday_ids: 
      res = self.pool.get('hr.holidays').browse(cr, uid, holiday_ids, context=context)[0].holiday_status_id.name 
     return res 

    res = [] 
    for contract in self.pool.get('hr.contract').browse(cr, uid, contract_ids, context=context): 
     if not contract.working_hours: 
      #fill only if the contract as a working schedule linked 
      continue 
     attendances = { 
      'name': _("Normal Working Days paid at 100%"), 
      'sequence': 1, 
      'code': 'WORK100', 
      'number_of_days': 0.0, 
      'number_of_hours': 0.0, 
      'contract_id': contract.id, 
     } 
     leaves = {} 
     day_from = datetime.strptime(date_from,"%Y-%m-%d") 
     day_to = datetime.strptime(date_to,"%Y-%m-%d") 
     nb_of_days = (day_to - day_from).days + 1 
     for day in range(0, nb_of_days): 
      working_hours_on_day = self.pool.get('resource.calendar').working_hours_on_day(cr, uid, contract.working_hours, day_from + timedelta(days=day), context) 
      if working_hours_on_day: 
       #the employee had to work 
       leave_type = was_on_leave(contract.employee_id.id, day_from + timedelta(days=day), context=context) 
       if leave_type: 
        #if he was on leave, fill the leaves dict 
        if leave_type in leaves: 
         leaves[leave_type]['number_of_days'] += 1.0 
         leaves[leave_type]['number_of_hours'] += working_hours_on_day 
        else: 
         leaves[leave_type] = { 
          'name': leave_type, 
          'sequence': 5, 
          'code': leave_type, 
          'number_of_days': 1.0, 
          'number_of_hours': working_hours_on_day, 
          'contract_id': contract.id, 
         } 
       else: 
        #add the input vals to tmp (increment if existing) 
        attendances['number_of_days'] += 1.0 
        attendances['number_of_hours'] += working_hours_on_day 
     leaves = [value for key,value in leaves.items()] 
     res += [attendances] + leaves 
    return res 
I'v 검색하고 모델을 검색하고, 제가하고 싶은 것은 작업 표에서 총을 어디에 hr_timeshet.employee_id = payslip.employee_id

def get_worked_day_lines(self, cr, uid, employee_id, date_from, date_to, context=None): 
    res = [] 
    for sheet in self.pool.get('hr_timesheet_sheet.sheet').search(cr,uid, [('state','=','confirm'),('employee_id','=',employee_id)]): 
     if not sheet: 
      continue 
     attendances = { 
      'name': _("Normal Working Days paid at 100%"), 
      'sequence': 1, 
      'code': 'WORK100', 
      'number_of_days': 0.0, 
      'number_of_hours': 0.0, 
      #'contract_id': contract.id, 
     } 
     leaves = {} 
     day_from = datetime.strptime(date_from,"%Y-%m-%d") 
     day_to = datetime.strptime(date_to,"%Y-%m-%d") 
     nb_of_days = (day_to - day_from).days + 1 
     for day in range(0, nb_of_days): 
      if sheet: 
       attendances['number_of_days'] += 1.0 
       attendances['code'] = sheet.total_attendance 

정말 얻을 수있다하는 방법에 대한 researche을하고

사전에 감사해야합니다. 오류 :

Invalid value hr.employee(1,) in domain term ('employee_id', '=', hr.employee(1,))

답변

1

실제로 id 만 필요할 때 hr.employee 개체가 표시되기 때문에 오류가 발생합니다. 변경 시도 :

('employee_id','=',employee_id)] 


sheet

('employee_id','=',employee_id.id)] 

하려면 정수, 먼저 객체를 찾아 본 후 total_attendance에 액세스해야합니다. 시도 :이 당신을 도움이되기를 바랍니다

if sheet: 
    sheet_obj=self.pool.get('hr_timesheet_sheet.sheet').browse(cr, uid, sheet, context=context) 
    attendances['number_of_days'] += 1.0 
    attendances['code'] = sheet_obj.total_attendance 

.

+0

감사합니다. @Dayana하지만 다른 오류가 있습니다. 'int'객체에 'total_attendance'속성이 없습니다. – imad

+0

내 대답을 편집했습니다 – Dayana

+1

감사합니다. 한 달 후에 방금 국가 문제를 해결해 주셔서 감사합니다. – imad