为了创建一个模块“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()
来实现此方法,并且它确实工作得很好,实际上我想要的是仅在我点击保存按钮时进行所有这些计算...
提前谢谢
答案 0 :(得分:2)
我喜欢你想要做的这个想法,来自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
即使保留arg field_name