gpt4 book ai didi

python - 函数域,超出最大递归深度

转载 作者:行者123 更新时间:2023-12-01 02:33:26 25 4
gpt4 key购买 nike

为了创建模块“hr_payroll_from_timesheet”,我尝试添加一个字段,以便可以计算员工在周六或周五工作的小时数。

class hr_timsheet_sheet(osv.osv)
_inherit = 'hr_timsheet_sheet.sheet'

def _woked_days(self,cr,uid,ids,field_name,args=None,context=None)
sheet = self.browse(cr,uid,ids)
for record in sheet:
hr_sup= ["Saturday","Friday"]
count = 0.0
for line in record.period_ids:
day = line.name
year, month, day = (int(x) for x in day.split('-'))
days = datetime.date(year,month,day)
if days.strftime("%A") in hr_sup:
count += line.total_attendance
self.write(cr,uid,ids,{
'weekend' : count,
})
return True

_columns = {
'weekend' : fields.function(_worked_days,method=True,type='float',store=True)
}

我确实尝试通过添加一个新按钮并将我的字段更改为 'weekend' : float() 来实现此方法,并且它确实工作得很好,实际上我想要的是使所有仅当我单击“保存”按钮时才进行此计算...提前致谢

最佳答案

我喜欢你要做的这个想法,来自 timsheet 的工资单试试这个:

class hr_timsheet_sheet(osv.osv)
_inherit = 'hr_timsheet_sheet.sheet'

def _woked_days(self,cr,uid,ids,weekend,args=None,context=None)
sheet = self.browse(cr,uid,ids)
for record in sheet:
hr_sup= ["Saturday","Friday"]
count = 0.0
for line in record.period_ids:
day = line.name
year, month, day = (int(x) for x in day.split('-'))
days = datetime.date(year,month,day)
if days.strftime("%A") in hr_sup:
count += line.total_attendance
res[record.id] = count
return True

即使保留参数field_name,它也会工作

关于python - 函数域,超出最大递归深度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46506845/

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