#
##############################################################################
-from base_status.base_stage import base_stage
-from crm import crm
+from openerp.addons.base_status.base_stage import base_stage
+from openerp.addons.crm import crm
from datetime import datetime
-from osv import fields,osv
-from tools.translate import _
+from openerp.osv import fields,osv
+from openerp.tools.translate import _
import binascii
import time
-import tools
+from openerp import tools
+from openerp.tools import html2plaintext
class project_issue_version(osv.osv):
_name = "project.issue.version"
}
project_issue_version()
-_ISSUE_STATE= [('draft', 'New'), ('open', 'In Progress'), ('cancel', 'Cancelled'), ('done', 'Done'),('pending', 'Pending')]
+_ISSUE_STATE = [('draft', 'New'), ('open', 'In Progress'), ('cancel', 'Cancelled'), ('done', 'Done'), ('pending', 'Pending')]
+
class project_issue(base_stage, osv.osv):
_name = "project.issue"
_order = "priority, create_date desc"
_inherit = ['mail.thread', 'ir.needaction_mixin']
+ _track = {
+ 'state': {
+ 'project_issue.mt_issue_new': lambda self, cr, uid, obj, ctx=None: obj['state'] == 'new',
+ 'project_issue.mt_issue_closed': lambda self, cr, uid, obj, ctx=None: obj['state'] == 'done',
+ 'project_issue.mt_issue_started': lambda self, cr, uid, obj, ctx=None: obj['state'] == 'open',
+ },
+ 'stage_id': {
+ 'project_issue.mt_issue_stage': lambda self, cr, uid, obj, ctx=None: obj['state'] not in ['new', 'done', 'open'],
+ },
+ 'kanban_state': {
+ 'project_issue.mt_issue_blocked': lambda self, cr, uid, obj, ctx=None: obj['kanban_state'] == 'blocked',
+ },
+ }
+
+ def create(self, cr, uid, vals, context=None):
+ if context is None:
+ context = {}
+ if not vals.get('stage_id'):
+ ctx = context.copy()
+ if vals.get('project_id'):
+ ctx['default_project_id'] = vals['project_id']
+ vals['stage_id'] = self._get_default_stage_id(cr, uid, context=ctx)
+ return super(project_issue, self).create(cr, uid, vals, context=context)
+
def _get_default_project_id(self, cr, uid, context=None):
""" Gives default project by checking if present in the context """
return self._resolve_project_id_from_context(cr, uid, context=context)
project_id = self._resolve_project_id_from_context(cr, uid, context=context)
if project_id:
search_domain += ['|', ('project_ids', '=', project_id)]
- search_domain += ['|', ('id', 'in', ids), ('case_default', '=', True)]
+ search_domain += [('id', 'in', ids)]
# perform search
stage_ids = stage_obj._search(cr, uid, search_domain, order=order, access_rights_uid=access_rights_uid, context=context)
result = stage_obj.name_get(cr, access_rights_uid, stage_ids, context=context)
Define Responsible user and Email account for mail gateway.'),
'partner_id': fields.many2one('res.partner', 'Contact', select=1),
'company_id': fields.many2one('res.company', 'Company'),
- 'description': fields.text('Description'),
+ 'description': fields.text('Private Note'),
'state': fields.related('stage_id', 'state', type="selection", store=True,
- selection=_ISSUE_STATE, string="State", readonly=True,
- help='The state is set to \'Draft\', when a case is created.\
- If the case is in progress the state is set to \'Open\'.\
- When the case is over, the state is set to \'Done\'.\
- If the case needs to be reviewed then the state is \
+ selection=_ISSUE_STATE, string="Status", readonly=True,
+ help='The status is set to \'Draft\', when a case is created.\
+ If the case is in progress the status is set to \'Open\'.\
+ When the case is over, the status is set to \'Done\'.\
+ If the case needs to be reviewed then the status is \
set to \'Pending\'.'),
+ 'kanban_state': fields.selection([('normal', 'Normal'),('blocked', 'Blocked'),('done', 'Ready for next stage')], 'Kanban State',
+ track_visibility='onchange',
+ help="A Issue's kanban state indicates special situations affecting it:\n"
+ " * Normal is the default situation\n"
+ " * Blocked indicates something is preventing the progress of this issue\n"
+ " * Ready for next stage indicates the issue is ready to be pulled to the next stage",
+ readonly=True, required=False),
'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"),
'date_open': fields.datetime('Opened', readonly=True,select=True),
'date_closed': fields.datetime('Closed', readonly=True,select=True),
'date': fields.datetime('Date'),
'channel_id': fields.many2one('crm.case.channel', 'Channel', help="Communication channel."),
- 'categ_ids': fields.many2many('project.category', string='Categories'),
+ 'categ_ids': fields.many2many('project.category', string='Tags'),
'priority': fields.selection(crm.AVAILABLE_PRIORITIES, 'Priority', select=True),
'version_id': fields.many2one('project.issue.version', 'Version'),
'stage_id': fields.many2one ('project.task.type', 'Stage',
- domain="['&', ('fold', '=', False), '|', ('project_ids', '=', project_id), ('case_default', '=', True)]"),
- 'project_id':fields.many2one('project.project', 'Project'),
+ track_visibility='onchange',
+ domain="['&', ('fold', '=', False), ('project_ids', '=', project_id)]"),
+ 'project_id':fields.many2one('project.project', 'Project', track_visibility='onchange'),
'duration': fields.float('Duration'),
'task_id': fields.many2one('project.task', 'Task', domain="[('project_id','=',project_id)]"),
'day_open': fields.function(_compute_day, string='Days to Open', \
multi='compute_day', type="float", store=True),
'day_close': fields.function(_compute_day, string='Days to Close', \
multi='compute_day', type="float", store=True),
- 'user_id': fields.many2one('res.users', 'Assigned to', required=False, select=1),
+ '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', \
multi='compute_day', type="float", store=True),
'working_hours_close': fields.function(_compute_day, string='Working Hours to Close the Issue', \
'active': 1,
'partner_id': lambda s, cr, uid, c: s._get_default_partner(cr, uid, c),
'email_from': lambda s, cr, uid, c: s._get_default_email(cr, uid, c),
- 'state': 'draft',
'stage_id': lambda s, cr, uid, c: s._get_default_stage_id(cr, uid, c),
'section_id': lambda s, cr, uid, c: s._get_default_section_id(cr, uid, c),
'company_id': lambda s, cr, uid, c: s.pool.get('res.company')._company_default_get(cr, uid, 'crm.helpdesk', context=c),
'priority': crm.AVAILABLE_PRIORITIES[2][0],
+ 'kanban_state': 'normal',
}
_group_by_full = {
})
vals = {
'task_id': new_task_id,
- 'state':'pending'
+ 'stage_id': self.stage_find(cr, uid, [bug], bug.project_id.id, [('state', '=', 'pending')], context=context),
}
- self.convert_to_task_send_note(cr, uid, [bug.id], context=context)
+ message = _("Project issue <b>converted</b> to task.")
+ self.message_post(cr, uid, [bug.id], body=message, 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'),
logged_fields = ['stage_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('project_id'):
- project_id = self.pool.get('project.project').browse(cr, uid, vals.get('project_id'), context=context)
- vals['message_follower_ids'] = [(4, follower.id) for follower in project_id.message_follower_ids]
return super(project_issue, self).write(cr, uid, ids, vals, context)
def onchange_task_id(self, cr, uid, ids, task_id, context=None):
if not task_id:
- return {'value':{}}
+ return {'value': {}}
task = self.pool.get('project.task').browse(cr, uid, task_id, context=context)
- return {'value':{'user_id': task.user_id.id,}}
+ return {'value': {'user_id': task.user_id.id, }}
def case_reset(self, cr, uid, ids, context=None):
"""Resets case as draft
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)
- project_id = self.browse(cr, uid, obj_id, context=context).project_id
- if project_id:
- followers = [follower.id for follower in project_id.message_follower_ids]
- self.message_subscribe(cr, uid, [obj_id], followers, context=context)
- self.create_send_note(cr, uid, [obj_id], context=context)
- return obj_id
-
# -------------------------------------------------------
# Stage management
# -------------------------------------------------------
+ def set_kanban_state_blocked(self, cr, uid, ids, context=None):
+ return self.write(cr, uid, ids, {'kanban_state': 'blocked'}, context=context)
+
+ def set_kanban_state_normal(self, cr, uid, ids, context=None):
+ return self.write(cr, uid, ids, {'kanban_state': 'normal'}, context=context)
+
+ def set_kanban_state_done(self, cr, uid, ids, context=None):
+ return self.write(cr, uid, ids, {'kanban_state': 'done'}, context=context)
+
def stage_find(self, cr, uid, cases, section_id, domain=[], order='sequence', context=None):
""" Override of the base.stage method
Parameter of the stage search taken from the issue:
# OR all section_ids and OR with case_default
search_domain = []
if section_ids:
- search_domain += [('|')] * len(section_ids)
+ search_domain += [('|')] * (len(section_ids)-1)
for section_id in section_ids:
search_domain.append(('project_ids', '=', section_id))
- search_domain.append(('case_default', '=', True))
- # AND with the domain in parameter
search_domain += list(domain)
# perform search, return the first found
stage_ids = self.pool.get('project.task.type').search(cr, uid, search_domain, order=order, context=context)
def case_cancel(self, cr, uid, ids, context=None):
""" Cancels case """
self.case_set(cr, uid, ids, 'cancelled', {'active': True}, context=context)
- self.case_cancel_send_note(cr, uid, ids, context=context)
return True
def case_escalate(self, cr, uid, ids, context=None):
else:
raise osv.except_osv(_('Warning!'), _('You cannot escalate this issue.\nThe relevant Project has not configured the Escalation Project!'))
self.case_set(cr, uid, ids, 'draft', data, context=context)
- self.case_escalate_send_note(cr, uid, [case.id], context=context)
return True
# -------------------------------------------------------
# Mail gateway
# -------------------------------------------------------
+ def message_get_reply_to(self, cr, uid, ids, context=None):
+ """ Override to get the reply_to of the parent project. """
+ return [issue.project_id.message_get_reply_to()[0] if issue.project_id else False
+ for issue in self.browse(cr, uid, ids, context=context)]
+
def message_new(self, cr, uid, msg, custom_values=None, context=None):
""" Overrides mail_thread message_new that is called by the mailgateway
through message_process.
if context is None: context = {}
context['state_to'] = 'draft'
- custom_values.update({
+ desc = html2plaintext(msg.get('body')) if msg.get('body') else ''
+
+ defaults = {
'name': msg.get('subject') or _("No Subject"),
- 'description': msg.get('body'),
+ 'description': desc,
'email_from': msg.get('from'),
'email_cc': msg.get('cc'),
+ 'partner_id': msg.get('author_id', False),
'user_id': False,
- })
+ }
if msg.get('priority'):
- custom_values['priority'] = msg.get('priority')
+ defaults['priority'] = msg.get('priority')
- res_id = super(project_issue, self).message_new(cr, uid, msg, custom_values=custom_values, context=context)
- # self.convert_to_bug(cr, uid, [res_id], context=context)
+ defaults.update(custom_values)
+ res_id = super(project_issue, self).message_new(cr, uid, msg, custom_values=defaults, context=context)
return res_id
def message_update(self, cr, uid, ids, msg, update_vals=None, context=None):
if update_vals is None: update_vals = {}
# Update doc values according to the message
- update_vals['description'] = msg.get('body', '')
if msg.get('priority'):
update_vals['priority'] = msg.get('priority')
# Parse 'body' to find values to update
}
for line in msg.get('body', '').split('\n'):
line = line.strip()
- res = tools.misc.command_re.match(line)
+ res = tools.command_re.match(line)
if res and maps.get(res.group(1).lower(), False):
key = maps.get(res.group(1).lower())
update_vals[key] = res.group(2).lower()
return super(project_issue, self).message_update(cr, uid, ids, msg, update_vals=update_vals, context=context)
- # -------------------------------------------------------
- # OpenChatter methods and notifications
- # -------------------------------------------------------
-
- def stage_set_send_note(self, cr, uid, ids, stage_id, context=None):
- """ Override of the (void) default notification method. """
- stage_name = self.pool.get('project.task.type').name_get(cr, uid, [stage_id], context=context)[0][1]
- return self.message_post(cr, uid, ids, body= _("Stage changed to <b>%s</b>.") % (stage_name), subtype="mt_issue_new", context=context)
-
- def case_get_note_msg_prefix(self, cr, uid, id, context=None):
- """ Override of default prefix for notifications. """
- return 'Project issue'
-
- def convert_to_task_send_note(self, cr, uid, ids, context=None):
- message = _("Project issue <b>converted</b> to task.")
- return self.message_post(cr, uid, ids, body=message, context=context)
-
- def create_send_note(self, cr, uid, ids, context=None):
- message = _("Project issue <b>created</b>.")
- return self.message_post(cr, uid, ids, body=message, subtype="mt_issue_new", 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 = _("<b>escalated</b> to <em>'%s'</em>.") % (obj.project_id.name)
- obj.message_post(body=message)
- else:
- message = _("<b>escalated</b>.")
- obj.message_post(body=message)
- return True
-
-project_issue()
class project(osv.osv):
_inherit = "project.project"