diff --git a/addons/mail/mail_message.py b/addons/mail/mail_message.py index 295056c66eb..b69869efa11 100644 --- a/addons/mail/mail_message.py +++ b/addons/mail/mail_message.py @@ -536,11 +536,9 @@ class mail_message(osv.osv): if res: message.write({'state':'sent', 'message_id': res}) message_sent = True - print "SENT" else: message.write({'state':'exception'}) message_sent = False - print "NOT SENT" # if auto_delete=True then delete that sent messages as well as attachments if message_sent and message.auto_delete: diff --git a/addons/project_issue/project_issue.py b/addons/project_issue/project_issue.py index a099f30f561..f0d78f53dfc 100644 --- a/addons/project_issue/project_issue.py +++ b/addons/project_issue/project_issue.py @@ -142,12 +142,27 @@ class project_issue(crm.crm_case, osv.osv): resource_ids = res_obj.search(cr, uid, [('user_id','=',issue.user_id.id)]) if resource_ids and len(resource_ids): resource_id = resource_ids[0] - duration = float(ans.days) + float(ans.seconds)/(24*3600) + duration = float(ans.days) + if issue.project_id and issue.project_id.resource_calendar_id: + duration = float(ans.days) * 24 + + new_dates = cal_obj.interval_min_get(cr, uid, + issue.project_id.resource_calendar_id.id, + date_create, + duration, resource=resource_id) + no_days = [] + date_until = datetime.strptime(date_until, '%Y-%m-%d %H:%M:%S') + for in_time, out_time in new_dates: + if in_time.date not in no_days: + no_days.append(in_time.date) + if out_time > date_until: + break + duration = len(no_days) if field in ['working_hours_open','working_hours_close']: res[issue.id][field] = hours else: - res[issue.id][field] = duration + res[issue.id][field] = abs(float(duration)) return res diff --git a/addons/resource/resource.py b/addons/resource/resource.py index 7578bf2f3f1..fb3d8c0980e 100644 --- a/addons/resource/resource.py +++ b/addons/resource/resource.py @@ -28,7 +28,6 @@ from tools.translate import _ from itertools import groupby from operator import itemgetter -import pytz class resource_calendar(osv.osv): _name = "resource.calendar" @@ -200,7 +199,7 @@ class resource_calendar(osv.osv): res = self.interval_get_multi(cr, uid, [(dt_from.strftime('%Y-%m-%d %H:%M:%S'), hours, id)], resource, byday)[(dt_from.strftime('%Y-%m-%d %H:%M:%S'), hours, id)] return res - def interval_hours_get(self, cr, uid, id, dt_from, dt_to, resource=False, context=None): + def interval_hours_get(self, cr, uid, id, dt_from, dt_to, resource=False): """ Calculates the Total Working hours based on given start_date to end_date, If resource id is supplied that it will consider the source leaves also in calculating the hours. @@ -217,57 +216,41 @@ class resource_calendar(osv.osv): return 0.0 dt_leave = self._get_leaves(cr, uid, id, resource) hours = 0.0 - - orig_dt_from = dt_from - - users_obj = self.pool.get('res.users') - user = users_obj.browse(cr, uid, uid, context=context) - utc = pytz.timezone('UTC') - - if user.context_tz: - context_tz = pytz.timezone(user.context_tz) - else: - context_tz = utc - - # gap between UTC ans user timezone - tz_gap = (utc.localize(dt_from) - context_tz.localize(dt_from)).seconds / 3600 - - while dt_from <= dt_to: + + current_hour = dt_from.hour + + while (dt_from <= dt_to): cr.execute("select hour_from,hour_to from resource_calendar_attendance where dayofweek='%s' and calendar_id=%s order by hour_from", (dt_from.weekday(),id)) - slots = cr.fetchall() - - for (hour_from, hour_to) in slots: + der = cr.fetchall() + for (hour_from,hour_to) in der: + if hours != 0.0:#For first time of the loop only,hours will be 0 + current_hour = hour_from leave_flag = False - dt_check = dt_from.strftime('%Y-%m-%d') - for leave in dt_leave: - if dt_check == leave: - dt_check = datetime.strptime(dt_check, "%Y-%m-%d") + timedelta(days=1) - leave_flag = True - - if leave_flag: - break - else: - if dt_from.hour >= hour_to: - continue - elif dt_from.hour >= hour_from: - hour_from = dt_from.hour + dt_from.minute/60 + dt_from.second/3600 - d1 = datetime(dt_from.year, dt_from.month, dt_from.day, int(math.floor(hour_from)), int((hour_from % 1) * 60)) - - if dt_from.day == dt_to.day and hour_from <= (dt_to.hour + tz_gap) < hour_to: - - hours += (utc.localize(dt_to) - context_tz.localize(d1)).seconds + if (hour_to>=current_hour): + dt_check = dt_from.strftime('%Y-%m-%d') + for leave in dt_leave: + if dt_check == leave: + dt_check = datetime.strptime(dt_check, "%Y-%m-%d") + timedelta(days=1) + leave_flag = True + + if leave_flag: break - elif dt_from == orig_dt_from: - d2 = datetime(dt_from.year, dt_from.month, dt_from.day, int(math.floor(hour_to)), int((hour_to%1) * 60)) - hours += (context_tz.localize(d2) - utc.localize(d1)).seconds else: + d1 = dt_from d2 = datetime(dt_from.year, dt_from.month, dt_from.day, int(math.floor(hour_to)), int((hour_to%1) * 60)) - hours += (d2 - d1).seconds - - dt_from += timedelta(days=1) - dt_from = datetime(dt_from.year, dt_from.month, dt_from.day) - - return hours / 3600 + + if hours != 0.0:#For first time of the loop only,hours will be 0 + d1 = datetime(dt_from.year, dt_from.month, dt_from.day, int(math.floor(current_hour)), int((current_hour%1) * 60)) + + if dt_from.day == dt_to.day: + if hour_from <= dt_to.hour <= hour_to: + d2 = dt_to + dt_from = d2 + hours += (d2-d1).seconds + dt_from = datetime(dt_from.year, dt_from.month, dt_from.day, int(math.floor(current_hour)), int((current_hour%1) * 60)) + timedelta(days=1) + current_hour = 0.0 + + return (hours/3600) resource_calendar()