[FIX] project_issue, resource: fixed computation of hours / days to open (assign) or close an issue. Those fields now have a conditional store, because they were not recomputed even when changing date_open and date_closed. Changing the stage now correctly changes the date_closed. Also added some fixes in resource module, the date was not correctly taken into account when computing the number of working hours between two dates.
This commit is contained in:
parent
f062eec639
commit
622b52d262
|
@ -25,9 +25,11 @@ from openerp import api
|
||||||
from openerp import SUPERUSER_ID
|
from openerp import SUPERUSER_ID
|
||||||
from openerp import tools
|
from openerp import tools
|
||||||
from openerp.osv import fields, osv, orm
|
from openerp.osv import fields, osv, orm
|
||||||
|
from openerp.tools import DEFAULT_SERVER_DATETIME_FORMAT
|
||||||
from openerp.tools import html2plaintext
|
from openerp.tools import html2plaintext
|
||||||
from openerp.tools.translate import _
|
from openerp.tools.translate import _
|
||||||
|
|
||||||
|
|
||||||
class project_issue_version(osv.Model):
|
class project_issue_version(osv.Model):
|
||||||
_name = "project.issue.version"
|
_name = "project.issue.version"
|
||||||
_order = "name desc"
|
_order = "name desc"
|
||||||
|
@ -129,73 +131,51 @@ class project_issue(osv.Model):
|
||||||
@return: difference between current date and log date
|
@return: difference between current date and log date
|
||||||
@param context: A standard dictionary for contextual values
|
@param context: A standard dictionary for contextual values
|
||||||
"""
|
"""
|
||||||
cal_obj = self.pool.get('resource.calendar')
|
Calendar = self.pool['resource.calendar']
|
||||||
res_obj = self.pool.get('resource.resource')
|
|
||||||
|
|
||||||
res = {}
|
res = dict.fromkeys(ids, dict())
|
||||||
for issue in self.browse(cr, uid, ids, context=context):
|
for issue in self.browse(cr, uid, ids, context=context):
|
||||||
|
values = {
|
||||||
|
'day_open': 0.0, 'day_close': 0.0,
|
||||||
|
'working_hours_open': 0.0, 'working_hours_close': 0.0,
|
||||||
|
'days_since_creation': 0.0, 'inactivity_days': 0.0,
|
||||||
|
}
|
||||||
# if the working hours on the project are not defined, use default ones (8 -> 12 and 13 -> 17 * 5), represented by None
|
# if the working hours on the project are not defined, use default ones (8 -> 12 and 13 -> 17 * 5), represented by None
|
||||||
if not issue.project_id or not issue.project_id.resource_calendar_id:
|
calendar_id = None
|
||||||
working_hours = None
|
if issue.project_id and issue.project_id.resource_calendar_id:
|
||||||
|
calendar_id = issue.project_id.resource_calendar_id.id
|
||||||
|
|
||||||
|
dt_create_date = datetime.strptime(issue.create_date, DEFAULT_SERVER_DATETIME_FORMAT)
|
||||||
|
|
||||||
|
if issue.date_open:
|
||||||
|
dt_date_open = datetime.strptime(issue.date_open, DEFAULT_SERVER_DATETIME_FORMAT)
|
||||||
|
values['day_open'] = (dt_date_open - dt_create_date).total_seconds() / (24.0 * 3600)
|
||||||
|
values['working_hours_open'] = Calendar._interval_hours_get(
|
||||||
|
cr, uid, calendar_id, dt_create_date, dt_date_open,
|
||||||
|
timezone_from_uid=issue.user_id.id or uid,
|
||||||
|
exclude_leaves=False, context=context)
|
||||||
|
|
||||||
|
if issue.date_closed:
|
||||||
|
dt_date_closed = datetime.strptime(issue.date_closed, DEFAULT_SERVER_DATETIME_FORMAT)
|
||||||
|
values['day_close'] = (dt_date_closed - dt_create_date).total_seconds() / (24.0 * 3600)
|
||||||
|
values['working_hours_close'] = Calendar._interval_hours_get(
|
||||||
|
cr, uid, calendar_id, dt_create_date, dt_date_closed,
|
||||||
|
timezone_from_uid=issue.user_id.id or uid,
|
||||||
|
exclude_leaves=False, context=context)
|
||||||
|
|
||||||
|
days_since_creation = datetime.today() - dt_create_date
|
||||||
|
values['days_since_creation'] = days_since_creation.days
|
||||||
|
if issue.date_action_last:
|
||||||
|
inactive_days = datetime.today() - datetime.strptime(issue.date_action_last, DEFAULT_SERVER_DATETIME_FORMAT)
|
||||||
|
elif issue.date_last_stage_update:
|
||||||
|
inactive_days = datetime.today() - datetime.strptime(issue.date_last_stage_update, DEFAULT_SERVER_DATETIME_FORMAT)
|
||||||
else:
|
else:
|
||||||
working_hours = issue.project_id.resource_calendar_id.id
|
inactive_days = datetime.today() - datetime.strptime(issue.create_date, DEFAULT_SERVER_DATETIME_FORMAT)
|
||||||
|
values['inactivity_days'] = inactive_days.days
|
||||||
|
|
||||||
res[issue.id] = {}
|
# filter only required values
|
||||||
for field in fields:
|
for field in fields:
|
||||||
duration = 0
|
res[issue.id][field] = values[field]
|
||||||
ans = False
|
|
||||||
hours = 0
|
|
||||||
|
|
||||||
date_create = datetime.strptime(issue.create_date, "%Y-%m-%d %H:%M:%S")
|
|
||||||
if field in ['working_hours_open','day_open']:
|
|
||||||
if issue.date_open:
|
|
||||||
date_open = datetime.strptime(issue.date_open, "%Y-%m-%d %H:%M:%S")
|
|
||||||
ans = date_open - date_create
|
|
||||||
date_until = issue.date_open
|
|
||||||
#Calculating no. of working hours to open the issue
|
|
||||||
hours = cal_obj._interval_hours_get(cr, uid, working_hours,
|
|
||||||
date_create,
|
|
||||||
date_open,
|
|
||||||
timezone_from_uid=issue.user_id.id or uid,
|
|
||||||
exclude_leaves=False,
|
|
||||||
context=context)
|
|
||||||
elif field in ['working_hours_close','day_close']:
|
|
||||||
if issue.date_closed:
|
|
||||||
date_close = datetime.strptime(issue.date_closed, "%Y-%m-%d %H:%M:%S")
|
|
||||||
date_until = issue.date_closed
|
|
||||||
ans = date_close - date_create
|
|
||||||
#Calculating no. of working hours to close the issue
|
|
||||||
hours = cal_obj._interval_hours_get(cr, uid, working_hours,
|
|
||||||
date_create,
|
|
||||||
date_close,
|
|
||||||
timezone_from_uid=issue.user_id.id or uid,
|
|
||||||
exclude_leaves=False,
|
|
||||||
context=context)
|
|
||||||
elif field in ['days_since_creation']:
|
|
||||||
if issue.create_date:
|
|
||||||
days_since_creation = datetime.today() - datetime.strptime(issue.create_date, "%Y-%m-%d %H:%M:%S")
|
|
||||||
res[issue.id][field] = days_since_creation.days
|
|
||||||
continue
|
|
||||||
|
|
||||||
elif field in ['inactivity_days']:
|
|
||||||
res[issue.id][field] = 0
|
|
||||||
if issue.date_action_last:
|
|
||||||
inactive_days = datetime.today() - datetime.strptime(issue.date_action_last, '%Y-%m-%d %H:%M:%S')
|
|
||||||
res[issue.id][field] = inactive_days.days
|
|
||||||
continue
|
|
||||||
if ans:
|
|
||||||
resource_id = False
|
|
||||||
if issue.user_id:
|
|
||||||
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)
|
|
||||||
|
|
||||||
if field in ['working_hours_open','working_hours_close']:
|
|
||||||
res[issue.id][field] = hours
|
|
||||||
elif field in ['day_open','day_close']:
|
|
||||||
res[issue.id][field] = duration
|
|
||||||
|
|
||||||
return res
|
return res
|
||||||
|
|
||||||
|
@ -230,11 +210,12 @@ class project_issue(osv.Model):
|
||||||
if work.task_id:
|
if work.task_id:
|
||||||
issues += issue_pool.search(cr, uid, [('task_id','=',work.task_id.id)])
|
issues += issue_pool.search(cr, uid, [('task_id','=',work.task_id.id)])
|
||||||
return issues
|
return issues
|
||||||
|
|
||||||
_columns = {
|
_columns = {
|
||||||
'id': fields.integer('ID', readonly=True),
|
'id': fields.integer('ID', readonly=True),
|
||||||
'name': fields.char('Issue', required=True),
|
'name': fields.char('Issue', required=True),
|
||||||
'active': fields.boolean('Active', required=False),
|
'active': fields.boolean('Active', required=False),
|
||||||
'create_date': fields.datetime('Creation Date', readonly=True,select=True),
|
'create_date': fields.datetime('Creation Date', readonly=True, select=True),
|
||||||
'write_date': fields.datetime('Update Date', readonly=True),
|
'write_date': fields.datetime('Update Date', readonly=True),
|
||||||
'days_since_creation': fields.function(_compute_day, string='Days since creation date', \
|
'days_since_creation': fields.function(_compute_day, string='Days since creation date', \
|
||||||
multi='compute_day', type="integer", help="Difference in days between creation date and current date"),
|
multi='compute_day', type="integer", help="Difference in days between creation date and current date"),
|
||||||
|
@ -254,9 +235,9 @@ class project_issue(osv.Model):
|
||||||
required=False),
|
required=False),
|
||||||
'email_from': fields.char('Email', size=128, help="These people will receive email.", select=1),
|
'email_from': fields.char('Email', size=128, help="These people will receive email.", select=1),
|
||||||
'email_cc': fields.char('Watchers Emails', size=256, help="These email addresses will be added to the CC field of all inbound and outbound emails for this record before being sent. Separate multiple email addresses with a comma"),
|
'email_cc': fields.char('Watchers Emails', size=256, help="These email addresses will be added to the CC field of all inbound and outbound emails for this record before being sent. Separate multiple email addresses with a comma"),
|
||||||
'date_open': fields.datetime('Opened', readonly=True,select=True),
|
'date_open': fields.datetime('Assigned', readonly=True, select=True),
|
||||||
# Project Issue fields
|
# Project Issue fields
|
||||||
'date_closed': fields.datetime('Closed', readonly=True,select=True),
|
'date_closed': fields.datetime('Closed', readonly=True, select=True),
|
||||||
'date': fields.datetime('Date'),
|
'date': fields.datetime('Date'),
|
||||||
'date_last_stage_update': fields.datetime('Last Stage Update', select=True),
|
'date_last_stage_update': fields.datetime('Last Stage Update', select=True),
|
||||||
'channel': fields.char('Channel', help="Communication channel."),
|
'channel': fields.char('Channel', help="Communication channel."),
|
||||||
|
@ -269,17 +250,21 @@ class project_issue(osv.Model):
|
||||||
'project_id': fields.many2one('project.project', 'Project', track_visibility='onchange', select=True),
|
'project_id': fields.many2one('project.project', 'Project', track_visibility='onchange', select=True),
|
||||||
'duration': fields.float('Duration'),
|
'duration': fields.float('Duration'),
|
||||||
'task_id': fields.many2one('project.task', 'Task', domain="[('project_id','=',project_id)]"),
|
'task_id': fields.many2one('project.task', 'Task', domain="[('project_id','=',project_id)]"),
|
||||||
'day_open': fields.function(_compute_day, string='Days to Open', \
|
'day_open': fields.function(_compute_day, string='Days to Assign',
|
||||||
multi='compute_day', type="float", store=True),
|
multi='compute_day', type="float",
|
||||||
'day_close': fields.function(_compute_day, string='Days to Close', \
|
store={'project.issue': (lambda self, cr, uid, ids, c={}: ids, ['date_open'], 10)}),
|
||||||
multi='compute_day', type="float", store=True),
|
'day_close': fields.function(_compute_day, string='Days to Close',
|
||||||
|
multi='compute_day', type="float",
|
||||||
|
store={'project.issue': (lambda self, cr, uid, ids, c={}: ids, ['date_closed'], 10)}),
|
||||||
'user_id': fields.many2one('res.users', 'Assigned to', required=False, select=1, track_visibility='onchange'),
|
'user_id': fields.many2one('res.users', 'Assigned to', required=False, select=1, track_visibility='onchange'),
|
||||||
'working_hours_open': fields.function(_compute_day, string='Working Hours to Open the Issue', \
|
'working_hours_open': fields.function(_compute_day, string='Working Hours to assign the Issue',
|
||||||
multi='compute_day', type="float", store=True),
|
multi='compute_day', type="float",
|
||||||
'working_hours_close': fields.function(_compute_day, string='Working Hours to Close the Issue', \
|
store={'project.issue': (lambda self, cr, uid, ids, c={}: ids, ['date_open'], 10)}),
|
||||||
multi='compute_day', type="float", store=True),
|
'working_hours_close': fields.function(_compute_day, string='Working Hours to close the Issue',
|
||||||
'inactivity_days': fields.function(_compute_day, string='Days since last action', \
|
multi='compute_day', type="float",
|
||||||
multi='compute_day', type="integer", help="Difference in days between last action and current date"),
|
store={'project.issue': (lambda self, cr, uid, ids, c={}: ids, ['date_closed'], 10)}),
|
||||||
|
'inactivity_days': fields.function(_compute_day, string='Days since last action',
|
||||||
|
multi='compute_day', type="integer", help="Difference in days between last action and current date"),
|
||||||
'color': fields.integer('Color Index'),
|
'color': fields.integer('Color Index'),
|
||||||
'user_email': fields.related('user_id', 'email', type='char', string='User Email', readonly=True),
|
'user_email': fields.related('user_id', 'email', type='char', string='User Email', readonly=True),
|
||||||
'date_action_last': fields.datetime('Last Action', readonly=1),
|
'date_action_last': fields.datetime('Last Action', readonly=1),
|
||||||
|
@ -312,13 +297,16 @@ class project_issue(osv.Model):
|
||||||
default = {}
|
default = {}
|
||||||
default = default.copy()
|
default = default.copy()
|
||||||
default.update(name=_('%s (copy)') % (issue['name']))
|
default.update(name=_('%s (copy)') % (issue['name']))
|
||||||
return super(project_issue, self).copy(cr, uid, id, default=default,
|
return super(project_issue, self).copy(cr, uid, id, default=default, context=context)
|
||||||
context=context)
|
|
||||||
|
|
||||||
def create(self, cr, uid, vals, context=None):
|
def create(self, cr, uid, vals, context=None):
|
||||||
context = dict(context or {})
|
context = dict(context or {})
|
||||||
if vals.get('project_id') and not context.get('default_project_id'):
|
if vals.get('project_id') and not context.get('default_project_id'):
|
||||||
context['default_project_id'] = vals.get('project_id')
|
context['default_project_id'] = vals.get('project_id')
|
||||||
|
if vals.get('user_id'):
|
||||||
|
vals['date_open'] = fields.datetime.now()
|
||||||
|
if 'stage_id' in vals:
|
||||||
|
vals.update(self.onchange_stage_id(cr, uid, None, vals.get('stage_id'), context=context)['value'])
|
||||||
|
|
||||||
# context: no_log, because subtype already handle this
|
# context: no_log, because subtype already handle this
|
||||||
create_context = dict(context, mail_create_nolog=True)
|
create_context = dict(context, mail_create_nolog=True)
|
||||||
|
@ -327,12 +315,13 @@ class project_issue(osv.Model):
|
||||||
def write(self, cr, uid, ids, vals, context=None):
|
def write(self, cr, uid, ids, vals, context=None):
|
||||||
# stage change: update date_last_stage_update
|
# stage change: update date_last_stage_update
|
||||||
if 'stage_id' in vals:
|
if 'stage_id' in vals:
|
||||||
|
vals.update(self.onchange_stage_id(cr, uid, ids, vals.get('stage_id'), context=context)['value'])
|
||||||
vals['date_last_stage_update'] = fields.datetime.now()
|
vals['date_last_stage_update'] = fields.datetime.now()
|
||||||
if 'kanban_state' not in vals:
|
if 'kanban_state' not in vals:
|
||||||
vals['kanban_state'] = 'normal'
|
vals['kanban_state'] = 'normal'
|
||||||
# user_id change: update date_start
|
# user_id change: update date_start
|
||||||
if vals.get('user_id'):
|
if vals.get('user_id'):
|
||||||
vals['date_start'] = fields.datetime.now()
|
vals['date_open'] = fields.datetime.now()
|
||||||
|
|
||||||
return super(project_issue, self).write(cr, uid, ids, vals, context)
|
return super(project_issue, self).write(cr, uid, ids, vals, context)
|
||||||
|
|
||||||
|
@ -363,6 +352,14 @@ class project_issue(osv.Model):
|
||||||
# Stage management
|
# Stage management
|
||||||
# -------------------------------------------------------
|
# -------------------------------------------------------
|
||||||
|
|
||||||
|
def onchange_stage_id(self, cr, uid, ids, stage_id, context=None):
|
||||||
|
if not stage_id:
|
||||||
|
return {'value': {}}
|
||||||
|
stage = self.pool['project.task.type'].browse(cr, uid, stage_id, context=context)
|
||||||
|
if stage.fold:
|
||||||
|
return {'value': {'date_closed': fields.datetime.now()}}
|
||||||
|
return {'value': {'date_closed': False}}
|
||||||
|
|
||||||
def stage_find(self, cr, uid, cases, section_id, domain=[], order='sequence', context=None):
|
def stage_find(self, cr, uid, cases, section_id, domain=[], order='sequence', context=None):
|
||||||
""" Override of the base.stage method
|
""" Override of the base.stage method
|
||||||
Parameter of the stage search taken from the issue:
|
Parameter of the stage search taken from the issue:
|
||||||
|
|
|
@ -90,16 +90,18 @@
|
||||||
<field name="description" placeholder="Add an internal note..." groups="base.group_user"/>
|
<field name="description" placeholder="Add an internal note..." groups="base.group_user"/>
|
||||||
</page>
|
</page>
|
||||||
<page string="Extra Info" groups="project.group_project_manager,project.group_project_user">
|
<page string="Extra Info" groups="project.group_project_manager,project.group_project_user">
|
||||||
<group string="Statistics">
|
<group>
|
||||||
<field name="day_open"/>
|
<group string="Statistics">
|
||||||
<field name="day_close"/>
|
<field name="day_open"/>
|
||||||
<field name="working_hours_open" widget="float_time"/>
|
<field name="day_close"/>
|
||||||
<field name="working_hours_close" widget="float_time"/>
|
<field name="working_hours_open" widget="float_time"/>
|
||||||
<field name="inactivity_days"/>
|
<field name="working_hours_close" widget="float_time"/>
|
||||||
<field name="days_since_creation"/>
|
<field name="inactivity_days"/>
|
||||||
</group>
|
<field name="days_since_creation"/>
|
||||||
<group string="Status" groups="base.group_no_one">
|
</group>
|
||||||
<field name="active"/>
|
<group string="Status" groups="base.group_no_one">
|
||||||
|
<field name="active"/>
|
||||||
|
</group>
|
||||||
</group>
|
</group>
|
||||||
</page>
|
</page>
|
||||||
</notebook>
|
</notebook>
|
||||||
|
|
|
@ -329,7 +329,8 @@ class resource_calendar(osv.osv):
|
||||||
# no calendar: try to use the default_interval, then return directly
|
# no calendar: try to use the default_interval, then return directly
|
||||||
if id is None:
|
if id is None:
|
||||||
if default_interval:
|
if default_interval:
|
||||||
intervals.append((start_dt.replace(hour=default_interval[0]), start_dt.replace(hour=default_interval[1])))
|
working_interval = (start_dt.replace(hour=default_interval[0], minute=0, second=0), start_dt.replace(hour=default_interval[1], minute=0, second=0))
|
||||||
|
intervals = self.interval_remove_leaves(working_interval, work_limits)
|
||||||
return intervals
|
return intervals
|
||||||
|
|
||||||
working_intervals = []
|
working_intervals = []
|
||||||
|
@ -371,10 +372,16 @@ class resource_calendar(osv.osv):
|
||||||
resource_id=None, default_interval=None, context=None):
|
resource_id=None, default_interval=None, context=None):
|
||||||
hours = 0.0
|
hours = 0.0
|
||||||
for day in rrule.rrule(rrule.DAILY, dtstart=start_dt,
|
for day in rrule.rrule(rrule.DAILY, dtstart=start_dt,
|
||||||
until=end_dt + datetime.timedelta(days=1),
|
until=(end_dt + datetime.timedelta(days=1)).replace(hour=0, minute=0, second=0),
|
||||||
byweekday=self.get_weekdays(cr, uid, id, context=context)):
|
byweekday=self.get_weekdays(cr, uid, id, context=context)):
|
||||||
|
day_start_dt = day.replace(hour=0, minute=0, second=0)
|
||||||
|
if start_dt and day.date() == start_dt.date():
|
||||||
|
day_start_dt = start_dt
|
||||||
|
day_end_dt = day.replace(hour=23, minute=59, second=59)
|
||||||
|
if end_dt and day.date() == end_dt.date():
|
||||||
|
day_end_dt = end_dt
|
||||||
hours += self.get_working_hours_of_date(
|
hours += self.get_working_hours_of_date(
|
||||||
cr, uid, id, start_dt=day,
|
cr, uid, id, start_dt=day_start_dt, end_dt=day_end_dt,
|
||||||
compute_leaves=compute_leaves, resource_id=resource_id,
|
compute_leaves=compute_leaves, resource_id=resource_id,
|
||||||
default_interval=default_interval,
|
default_interval=default_interval,
|
||||||
context=context)
|
context=context)
|
||||||
|
|
Loading…
Reference in New Issue