[MERGE] with trunk
[odoo/odoo.git] / addons / crm / crm_lead.py
index 9b958f5..ed12590 100644 (file)
@@ -307,8 +307,8 @@ class crm_lead(base_stage, format_address, osv.osv):
         obj_id = super(crm_lead, self).create(cr, uid, vals, context)
         section_id = self.browse(cr, uid, obj_id, context=context).section_id
         if section_id:
-            followers = [follow.id for follow in section_id.message_follower_ids]
-            self.message_subscribe(cr, uid, [obj_id], followers, context=context)
+            # subscribe salesteam followers & subtypes to the lead
+            self._subscribe_followers_subtype(cr, uid, [obj_id], section_id, 'crm.case.section', context=context)
         self.create_send_note(cr, uid, [obj_id], context=context)
         return obj_id
 
@@ -915,10 +915,13 @@ class crm_lead(base_stage, format_address, osv.osv):
                 vals['probability'] = stage.probability
         if vals.get('section_id'):
             section_id = self.pool.get('crm.case.section').browse(cr, uid, vals.get('section_id'), context=context)
-            if section_id:
-                vals.setdefault('message_follower_ids', [])
-                vals['message_follower_ids'] += [(4, follower.id) for follower in section_id.message_follower_ids]
-        return super(crm_lead,self).write(cr, uid, ids, vals, context)
+            vals.setdefault('message_follower_ids', [])
+            vals['message_follower_ids'] += [(6, 0,[follower.id]) for follower in section_id.message_follower_ids]
+        res = super(crm_lead,self).write(cr, uid, ids, vals, context)
+        # subscribe new salesteam followers & subtypes to the lead
+        if vals.get('section_id'):
+            self._subscribe_followers_subtype(cr, uid, ids, vals.get('section_id'), 'crm.case.section', context=context)
+        return res
 
     # ----------------------------------------
     # Mail Gateway
@@ -975,7 +978,7 @@ class crm_lead(base_stage, format_address, osv.osv):
     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('crm.case.stage').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_crm_stage", context=context)
+        return self.message_post(cr, uid, ids, body= _("Stage changed to <b>%s</b>.") % (stage_name), subtype="crm.mt_lead_stage", context=context)
 
     def case_get_note_msg_prefix(self, cr, uid, lead, context=None):
         if isinstance(lead, (int, long)):
@@ -985,16 +988,16 @@ class crm_lead(base_stage, format_address, osv.osv):
     def create_send_note(self, cr, uid, ids, context=None):
         for id in ids:
             message = _("%s has been <b>created</b>.") % (self.case_get_note_msg_prefix(cr, uid, id, context=context))
-            self.message_post(cr, uid, [id], body=message, context=context)
+            self.message_post(cr, uid, [id], body=message, subtype="crm.mt_lead_create", context=context)
         return True
 
     def case_mark_lost_send_note(self, cr, uid, ids, context=None):
         message = _("Opportunity has been <b>lost</b>.")
-        return self.message_post(cr, uid, ids, body=message, subtype="mt_crm_lost", context=context)
+        return self.message_post(cr, uid, ids, body=message, subtype="crm.mt_lead_lost", context=context)
 
     def case_mark_won_send_note(self, cr, uid, ids, context=None):
         message = _("Opportunity has been <b>won</b>.")
-        return self.message_post(cr, uid, ids, body=message, subtype="mt_crm_won", context=context)
+        return self.message_post(cr, uid, ids, body=message, subtype="crm.mt_lead_won", context=context)
 
     def schedule_phonecall_send_note(self, cr, uid, ids, phonecall_id, action, context=None):
         phonecall = self.pool.get('crm.phonecall').browse(cr, uid, [phonecall_id], context=context)[0]
@@ -1011,7 +1014,7 @@ class crm_lead(base_stage, format_address, osv.osv):
 
     def convert_opportunity_send_note(self, cr, uid, lead, context=None):
         message = _("Lead has been <b>converted to an opportunity</b>.")
-        lead.message_post(body=message)
+        lead.message_post(body=message, subtype="crm.mt_lead_convert_to_opportunity")
         return True
 
     def onchange_state(self, cr, uid, ids, state_id, context=None):