_name = "project.issue"
_description = "Project Issue"
_order = "priority, create_date desc"
- _inherit = ['mail.thread']
-
- def case_open(self, cr, uid, ids, *args):
- """
- @param self: The object pointer
- @param cr: the current row, from the database cursor,
- @param uid: the current user’s ID for security checks,
- @param ids: List of case's Ids
- @param *args: Give Tuple Value
- """
-
- res = super(project_issue, self).case_open(cr, uid, ids, *args)
- self.write(cr, uid, ids, {'date_open': time.strftime('%Y-%m-%d %H:%M:%S'), 'user_id' : uid})
- for (id, name) in self.name_get(cr, uid, ids):
- message = _("Issue '%s' has been opened.") % name
- self.log(cr, uid, id, message)
- return res
-
- def case_close(self, cr, uid, ids, *args):
- """
- @param self: The object pointer
- @param cr: the current row, from the database cursor,
- @param uid: the current user’s ID for security checks,
- @param ids: List of case's Ids
- @param *args: Give Tuple Value
- """
-
- res = super(project_issue, self).case_close(cr, uid, ids, *args)
- for (id, name) in self.name_get(cr, uid, ids):
- message = _("Issue '%s' has been closed.") % name
- self.log(cr, uid, id, message)
- return res
+ _inherit = ['ir.needaction_mixin', 'mail.thread']
def _compute_day(self, cr, uid, ids, fields, args, context=None):
"""
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_create = datetime.strptime(issue.create_date, "%Y-%m-%d %H:%M:%S")
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, issue.project_id.resource_calendar_id.id,
- datetime.strptime(issue.create_date, '%Y-%m-%d %H:%M:%S'),
- datetime.strptime(issue.date_open, '%Y-%m-%d %H:%M:%S'))
+ if issue.project_id.resource_calendar_id:
+ hours = cal_obj.interval_hours_get(cr, uid, issue.project_id.resource_calendar_id.id,
+ date_create,
+ date_open)
elif field in ['working_hours_close','day_close']:
if issue.date_closed:
- date_create = datetime.strptime(issue.create_date, "%Y-%m-%d %H:%M:%S")
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, issue.project_id.resource_calendar_id.id,
- datetime.strptime(issue.create_date, '%Y-%m-%d %H:%M:%S'),
- datetime.strptime(issue.date_closed, '%Y-%m-%d %H:%M:%S'))
+ if issue.project_id.resource_calendar_id:
+ hours = cal_obj.interval_hours_get(cr, uid, issue.project_id.resource_calendar_id.id,
+ date_create,
+ date_close)
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")
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, datetime.strptime(issue.create_date, '%Y-%m-%d %H:%M:%S'), duration, resource=resource_id)
+
+ 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 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] = abs(float(duration))
+
+ return res
+
+ def _hours_get(self, cr, uid, ids, field_names, args, context=None):
+ task_pool = self.pool.get('project.task')
+ res = {}
+ for issue in self.browse(cr, uid, ids, context=context):
+ progress = 0.0
+ if issue.task_id:
+ progress = task_pool._hours_get(cr, uid, [issue.task_id.id], field_names, args, context=context)[issue.task_id.id]['progress']
+ res[issue.id] = {'progress' : progress}
return res
+ def _get_project(self, cr, uid, context=None):
+ user = self.pool.get('res.users').browse(cr, uid, uid, context=context)
+ if user.context_project_id:
+ return user.context_project_id.id
+ return False
+
+ def on_change_project(self, cr, uid, ids, project_id, context=None):
+ return {}
+
def _get_issue_task(self, cr, uid, ids, context=None):
issues = []
issue_pool = self.pool.get('project.issue')
issues += issue_pool.search(cr, uid, [('task_id','=',work.task_id.id)])
return issues
- def _hours_get(self, cr, uid, ids, field_names, args, context=None):
- task_pool = self.pool.get('project.task')
- res = {}
- for issue in self.browse(cr, uid, ids, context=context):
- progress = 0.0
- if issue.task_id:
- progress = task_pool._hours_get(cr, uid, [issue.task_id.id], field_names, args, context=context)[issue.task_id.id]['progress']
- res[issue.id] = {'progress' : progress}
- return res
-
_columns = {
'id': fields.integer('ID', readonly=True),
'name': fields.char('Issue', size=128, required=True),
select=True, help='Sales team to which Case belongs to.\
Define Responsible user and Email account for mail gateway.'),
'partner_id': fields.many2one('res.partner', 'Partner', select=1),
- 'partner_address_id': fields.many2one('res.partner.address', 'Partner Contact', \
- domain="[('partner_id','=',partner_id)]"),
'company_id': fields.many2one('res.company', 'Company'),
'description': fields.text('Description'),
'state': fields.selection([('draft', 'New'), ('open', 'In Progress'), ('cancel', 'Cancelled'), ('done', 'Done'),('pending', 'Pending'), ], 'State', size=16, readonly=True,
'date': fields.datetime('Date'),
'channel_id': fields.many2one('crm.case.channel', 'Channel', help="Communication channel."),
'categ_id': fields.many2one('crm.case.categ', 'Category', domain="[('object_id.model', '=', 'crm.project.bug')]"),
- 'priority': fields.selection(crm.AVAILABLE_PRIORITIES, 'Priority'),
+ 'priority': fields.selection(crm.AVAILABLE_PRIORITIES, 'Priority', select=True),
'version_id': fields.many2one('project.issue.version', 'Version'),
- 'type_id': fields.many2one ('project.task.type', 'Resolution', domain="[('project_ids', '=', project_id)]"),
+ 'type_id': fields.many2one ('project.task.type', 'Stages', domain="[('project_ids', '=', project_id)]"),
'project_id':fields.many2one('project.project', 'Project'),
'duration': fields.float('Duration'),
'task_id': fields.many2one('project.task', 'Task', domain="[('project_id','=',project_id)]"),
}),
}
- def _get_project(self, cr, uid, context=None):
- user = self.pool.get('res.users').browse(cr, uid, uid, context=context)
- if user.context_project_id:
- return user.context_project_id.id
- return False
-
- def on_change_project(self, cr, uid, ids, project_id, context=None):
- return {}
-
_defaults = {
'active': 1,
'partner_id': crm.crm_case._get_default_partner,
- 'partner_address_id': crm.crm_case._get_default_partner_address,
'email_from': crm.crm_case._get_default_email,
'state': 'draft',
'section_id': crm.crm_case._get_section,
return self.set_priority(cr, uid, ids, '3')
def convert_issue_task(self, cr, uid, ids, context=None):
+ if context is None:
+ context = {}
+
case_obj = self.pool.get('project.issue')
data_obj = self.pool.get('ir.model.data')
task_obj = self.pool.get('project.task')
-
-
- if context is None:
- context = {}
-
+
result = data_obj._get_id(cr, uid, 'project', 'view_task_search_form')
res = data_obj.read(cr, uid, result, ['res_id'])
id2 = data_obj._get_id(cr, uid, 'project', 'view_task_form2')
'name': bug.name,
'partner_id': bug.partner_id.id,
'description':bug.description,
- 'date': bug.date,
+ 'date_deadline': bug.date,
'project_id': bug.project_id.id,
- 'priority': bug.priority,
+ # priority must be in ['0','1','2','3','4'], while bug.priority is in ['1','2','3','4','5']
+ 'priority': str(int(bug.priority) - 1),
'user_id': bug.user_id.id,
'planned_hours': 0.0,
})
-
vals = {
'task_id': new_task_id,
'state':'pending'
}
- case_obj.write(cr, uid, [bug.id], vals)
+ self.convert_to_task_send_note(cr, uid, [bug.id], context=context)
+ case_obj.write(cr, uid, [bug.id], vals, context=context)
+ self.case_pending_send_note(cr, uid, [bug.id], context=context)
return {
'name': _('Tasks'),
def convert_to_bug(self, cr, uid, ids, context=None):
return self._convert(cr, uid, ids, 'bug_categ', context=context)
- def next_type(self, cr, uid, ids, *args):
+ def next_type(self, cr, uid, ids, context=None):
for task in self.browse(cr, uid, ids):
typeid = task.type_id.id
types = map(lambda x:x.id, task.project_id.type_ids or [])
if types:
if not typeid:
- self.write(cr, uid, task.id, {'type_id': types[0]})
+ self.write(cr, uid, [task.id], {'type_id': types[0]})
elif typeid and typeid in types and types.index(typeid) != len(types)-1 :
index = types.index(typeid)
- self.write(cr, uid, task.id, {'type_id': types[index+1]})
+ self.write(cr, uid, [task.id], {'type_id': types[index+1]})
return True
- def prev_type(self, cr, uid, ids, *args):
+ def prev_type(self, cr, uid, ids, context=None):
for task in self.browse(cr, uid, ids):
typeid = task.type_id.id
types = map(lambda x:x.id, task.project_id and task.project_id.type_ids or [])
if types:
if typeid and typeid in types:
index = types.index(typeid)
- self.write(cr, uid, task.id, {'type_id': index and types[index-1] or False})
+ self.write(cr, uid, [task.id], {'type_id': index and types[index-1] or False})
return True
+ def write(self, cr, uid, ids, vals, context=None):
+ #Update last action date every time the user change the stage, the state or send a new email
+ logged_fields = ['type_id', 'state', 'message_ids']
+ if any([field in vals for field in logged_fields]):
+ vals['date_action_last'] = time.strftime('%Y-%m-%d %H:%M:%S')
+ if vals.get('type_id', False):
+ stage = self.pool.get('project.task.type').browse(cr, uid, vals['type_id'], context=context)
+ self.message_append_note(cr, uid, ids, body=_("Stage changed to <b>%s</b>.") % stage.name, context=context)
+ return super(project_issue, self).write(cr, uid, ids, vals, context)
def onchange_task_id(self, cr, uid, ids, task_id, context=None):
result = {}
task = self.pool.get('project.task').browse(cr, uid, task_id, context=context)
return {'value':{'user_id': task.user_id.id,}}
- def case_escalate(self, cr, uid, ids, *args):
- """Escalates case to top level
- @param self: The object pointer
- @param cr: the current row, from the database cursor,
- @param uid: the current user’s ID for security checks,
- @param ids: List of case Ids
- @param *args: Tuple Value for additional Params
+ def case_reset(self, cr, uid, ids, context=None):
+ """Resets case as draft
"""
+ res = super(project_issue, self).case_reset(cr, uid, ids, context)
+ self.write(cr, uid, ids, {'date_open': False, 'date_closed': False})
+ return res
+
+ def create(self, cr, uid, vals, context=None):
+ obj_id = super(project_issue, self).create(cr, uid, vals, context=context)
+ self.create_send_note(cr, uid, [obj_id], context=context)
+ return obj_id
+
+ def case_open(self, cr, uid, ids, context=None):
+ res = super(project_issue, self).case_open(cr, uid, ids, context)
+ self.write(cr, uid, ids, {'date_open': time.strftime('%Y-%m-%d %H:%M:%S'), 'user_id' : uid})
+ return res
+
+ def case_escalate(self, cr, uid, ids, context=None):
cases = self.browse(cr, uid, ids)
for case in cases:
- data = {}
+ data = {'state' : 'draft'}
if case.project_id.project_escalation_id:
data['project_id'] = case.project_id.project_escalation_id.id
if case.project_id.project_escalation_id.user_id:
else:
raise osv.except_osv(_('Warning !'), _('You cannot escalate this issue.\nThe relevant Project has not configured the Escalation Project!'))
self.write(cr, uid, [case.id], data)
- self.message_append(cr, uid, cases, _('Escalate'))
+ self.case_escalate_send_note(cr, uid, [case.id], context)
return True
def message_new(self, cr, uid, msg, custom_values=None, context=None):
return res_id
def message_update(self, cr, uid, ids, msg, vals=None, default_act='pending', context=None):
-
if vals is None:
vals = {}
default['name'] = issue['name'] + _(' (copy)')
return super(project_issue, self).copy(cr, uid, id, default=default,
context=context)
+
+ # -------------------------------------------------------
+ # OpenChatter methods and notifications
+ # -------------------------------------------------------
+
+ def get_needaction_user_ids(self, cr, uid, ids, context=None):
+ result = dict.fromkeys(ids, [])
+ for obj in self.browse(cr, uid, ids, context=context):
+ if obj.state == 'draft' and obj.user_id:
+ result[obj.id] = [obj.user_id.id]
+ return result
+
+ def message_get_subscribers(self, cr, uid, ids, context=None):
+ sub_ids = self.message_get_subscribers_ids(cr, uid, ids, context=context);
+ for obj in self.browse(cr, uid, ids, context=context):
+ if obj.user_id:
+ sub_ids.append(obj.user_id.id)
+ return self.pool.get('res.users').read(cr, uid, sub_ids, context=context)
+
+ def case_get_note_msg_prefix(self, cr, uid, id, context=None):
+ return 'Project issue '
+
+ def convert_to_task_send_note(self, cr, uid, ids, context=None):
+ message = _("Project issue has been <b>converted</b> in to task.")
+ return self.message_append_note(cr, uid, ids, body=message, context=context)
+
+ def create_send_note(self, cr, uid, ids, context=None):
+ message = _("Project issue has been <b>created</b>.")
+ return self.message_append_note(cr, uid, ids, body=message, context=context)
+
+ def case_escalate_send_note(self, cr, uid, ids, context=None):
+ for obj in self.browse(cr, uid, ids, context=context):
+ if obj.project_id:
+ message = _("has been <b>escalated</b> to <em>'%s'</em>.") % (obj.project_id.name)
+ obj.message_append_note(body=message, context=context)
+ else:
+ message = _("has been <b>escalated</b>.")
+ obj.message_append_note(body=message, context=context)
+ return True
project_issue()
class project(osv.osv):
_inherit = "project.project"
_columns = {
- 'resource_calendar_id' : fields.many2one('resource.calendar', 'Working Time', help="Timetable working hours to adjust the gantt diagram report", states={'close':[('readonly',True)], 'cancelled':[('readonly',True)]}),
'project_escalation_id' : fields.many2one('project.project','Project Escalation', help='If any issue is escalated from the current Project, it will be listed under the project selected here.', states={'close':[('readonly',True)], 'cancelled':[('readonly',True)]}),
'reply_to' : fields.char('Reply-To Email Address', size=256)
}
def _check_escalation(self, cr, uid, ids, context=None):
- project_obj = self.browse(cr, uid, ids[0], context=context)
- if project_obj.project_escalation_id:
- if project_obj.project_escalation_id.id == project_obj.id:
- return False
- return True
+ project_obj = self.browse(cr, uid, ids[0], context=context)
+ if project_obj.project_escalation_id:
+ if project_obj.project_escalation_id.id == project_obj.id:
+ return False
+ return True
_constraints = [
(_check_escalation, 'Error! You cannot assign escalation to the same project!', ['project_escalation_id'])