[FIX] resource: py26 compat'
bzr revid: xmo@openerp.com-20140128175640-gmeecmwhevhg3oek
This commit is contained in:
parent
59afba09db
commit
642b3a167d
|
@ -24,13 +24,11 @@ from dateutil import rrule
|
|||
from dateutil.relativedelta import relativedelta
|
||||
from operator import itemgetter
|
||||
|
||||
from faces import *
|
||||
from openerp import tools
|
||||
from openerp.osv import fields, osv
|
||||
from openerp.tools.float_utils import float_compare
|
||||
from openerp.tools.translate import _
|
||||
|
||||
|
||||
class resource_calendar(osv.osv):
|
||||
""" Calendar model for a resource. It has
|
||||
|
||||
|
@ -159,9 +157,9 @@ class resource_calendar(osv.osv):
|
|||
for interval in intervals:
|
||||
res += interval[1] - interval[0]
|
||||
if res > limit and remove_at_end:
|
||||
interval = (interval[0], interval[1] + relativedelta(seconds=(limit-res).total_seconds()))
|
||||
interval = (interval[0], interval[1] + relativedelta(seconds=seconds(limit-res)))
|
||||
elif res > limit:
|
||||
interval = (interval[0] + relativedelta(seconds=(res-limit).total_seconds()), interval[1])
|
||||
interval = (interval[0] + relativedelta(seconds=seconds(res-limit)), interval[1])
|
||||
results.append(interval)
|
||||
if res > limit:
|
||||
break
|
||||
|
@ -367,7 +365,7 @@ class resource_calendar(osv.osv):
|
|||
default_interval, context)
|
||||
for interval in intervals:
|
||||
res += interval[1] - interval[0]
|
||||
return (res.total_seconds() / 3600.0)
|
||||
return seconds(res) / 3600.0
|
||||
|
||||
def get_working_hours(self, cr, uid, id, start_dt, end_dt, compute_leaves=False,
|
||||
resource_id=None, default_interval=None, context=None):
|
||||
|
@ -450,7 +448,7 @@ class resource_calendar(osv.osv):
|
|||
res = datetime.timedelta()
|
||||
for interval in working_intervals:
|
||||
res += interval[1] - interval[0]
|
||||
remaining_hours -= (res.total_seconds() / 3600.0)
|
||||
remaining_hours -= (seconds(res) / 3600.0)
|
||||
if backwards:
|
||||
intervals = new_working_intervals + intervals
|
||||
else:
|
||||
|
@ -821,5 +819,9 @@ class resource_calendar_leaves(osv.osv):
|
|||
return {'value': result}
|
||||
return {'value': {'calendar_id': []}}
|
||||
|
||||
def seconds(td):
|
||||
assert isinstance(td, datetime.timedelta)
|
||||
|
||||
return (td.microseconds + (td.seconds + td.days * 24 * 3600) * 10**6) / 10.**6
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
|
|
@ -290,7 +290,7 @@ class TestResource(TestResourceCommon):
|
|||
td = timedelta()
|
||||
for item in res:
|
||||
td += item[1] - item[0]
|
||||
self.assertEqual(td.total_seconds() / 3600.0, 40.0, 'resource_calendar: wrong hours scheduling')
|
||||
self.assertEqual(seconds(td) / 3600.0, 40.0, 'resource_calendar: wrong hours scheduling')
|
||||
|
||||
# --------------------------------------------------
|
||||
# Test2: schedule hours forward (old interval_get)
|
||||
|
@ -326,7 +326,7 @@ class TestResource(TestResourceCommon):
|
|||
td = timedelta()
|
||||
for item in res:
|
||||
td += item[1] - item[0]
|
||||
self.assertEqual(td.total_seconds() / 3600.0, 40.0, 'resource_calendar: wrong hours scheduling')
|
||||
self.assertEqual(seconds(td) / 3600.0, 40.0, 'resource_calendar: wrong hours scheduling')
|
||||
|
||||
# res = self.resource_calendar.interval_get(cr, uid, self.calendar_id, self.date1, 40, resource=self.resource1_id, byday=True)
|
||||
# (datetime.datetime(2013, 2, 12, 9, 0), datetime.datetime(2013, 2, 12, 16, 0))
|
||||
|
@ -364,7 +364,7 @@ class TestResource(TestResourceCommon):
|
|||
td = timedelta()
|
||||
for item in res:
|
||||
td += item[1] - item[0]
|
||||
self.assertEqual(td.total_seconds() / 3600.0, 40.0, 'resource_calendar: wrong hours scheduling')
|
||||
self.assertEqual(seconds(td) / 3600.0, 40.0, 'resource_calendar: wrong hours scheduling')
|
||||
|
||||
# --------------------------------------------------
|
||||
# Test3: working hours (old _interval_hours_get)
|
||||
|
@ -443,3 +443,8 @@ class TestResource(TestResourceCommon):
|
|||
# Without calendar, should only count days -> 12 -> 16, 5 days with default intervals
|
||||
res = self.resource_calendar.schedule_days_get_date(cr, uid, None, 5, day_date=self.date1, default_interval=(8, 16))
|
||||
self.assertEqual(res, datetime.strptime('2013-02-16 16:00:00', _format), 'resource_calendar: wrong days scheduling')
|
||||
|
||||
def seconds(td):
|
||||
assert isinstance(td, timedelta)
|
||||
|
||||
return (td.microseconds + (td.seconds + td.days * 24 * 3600) * 10**6) / 10.**6
|
||||
|
|
Loading…
Reference in New Issue