gpt4 book ai didi

python - 从时间表中获得总出勤率

转载 作者:行者123 更新时间:2023-11-28 18:19:12 24 4
gpt4 key购买 nike

在电力社会中,员工的工资单是基于考勤表的出勤率。所以为了使之成为可能,我一直在更改 openerp(7) 代码,就在 payroll.py 中预览代码基于“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

我一直在研究如何浏览和搜索模型,我想做的是从时间表中获取总数,其中 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

非常需要,先谢谢了错误:

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

最佳答案

错误是因为当您实际上只需要 id 时,您正在获取 hr.employee 对象。尝试改变:

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

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

sheet是一个整数,必须先浏览对象,然后获取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

希望对你有帮助

关于python - 从时间表中获得总出勤率,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46345613/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com