gpt4 book ai didi

python - 工资单 odoo 中的休假扣除错误

转载 作者:行者123 更新时间:2023-12-01 03:39:17 27 4
gpt4 key购买 nike

我尝试为一名员工生成工资单。员工休了半天假(0.5),但在计算工资单时,其自动填充为 1。

从模块 hr_payroll.py 中已有的代码来看,它看起来如下

 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

我不确定这是否是问题所在。有人对此有什么建议吗?

最佳答案

让我先说一下:我没有使用过 odoo,也没有你的其余代码可供测试,所以我还没有验证这一点。

你这里肯定有问题:

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

查看您引用休假和出勤的位置,虽然这些是 float 的,但它们仅在全天中增加,而不是根据您度过的一天的分数来计算。您需要将其更改为:

leaves[leave_type]['number_of_days'] += time_off / hours_per_workday # the 1.0 might make sense here depending on if you count time off as an attendance
leaves[leave_type]['number_of_hours'] += time_off

attendances['number_of_days'] += 1.0 - time_off / hours_per_workday
attendances['number_of_hours'] += working_hours_on_day - time_off

显然,我插入的虚拟变量需要在某处定义和计算。

此外,正如安东尼·罗西(Anthony Rossi)在评论中指出的那样,您通常需要几天而不是几个小时才能工作。示例:

day_from = datetime.strptime(date_from,"%Y-%m-%d")
day_to = datetime.strptime(date_to,"%Y-%m-%d")

请注意,您只有 YY/MM/DD 而没有时间。

关于python - 工资单 odoo 中的休假扣除错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39909636/

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