我有这个名为" hr_company_holidays ",
的课程 class hr_company_holidays(osv.osv):
_name = "hr.company.holidays"
_description = "hr.company.holidays"
_columns = {
'name': fields.char('Holiday', size=256, required=True),
'date': fields.date('Day', size=256, required=True),
}
在hr_holiday模块中,还有另一个名为" hr_holidays "在那个班级里有一个像这样的函数,
def _get_number_of_days(self, date_from, date_to):
"""Returns a float equals to the timedelta between two dates given as string."""
DATETIME_FORMAT = "%Y-%m-%d %H:%M:%S"
from_dt = datetime.datetime.strptime(date_from, DATETIME_FORMAT)
to_dt = datetime.datetime.strptime(date_to, DATETIME_FORMAT)
timedelta = to_dt - from_dt
diff_day = timedelta.days + float(timedelta.seconds) / 86400
return diff_day
如何计算 from_dt 和 to_dt 之间的天数,以避免公司假期和周末......?
我尝试过波纹管功能,我得到的只是一个错误,请帮帮我
def _get_number_of_days(self, date_from, date_to):
"""Returns a float equals to the timedelta between two dates given as string."""
values = {}
#comp_holidays = self.pool.get('company.holidays').browse(values['company_holiday_id']).date
#print comp_holidays
DATETIME_FORMAT = "%Y-%m-%d %H:%M:%S"
incre=timedelta(day=1)
from_dt = datetime.datetime.strptime(date_from, DATETIME_FORMAT)
to_dt = datetime.datetime.strptime(date_to, DATETIME_FORMAT)
from_date=from_dt
to_date=to_dt
diff=0
holi=0
while from_dt <= to_dt:
holiday_id=hr_holidays.search(self, cr, uid, from_date,context=context)
holiday_day=hr_holidays.browse(cr, uid, holiday_id, context=context).date
if from_date == holiday_day:
holi += 1
from_date += incre
else:
from_date += incre
timedelta = to_dt - from_dt + holi
diff_day = timedelta.days + float(timedelta.seconds) / 86400