函数字段,超过最大递归深度
function field, maximum recursion depth exceeded
为了创建模块 "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()
来实现此方法,并且效果很好,实际上我想要的是仅在单击保存按钮...
提前致谢
我喜欢你想做的这个想法,时间表中的工资单
试试这个:
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
即使保留 arg field_name
也能正常工作
为了创建模块 "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()
来实现此方法,并且效果很好,实际上我想要的是仅在单击保存按钮...
提前致谢
我喜欢你想做的这个想法,时间表中的工资单 试试这个:
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
即使保留 arg field_name