[IMP] safe_eval: do not log exceptions, when re-raising a new exception, make the...
[odoo/odoo.git] / addons / project_issue / project_issue.py
index e539b9e..8eb7281 100644 (file)
@@ -51,16 +51,29 @@ class project_issue(base_stage, osv.osv):
     _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_project_issue_closed': lambda self, cr, uid, obj, ctx=None: obj.stage_id and obj.stage_id.state == 'done',
-            'project_issue.mt_project_issue_started': lambda self, cr, uid, obj, ctx=None: obj.stage_id and obj.stage_id.state == 'open',
-            'project_issue.mt_project_issue_stage': lambda self, cr, uid, obj, ctx=None: obj.stage_id and obj.stage_id.state not in ['done', 'open'],
+            'project_issue.mt_issue_stage': lambda self, cr, uid, obj, ctx=None: obj['state'] not in ['new', 'done', 'open'],
         },
         'kanban_state': {
-            'project_issue.mt_project_issue_blocked': lambda self, cr, uid, obj, ctx=None: obj.kanban_state == 'blocked',
+            '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)
@@ -246,7 +259,7 @@ class project_issue(base_stage, osv.osv):
                       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=1,
+                                         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"
@@ -263,16 +276,16 @@ class project_issue(base_stage, osv.osv):
         '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',
-                        _track_visibility=1,
+                        track_visibility='onchange',
                         domain="['&', ('fold', '=', False), ('project_ids', '=', project_id)]"),
-        'project_id':fields.many2one('project.project', 'Project', _track_visibility=1),
+        '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, _track_visibility=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', \
@@ -354,7 +367,8 @@ class project_issue(base_stage, osv.osv):
                 'task_id': new_task_id,
                 '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)
 
         return  {
@@ -385,12 +399,7 @@ class project_issue(base_stage, osv.osv):
         if any([field in vals for field in logged_fields]):
             vals['date_action_last'] = time.strftime('%Y-%m-%d %H:%M:%S')
 
-        res = super(project_issue, self).write(cr, uid, ids, vals, context)
-
-        # subscribe new project followers to the issue
-        if vals.get('project_id'):
-            self.message_subscribe_from_parent(cr, uid, ids, context=context)
-        return res
+        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:
@@ -471,6 +480,11 @@ class project_issue(base_stage, osv.osv):
     # 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.
@@ -482,17 +496,19 @@ class project_issue(base_stage, osv.osv):
 
         desc = html2plaintext(msg.get('body')) if msg.get('body') else ''
 
-        custom_values.update({
+        defaults = {
             'name':  msg.get('subject') or _("No Subject"),
             '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)
+        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):
@@ -515,22 +531,13 @@ class project_issue(base_stage, osv.osv):
         }
         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 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)
-
-project_issue()
 
 class project(osv.osv):
     _inherit = "project.project"