[FIX] Propagated ir.needaction class name change.
[odoo/odoo.git] / addons / project_issue / project_issue.py
index 646be57..e61af23 100644 (file)
@@ -46,7 +46,7 @@ class project_issue(crm.crm_case, osv.osv):
     _name = "project.issue"
     _description = "Project Issue"
     _order = "priority, create_date desc"
-    _inherit = ['mail.thread']
+    _inherit = ['ir.needaction_mixin', 'mail.thread']
 
     def _compute_day(self, cr, uid, ids, fields, args, context=None):
         """
@@ -177,8 +177,6 @@ class project_issue(crm.crm_case, osv.osv):
                         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,
@@ -228,7 +226,6 @@ class project_issue(crm.crm_case, osv.osv):
     _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,
@@ -254,14 +251,13 @@ class project_issue(crm.crm_case, osv.osv):
         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')
@@ -287,10 +283,9 @@ class project_issue(crm.crm_case, osv.osv):
                 'task_id': new_task_id,
                 'state':'pending'
             }
-            self._convert_to_task_notification(cr, uid, ids, context)
-            cases = self.browse(cr, uid, ids)
-            self._case_pending_notification(cases, context=context)
-            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'),
@@ -322,16 +317,6 @@ class project_issue(crm.crm_case, osv.osv):
     def convert_to_bug(self, cr, uid, ids, context=None):
         return self._convert(cr, uid, ids, 'bug_categ', context=context)
 
-    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})
-        return True
-
     def next_type(self, cr, uid, ids, context=None):
         for task in self.browse(cr, uid, ids):
             typeid = task.type_id.id
@@ -344,15 +329,24 @@ class project_issue(crm.crm_case, osv.osv):
                     self.write(cr, uid, [task.id], {'type_id': types[index+1]})
         return True
 
+    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})
+        return True
+
     def write(self, cr, uid, ids, vals, context=None):
-        #Update last action date everytime the user change the stage, the state or send a new email
+        #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 'type_id' in vals and vals['type_id']:
+        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, _('System notification'),
-                        _("Changed stage to <b>%s</b>.") % stage.name, type='notification')
+            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):
@@ -362,114 +356,24 @@ class project_issue(crm.crm_case, osv.osv):
         task = self.pool.get('project.task').browse(cr, uid, task_id, context=context)
         return {'value':{'user_id': task.user_id.id,}}
 
-    def _case_open_notification(self, case, context=None):
-        if case.state:
-        message = _("Issue is <b>opened</b>.")
-        case.message_append_note('' ,message, type='notification')
-        return True
-
-    def _case_close_notification(self, case, context=None):
-        case[0].message_mark_done(context)
-        message = _("Issue <em>%s</em> is <b>closed</b>.")
-        case[0].message_append_note('' ,message, type='notification')
-        return True
-
-
-    def _convert_to_task_notification(self, cr, uid, ids, context=None):
-        for obj in self.browse(cr, uid, ids, context=context):
-            self.message_append_note(cr, uid, ids, _('System notification'),
-                        _("Issue is <b>converted</b> in to task."), type='notification', context=context)
-        return True
-
-    def create_notificate(self, cr, uid, ids, context=None):
-        for obj in self.browse(cr, uid, ids, context=context):
-            self.message_append_note(cr, uid, ids, _('System notification'),
-                        _("Issue is <b>created</b>."), type='notification', need_action_user_id=False, context=context)
-        return True
-
-    def _case_pending_notification(self, case, context=None):
-        message = _("Issue is on <b>pending<b>.")
-        case[0].message_append_note('' ,message, type='notification')
-        return True
-
-    def _case_escalate_notification(self, case, context=None):
-        if case[0].project_id.project_escalation_id.user_id.id:
-            message = _("Issue is <b>escalated</b> from project <em>'%s'</em>.") % (case[0].project_id.name)
-            case[0].message_append_note('' ,message, type='notification', need_action_user_id=case[0].project_id.project_escalation_id.user_id.id, context=context)
-        else:
-            message = _("Issue is <b>escalated</b>.")
-            case[0].message_append_note('' ,message, type='notification', need_action_user_id=False, context=context)
-        
-        return True
-
-    def _case_reset_notification(self, cr, uid, ids, context=None):
-        for obj in self.browse(cr, uid, ids, context=context):
-            self.message_append_note(cr, uid, ids, _('System notification'),
-                        _("Issue is reset as <b>new<b>."), type='notification', need_action_user_id=obj.user_id.id, context=context)
-        return True
-
-    def _case_cancel_notification(self, case, context=None):
-        case[0].message_mark_done(context=context)
-        message = _("Issue is <b>cancelled<b>.")
-        case[0].message_append_note('' ,message, type="notification")
-        return True
-
     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})
-        self._case_reset_notification(cr, uid, ids, context)
-        return res
-
-    def case_pending(self, cr, uid, ids, context=None):
-        """Marks case as pending"""
-        res = super(project_issue, self).case_pending(cr, uid, ids, context)
-        self.write(cr, uid, ids, context)
-        return res
-
-    def case_cancel(self, cr, uid, ids, context=None):
-        """Overrides cancel for crm_case for setting probability
-        """
-        res = super(project_issue, self).case_cancel(cr, uid, ids, context)
-        self.write(cr, uid, ids, context)
         return res
 
     def create(self, cr, uid, vals, context=None):
         obj_id = super(project_issue, self).create(cr, uid, vals, context=context)
-        self.create_notificate(cr, uid, [obj_id], context=context)
+        self.create_send_note(cr, uid, [obj_id], context=context)
         return obj_id
 
     def case_open(self, cr, uid, ids, context=None):
-        """
-        @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
-        """
-
         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_close(self, cr, uid, ids, context=None):
-        """
-        @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
-        """
-
-        res = super(project_issue, self).case_close(cr, uid, ids, context)
-        return res
-
     def case_escalate(self, cr, uid, ids, context=None):
-        """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
-        """
         cases = self.browse(cr, uid, ids)
         for case in cases:
             data = {'state' : 'draft'}
@@ -482,7 +386,7 @@ class project_issue(crm.crm_case, osv.osv):
             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._case_escalate_notification(cases, context=context)
+            self.case_escalate_send_note(cr, uid, [case.id], context)
         return True
 
     def message_new(self, cr, uid, msg, custom_values=None, context=None):
@@ -558,6 +462,45 @@ class project_issue(crm.crm_case, osv.osv):
         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()