Bhumi Thakkar (Open ERP) has proposed merging 
lp:~openerp-dev/openobject-addons/trunk-social-crm-bth into 
lp:~openerp-dev/openobject-addons/trunk-social-jra.

Requested reviews:
  OpenERP R&D Team (openerp-dev)

For more details, see:
https://code.launchpad.net/~openerp-dev/openobject-addons/trunk-social-crm-bth/+merge/96088

Hello,

Notifications for the crm lead, opportunity, phonecall and meeting.

Thanks & Regards,
Bhumi Thakkar (BTH)
-- 
https://code.launchpad.net/~openerp-dev/openobject-addons/trunk-social-crm-bth/+merge/96088
Your team OpenERP R&D Team is requested to review the proposed merge of 
lp:~openerp-dev/openobject-addons/trunk-social-crm-bth into 
lp:~openerp-dev/openobject-addons/trunk-social-jra.
=== modified file 'crm/crm.py'
--- crm/crm.py	2012-02-28 14:04:07 +0000
+++ crm/crm.py	2012-03-06 10:31:27 +0000
@@ -127,7 +127,7 @@
 
     def name_get(self, cr, uid, ids, context=None):
         """Overrides orm name_get method"""
-        if not isinstance(ids, list) : 
+        if not isinstance(ids, list) :
             ids = [ids]
         res = []
         if not ids:
@@ -258,7 +258,31 @@
             data.update(self.onchange_partner_address_id(cr, uid, ids, addr['contact'])['value'])
         return {'value': data}
 
-    def case_open(self, cr, uid, ids, *args):
+    def _case_opportunity_meeting_notification(self, cr, uid, ids, context=None):
+        return True
+
+    def _case_open_notification(self, case, context=None):
+        return True
+
+    def _case_close_notification(self, case, context=None):
+        return True
+
+    def _case_cancel_notification(self, case, context=None):
+        return True
+
+    def _case_pending_notification(self, case, context=None):
+        return True
+
+    def _case_reset_notification(self, case, context=None):
+        return True
+
+    def _case_escalate_notification(self, case, context=None):
+        return True
+
+    def _case_phonecall_notification(self, case, action, context=None):
+        return True
+
+    def case_open(self, cr, uid, ids, context=None):
         """Opens Case
         :param ids: List of case Ids
         """
@@ -268,11 +292,12 @@
             if not case.user_id:
                 data['user_id'] = uid
             self.write(cr, uid, [case.id], data)
-
+            self._case_open_notification(case, context=context)
         self._action(cr, uid, cases, 'open')
+
         return True
 
-    def case_close(self, cr, uid, ids, *args):
+    def case_close(self, cr, uid, ids, context=None):
         """Closes Case
         :param ids: List of case Ids
         """
@@ -280,10 +305,11 @@
         cases[0].state # to fill the browse record cache
         self.write(cr, uid, ids, {'state': 'done', 'date_closed': time.strftime('%Y-%m-%d %H:%M:%S'), })
         # We use the cache of cases to keep the old case state
+        self._case_close_notification(cases, context=context)
         self._action(cr, uid, cases, 'done')
         return True
 
-    def case_cancel(self, cr, uid, ids, *args):
+    def case_cancel(self, cr, uid, ids, context=None):
         """Cancels Case
         :param ids: List of case Ids
         """
@@ -291,26 +317,29 @@
         cases[0].state # to fill the browse record cache
         self.write(cr, uid, ids, {'state': 'cancel', 'active': True})
         # We use the cache of cases to keep the old case state
+        self._case_cancel_notification(cases, context=context)
         self._action(cr, uid, cases, 'cancel')
         return True
 
-    def case_pending(self, cr, uid, ids, *args):
+    def case_pending(self, cr, uid, ids, context=None):
         """Marks case as pending
         :param ids: List of case Ids
         """
         cases = self.browse(cr, uid, ids)
         cases[0].state # to fill the browse record cache
         self.write(cr, uid, ids, {'state': 'pending', 'active': True})
+        self._case_pending_notification(cases, context=context)
         self._action(cr, uid, cases, 'pending')
         return True
 
-    def case_reset(self, cr, uid, ids, *args):
+    def case_reset(self, cr, uid, ids, context=None):
         """Resets case as draft
         :param ids: List of case Ids
         """
         cases = self.browse(cr, uid, ids)
         cases[0].state # to fill the browse record cache
         self.write(cr, uid, ids, {'state': 'draft', 'active': True})
+        self._case_reset_notification(cases, context=context)
         self._action(cr, uid, cases, 'draft')
         return True
 
@@ -325,10 +354,10 @@
         return rule_obj._action(cr, uid, rule_ids, cases, scrit=scrit, context=context)
 
 class crm_case(crm_base):
-    """ A simple python class to be used for common functions 
+    """ A simple python class to be used for common functions
     Object that inherit from this class should inherit from mailgate.thread
     And need a stage_id field
-    And object that inherit (orm inheritance) from a class the overwrite copy 
+    And object that inherit (orm inheritance) from a class the overwrite copy
     """
 
     def stage_find(self, cr, uid, section_id, domain=[], order='sequence'):
@@ -389,8 +418,7 @@
                 default.update({ 'date_open': False })
         return super(crm_case, self).copy(cr, uid, id, default, context=context)
 
-
-    def case_open(self, cr, uid, ids, *args):
+    def case_open(self, cr, uid, ids, context=None):
         """Opens Case"""
         cases = self.browse(cr, uid, ids)
         for case in cases:
@@ -398,10 +426,11 @@
             if not case.user_id:
                 data['user_id'] = uid
             self.write(cr, uid, [case.id], data)
+            self._case_open_notification(case, context=context)
         self._action(cr, uid, cases, 'open')
         return True
 
-    def case_close(self, cr, uid, ids, *args):
+    def case_close(self, cr, uid, ids, context=None):
         """Closes Case"""
         cases = self.browse(cr, uid, ids)
         cases[0].state # to fill the browse record cache
@@ -411,10 +440,11 @@
         #
         # We use the cache of cases to keep the old case state
         #
+        self._case_close_notification(cases, context=context)
         self._action(cr, uid, cases, 'done')
         return True
 
-    def case_escalate(self, cr, uid, ids, *args):
+    def case_escalate(self, cr, uid, ids, context=None):
         """Escalates case to parent level"""
         cases = self.browse(cr, uid, ids)
         for case in cases:
@@ -428,37 +458,38 @@
                 raise osv.except_osv(_('Error !'), _('You can not escalate, you are already at the top level regarding your sales-team category.'))
             self.write(cr, uid, [case.id], data)
         cases = self.browse(cr, uid, ids)
+        self._case_escalate_notification(cases, context=context)
         self._action(cr, uid, cases, 'escalate')
         return True
 
-    def case_cancel(self, cr, uid, ids, *args):
+    def case_cancel(self, cr, uid, ids, context=None):
         """Cancels Case"""
         cases = self.browse(cr, uid, ids)
         cases[0].state # to fill the browse record cache
         self.write(cr, uid, ids, {'state': 'cancel',
                                   'active': True})
+        self._case_cancel_notification(cases, context=context)
         self._action(cr, uid, cases, 'cancel')
-        for case in cases:
-            message = _("The case '%s' has been cancelled.") % (case.name,)
-            self.log(cr, uid, case.id, message)
         return True
 
-    def case_pending(self, cr, uid, ids, *args):
+    def case_pending(self, cr, uid, ids, context=None):
         """Marks case as pending"""
         cases = self.browse(cr, uid, ids)
         cases[0].state # to fill the browse record cache
         self.write(cr, uid, ids, {'state': 'pending', 'active': True})
+        self._case_pending_notification(cases, context=context)
         self._action(cr, uid, cases, 'pending')
         return True
 
-    def case_reset(self, cr, uid, ids, *args):
+    def case_reset(self, cr, uid, ids, context=None):
         """Resets case as draft"""
         state = 'draft'
-        if 'crm.phonecall' in args:
+        if 'crm.phonecall' in context: #TO fix: move into crm_phonecall.py?
             state = 'open'
         cases = self.browse(cr, uid, ids)
         cases[0].state # to fill the browse record cache
         self.write(cr, uid, ids, {'state': state, 'active': True})
+        self._case_reset_notification(cases, context=context);
         self._action(cr, uid, cases, state)
         return True
 

=== modified file 'crm/crm_lead.py'
--- crm/crm_lead.py	2012-01-31 13:36:57 +0000
+++ crm/crm_lead.py	2012-03-06 10:31:27 +0000
@@ -192,7 +192,6 @@
         'message_ids': fields.one2many('mail.message', 'res_id', 'Messages', domain=[('model','=',_name)]),
         'subjects': fields.function(_get_email_subject, fnct_search=_history_search, string='Subject of Email', type='char', size=64),
 
-
         # Only used for type opportunity
         'partner_address_id': fields.many2one('res.partner.address', 'Partner Contact', domain="[('partner_id','=',partner_id)]"),
         'probability': fields.float('Probability (%)',group_operator="avg"),
@@ -225,6 +224,12 @@
         'color': 0,
     }
 
+    def create(self, cr, uid, vals, context=None):
+        obj_id = super(crm_lead, self).create(cr, uid, vals, context)
+        self._case_create_notification(cr, uid, [obj_id], context=context)
+        return obj_id
+
+
     def onchange_partner_address_id(self, cr, uid, ids, add, email=False):
         """This function returns value of partner email based on Partner Address
         """
@@ -266,75 +271,137 @@
     def stage_find_won(self, cr, uid, section_id):
         return self.stage_find_percent(cr, uid, 100.0, section_id)
 
-    def case_open(self, cr, uid, ids, *args):
-        for l in self.browse(cr, uid, ids):
-            # When coming from draft override date and stage otherwise just set state
-            if l.state == 'draft':
-                if l.type == 'lead':
-                    message = _("The lead '%s' has been opened.") % l.name
-                elif l.type == 'opportunity':
-                    message = _("The opportunity '%s' has been opened.") % l.name
-                else:
-                    message = _("The case '%s' has been opened.") % l.name
-                self.log(cr, uid, l.id, message)
-                value = {'date_open': time.strftime('%Y-%m-%d %H:%M:%S')}
-                self.write(cr, uid, [l.id], value)
-                if l.type == 'opportunity' and not l.stage_id:
-                    stage_id = self.stage_find(cr, uid, l.section_id.id or False, [('sequence','>',0)])
-                    if stage_id:
-                        self.stage_set(cr, uid, [l.id], stage_id)
-        res = super(crm_lead, self).case_open(cr, uid, ids, *args)
+    def _case_create_notification(self, cr, uid, ids, context=None):
+        for obj in self.browse(cr, uid, ids, context=context):
+            self.message_subscribe(cr, uid, ids, [obj.user_id.id], context=context)
+            if obj.type=="opportunity" and obj.state=="draft":
+                message = _("Opportunity is <b>created</b>.")
+            elif obj.type=="lead" :
+                message = _("Lead is <b>created</b>.")
+            else:
+                message = _("The case has been <b>created</b>.")
+            self.message_append_note(cr, uid, ids, _('System notification'),
+                        message, type='notification', need_action_user_id=obj.user_id.id, context=context)
+        return True
+
+    def _case_open_notification(self, lead, context=None):
+        if lead.state != 'draft' and lead.state != 'pending':
+            return False
+        if lead.type == 'lead':
+            message = _("The lead has been <b>opened</b>.")
+        elif lead.type == 'opportunity':
+            message = _("The opportunity has been <b>opened</b>.")
+        else:
+            message = _("The case has been <b>opened</b>.")
+        lead.message_append_note('' ,message, need_action_user_id=lead.user_id.id)
+
+    def _case_close_notification(self, lead, context=None):
+        lead[0].message_mark_done(context)
+        if lead[0].type == 'lead':
+            message = _("The lead has been <b>closed</b>.")
+        elif lead[0].type == 'opportunity':
+            message = _("The opportunity has been <b>closed</b>.")
+        else:
+            message = _("The case has been <b>closed</b>.")
+        lead[0].message_append_note('' ,message)
+
+    def _case_mark_lost_notification(self, lead, context=None):
+        lead.message_mark_done(context)
+        message = _("The opportunity has been <b>marked as lost</b>.")
+        lead.message_append_note('' ,message)
+
+    def _case_mark_won_notification(self, lead, context=None):
+        lead.message_mark_done(context)
+        message = _("The opportunity has been <b>won</b>.")
+        lead.message_append_note('' ,message)
+
+    def _case_cancel_notification(self, lead, context=None):
+        lead[0].message_mark_done(context)
+        if lead[0].type == 'lead':
+            message = _("The lead has been <b>cancelled</b>.")
+        elif lead[0].type == 'opportunity':
+            message = _("The opportunity has been <b>cancelled</b>.")
+        lead[0].message_append_note('' ,message)
+
+    def _case_pending_notification(self, case, context=None):
+        if case[0].type == 'lead':
+            message = _("The lead is <b>pending</b>.")
+        elif case[0].type == 'opportunity':
+            message = _("The opportunity is <b>pending</b>.")
+        case[0].message_append_note('' ,message)
+
+    def _case_escalate_notification(self, case, context=None):
+        message = _("The lead is <b>escalated</b>.")
+        case.message_append_note('' ,message)
+
+    def _case_reset_notification(self, case, context=None):
+        if case[0].type == 'lead':
+            message = _("The lead is <b>renewed</b>.")
+        elif case[0].type == 'opportunity':
+            message = _("The opportunity is <b>renewed</b>.")
+        case[0].message_append_note('' ,message, need_action_user_id=case[0].user_id.id)
+
+    def _case_phonecall_notification(self, cr, uid, ids, case, phonecall, action, context=None):
+        for obj in phonecall.browse(cr, uid, ids, context=context):
+            if action == "schedule" :
+                message = _("<b>%s a call</b> for the %s.") % (action, obj.date)
+            else :
+                message = _("<b>%s a call</b>.") % (action)
+            case.message_append_note('', message)
+            if action == "schedule" :
+                phonecall.message_append_note(cr, uid, ids, '', message, need_action_user_id=obj.user_id.id)
+
+    def case_open(self, cr, uid, ids, context=None):
+        res = super(crm_lead, self).case_open(cr, uid, ids, context)
+        for lead in self.browse(cr, uid, ids, context=context):
+            value = {'date_open': time.strftime('%Y-%m-%d %H:%M:%S')}
+            self.write(cr, uid, [lead.id], value)
+            if lead.type == 'opportunity' and not lead.stage_id:
+                stage_id = self.stage_find(cr, uid, lead.section_id.id or False, [('sequence','>',0)])
+                if stage_id:
+                    self.stage_set(cr, uid, [lead.id], stage_id)
         return res
 
-    def case_close(self, cr, uid, ids, *args):
-        res = super(crm_lead, self).case_close(cr, uid, ids, *args)
+    def case_close(self, cr, uid, ids, context=None):
+        res = super(crm_lead, self).case_close(cr, uid, ids, context)
         self.write(cr, uid, ids, {'date_closed': time.strftime('%Y-%m-%d %H:%M:%S')})
-        for case in self.browse(cr, uid, ids):
-            if case.type == 'lead':
-                message = _("The lead '%s' has been closed.") % case.name
-            else:
-                message = _("The case '%s' has been closed.") % case.name
-            self.log(cr, uid, case.id, message)
         return res
 
-    def case_cancel(self, cr, uid, ids, *args):
+    def case_cancel(self, cr, uid, ids, context=None):
         """Overrides cancel for crm_case for setting probability
         """
-        res = super(crm_lead, self).case_cancel(cr, uid, ids, args)
+        res = super(crm_lead, self).case_cancel(cr, uid, ids, context)
         self.write(cr, uid, ids, {'probability' : 0.0})
         return res
 
-    def case_reset(self, cr, uid, ids, *args):
+    def case_reset(self, cr, uid, ids, context=None):
         """Overrides reset as draft in order to set the stage field as empty
         """
-        res = super(crm_lead, self).case_reset(cr, uid, ids, *args)
+        res = super(crm_lead, self).case_reset(cr, uid, ids, context)
         self.write(cr, uid, ids, {'stage_id': False, 'probability': 0.0})
         return res
 
-    def case_mark_lost(self, cr, uid, ids, *args):
+    def case_mark_lost(self, cr, uid, ids, context=None):
         """Mark the case as lost: state = done and probability = 0%
         """
-        res = super(crm_lead, self).case_close(cr, uid, ids, *args)
+        res = super(crm_lead, self).case_close(cr, uid, ids, context)
         self.write(cr, uid, ids, {'probability' : 0.0})
-        for l in self.browse(cr, uid, ids):
-            stage_id = self.stage_find_lost(cr, uid, l.section_id.id or False)
+        for lead in self.browse(cr, uid, ids):
+            stage_id = self.stage_find_lost(cr, uid, lead.section_id.id or False)
             if stage_id:
-                self.stage_set(cr, uid, [l.id], stage_id)
-            message = _("The opportunity '%s' has been marked as lost.") % l.name
-            self.log(cr, uid, l.id, message)
+                self.stage_set(cr, uid, [lead.id], stage_id)
         return res
 
-    def case_mark_won(self, cr, uid, ids, *args):
+    def case_mark_won(self, cr, uid, ids, context=None):
         """Mark the case as lost: state = done and probability = 0%
         """
-        res = super(crm_lead, self).case_close(cr, uid, ids, *args)
+        res = super(crm_lead, self).case_close(cr, uid, ids, context=None)
         self.write(cr, uid, ids, {'probability' : 100.0})
-        for l in self.browse(cr, uid, ids):
-            stage_id = self.stage_find_won(cr, uid, l.section_id.id or False)
+        for lead in self.browse(cr, uid, ids):
+            stage_id = self.stage_find_won(cr, uid, lead.section_id.id or False)
             if stage_id:
-                self.stage_set(cr, uid, [l.id], stage_id)
-            message = _("The opportunity '%s' has been been won.") % l.name
-            self.log(cr, uid, l.id, message)
+                self.stage_set(cr, uid, [lead.id], stage_id)
+            self._case_mark_won_notification(lead, context=context)
         return res
 
     def set_priority(self, cr, uid, ids, priority):
@@ -342,12 +409,12 @@
         """
         return self.write(cr, uid, ids, {'priority' : priority})
 
-    def set_high_priority(self, cr, uid, ids, *args):
+    def set_high_priority(self, cr, uid, ids, context=None):
         """Set lead priority to high
         """
         return self.set_priority(cr, uid, ids, '1')
 
-    def set_normal_priority(self, cr, uid, ids, *args):
+    def set_normal_priority(self, cr, uid, ids, context=None):
         """Set lead priority to normal
         """
         return self.set_priority(cr, uid, ids, '3')
@@ -440,7 +507,7 @@
 
         subject = subject[0] + ", ".join(subject[1:])
         details = "\n\n".join(details)
-        return self.message_append(cr, uid, [opportunity_id], subject, body_text=details, context=context)
+        return opportunity.message_append_note(subject, body=details, need_action_user_id=opportunity.user_id.id)
 
     def _merge_opportunity_history(self, cr, uid, opportunity_id, opportunities, context=None):
         message = self.pool.get('mail.message')
@@ -550,10 +617,8 @@
         }
 
     def _convert_opportunity_notification(self, cr, uid, lead, context=None):
-        success_message = _("Lead '%s' has been converted to an opportunity.") % lead.name
-        self.message_append(cr, uid, [lead.id], success_message, body_text=success_message, context=context)
-        self.log(cr, uid, lead.id, success_message)
-        self._send_mail_to_salesman(cr, uid, lead, context=context)
+        success_message = _("Lead is <b>converted to an opportunity</b>.")
+        lead.message_append_note(success_message ,success_message, need_action_user_id=lead.user_id.id)
         return True
 
     def convert_opportunity(self, cr, uid, ids, partner_id, user_ids=False, section_id=False, context=None):
@@ -705,6 +770,7 @@
             if action == 'log':
                 phonecall.case_close(cr, uid, [new_id])
             phonecall_dict[lead.id] = new_id
+            self._case_phonecall_notification(cr, uid, [new_id], lead, phonecall, action, context=context)
         return phonecall_dict
 
 
@@ -782,7 +848,7 @@
                 #re-open
                 values.update(state=crm.AVAILABLE_STATES[1][0])
                 if not case.date_open:
-                    values['date_open'] = time.strftime(tools.DEFAULT_SERVER_DATETIME_FORMAT) 
+                    values['date_open'] = time.strftime(tools.DEFAULT_SERVER_DATETIME_FORMAT)
             res = self.write(cr, uid, [case.id], values, context=context)
         return res
 
@@ -846,15 +912,13 @@
             # change probability of lead(s) if required by stage
             if not vals.get('probability') and stage.on_change:
                 vals['probability'] = stage.probability
-            text = _("Changed Stage to: %s") % stage.name
-            self.message_append(cr, uid, ids, text, body_text=text, context=context)
             for case in self.browse(cr, uid, ids, context=context):
                 if case.type == 'lead' or context.get('stage_type') == 'lead':
-                    message = _("The stage of lead '%s' has been changed to '%s'.") % (case.name, stage.name)
-                    self.log(cr, uid, case.id, message)
+                    message = _("The stage of lead has been changed to <b>%s</b>.") % (stage.name)
+                    case.message_append_note('', message)
                 elif case.type == 'opportunity':
-                    message = _("The stage of opportunity '%s' has been changed to '%s'.") % (case.name, stage.name)
-                    self.log(cr, uid, case.id, message)
+                    message = _("The stage of opportunity has been changed to <b>%s</b>.") % (stage.name)
+                    case.message_append_note('', message)
 
         return super(crm_lead,self).write(cr, uid, ids, vals, context)
 

=== modified file 'crm/crm_lead_view.xml'
--- crm/crm_lead_view.xml	2012-02-07 09:23:28 +0000
+++ crm/crm_lead_view.xml	2012-03-06 10:31:27 +0000
@@ -77,6 +77,9 @@
                             icon="gtk-go-forward" context="{'stage_type': 'lead'}" />
                     </group>
                     <field name="type" invisible="1"/>
+                    <button string="Send New Email"
+                        name="%(mail.action_email_compose_message_wizard)d"
+                        icon="terp-mail-message-new" type="action"/>
                 </group>
                 <notebook colspan="4">
                 <page string="Lead">
@@ -143,29 +146,6 @@
                             type="object" icon="gtk-convert" />
                     </group>
                  </page>
-                 <page string="Communication &amp; History" groups="base.group_extended">
-                   <group colspan="4">
-                       <field colspan="4" name="email_cc" widget="char" size="512"/>
-                   </group>
-                    <field name="message_ids" colspan="4" nolabel="1" mode="tree" readonly="1">
-                        <tree string="History">
-                            <field name="display_text" string="History Information"/>
-                            <field name="email_from" invisible="1"/>
-                            <button
-                                string="Reply" attrs="{'invisible': [('email_from', '=', False)]}"
-                                name="%(mail.action_email_compose_message_wizard)d"
-                                context="{'mail.compose.message.mode':'reply', 'message_id':active_id}"
-                                icon="terp-mail-replied" type="action" />
-                        </tree>
-                    </field>
-                    <button string="Add Internal Note"
-                        name="%(crm.action_crm_add_note)d"
-                        context="{'model': 'crm.lead' }"
-                        icon="terp-document-new" type="action" />
-                    <button string="Send New Email"
-                        name="%(mail.action_email_compose_message_wizard)d"
-                        icon="terp-mail-message-new" type="action"/>
-                 </page>
                  <page string="Extra Info" groups="base.group_extended">
                     <group colspan="2" col="2">
                         <separator string="Categorization" colspan="2" col="2"/>
@@ -177,13 +157,6 @@
                         <field name="referred"/>
                     </group>
                     <group colspan="2" col="2">
-                        <separator string="Dates" colspan="2" col="2"/>
-                        <field name="create_date"/>
-                        <field name="write_date"/>
-                        <field name="date_open"/>
-                        <field name="date_closed"/>
-                    </group>
-                    <group colspan="2" col="2">
                         <separator string="Mailings" colspan="2" col="2"/>
                         <field name="optin" on_change="on_change_optin(optin)"/>
                         <field name="optout" on_change="on_change_optout(optout)"/>
@@ -195,6 +168,7 @@
                     </group>
                  </page>
                 </notebook>
+                <field name="message_ids_social" widget="ThreadView"/>
             </form>
         </field>
     </record>
@@ -460,6 +434,10 @@
                     <button name="action_makeMeeting" type="object"
                     string="Schedule Meeting" icon="gtk-redo" />
                     <newline/>
+                    <button string="Send New Email"
+                        name="%(mail.action_email_compose_message_wizard)d"
+                        icon="terp-mail-message-new" type="action"/>
+                    <newline/>
                     <field name="date_action"/>
                     <field name="title_action"/>
                     <field name="priority" string="Priority"/>
@@ -546,38 +524,8 @@
                         <field name="optout" on_change="on_change_optout(optout)"/>
                     </group>
                 </page>
-                <page string="Communication &amp; History" groups="base.group_extended">
-                    <group colspan="4">
-                      <field colspan="4" name="email_cc" widget="char" size="512"/>
-                    </group>
-                    <field name="message_ids" colspan="4" nolabel="1" mode="tree" readonly="1">
-                        <tree string="History">
-                            <field name="display_text" string="History Information"/>
-                            <field name="email_from" invisible="1"/>
-                            <button
-                                string="Reply" attrs="{'invisible': [('email_from', '=', False)]}"
-                                name="%(mail.action_email_compose_message_wizard)d"
-                                context="{'mail.compose.message.mode':'reply', 'message_id':active_id}"
-                                icon="terp-mail-replied" type="action" />
-                        </tree>
-                    </field>
-                    <button string="Add Internal Note"
-                        name="%(crm.action_crm_add_note)d"
-                        context="{'model': 'crm.lead' }"
-                        icon="terp-document-new" type="action" />
-                    <button string="Send New Email"
-                        name="%(mail.action_email_compose_message_wizard)d"
-                        icon="terp-mail-message-new" type="action"/>
-                </page>
                 <page string="Extra Info" groups="base.group_extended">
                     <group col="2" colspan="2">
-                        <separator string="Dates" colspan="2"/>
-                        <field name="create_date"/>
-                        <field name="write_date"/>
-                        <field name="date_closed"/>
-                        <field name="date_open"/>
-                    </group>
-                    <group col="2" colspan="2">
                         <separator string="Misc" colspan="2"/>
                         <field name="active"/>
                         <field name="day_open"/>
@@ -589,6 +537,7 @@
                     <field name="ref2"/>
                 </page>
                 </notebook>
+                <field name="message_ids_social" widget="ThreadView"/>
             </form>
         </field>
     </record>

=== modified file 'crm/crm_meeting.py'
--- crm/crm_meeting.py	2011-10-16 01:28:00 +0000
+++ crm/crm_meeting.py	2012-03-06 10:31:27 +0000
@@ -42,7 +42,7 @@
     _name = 'crm.meeting'
     _description = "Meeting"
     _order = "id desc"
-    _inherit = "calendar.event"
+    _inherit = ["calendar.event","mail.thread"]
     _columns = {
         # From crm.case
         'name': fields.char('Summary', size=124, required=True, states={'done': [('readonly', True)]}),
@@ -80,7 +80,47 @@
         'user_id': lambda self, cr, uid, ctx: uid,
     }
 
-    def case_open(self, cr, uid, ids, *args):
+    def create(self, cr, uid, vals, context=None):
+        obj_id = super(crm_meeting, self).create(cr, uid, vals, context=context)
+        self._case_opportunity_meeting_notification(cr, uid, [obj_id], context=context)
+        return obj_id
+
+    def _case_opportunity_meeting_notification(self, cr, uid, ids, context=None):
+        lead_obj = self.pool.get('crm.lead')
+        phonecall_obj = self.pool.get('crm.phonecall')
+        for obj in self.browse(cr, uid, ids, context=context):
+            if(obj.opportunity_id.id):
+                newid = obj.opportunity_id.id
+                message = _("<b>scheduled meeting on</b> %s for opportunity.") % (obj.date)
+                for lead in lead_obj.browse(cr, uid, [newid], context=context):
+                    lead.message_append_note('', message)
+                    obj.message_append_note('', message, need_action_user_id=lead.user_id.id)
+            elif(obj.phonecall_id.id):
+                newid = obj.phonecall_id.id
+                message = _("<b>scheduled meeting on</b> %s for phonecall.") % (obj.date)
+                for phonecall in phonecall_obj.browse(cr, uid, [newid], context=context):
+                    phonecall.message_append_note('', message)
+                    obj.message_append_note('', message, need_action_user_id=phonecall.user_id.id)
+            else:
+                message = _("<b>scheduled meeting on</b> %s.") % (obj.date)
+                obj.message_append_note('', message, need_action_user_id=obj.user_id.id)
+
+    def _case_close_notification(self, meeting, context=None):
+        meeting[0].message_mark_done(context)
+        message = _("The meeting is <b>done</b>.")
+        meeting[0].message_append_note('' ,message)
+
+    def _case_reset_notification(self, meeting, context=None):
+        message = _("The meeting is <b>unconfirmed</b>.")
+        meeting[0].message_append_note('' ,message)
+
+    def _case_open_notification(self, meeting, context=None):
+        if meeting.state != 'draft':
+            return False
+        message = _("The meeting has been <b>confirmed</b>.")
+        meeting.message_append_note('' ,message, need_action_user_id=meeting.user_id.id)
+
+    def case_open(self, cr, uid, ids, context=None):
         """Confirms meeting
         @param self: The object pointer
         @param cr: the current row, from the database cursor,
@@ -88,11 +128,9 @@
         @param ids: List of Meeting Ids
         @param *args: Tuple Value for additional Params
         """
-        res = super(crm_meeting, self).case_open(cr, uid, ids, args)
+        res = super(crm_meeting, self).case_open(cr, uid, ids, context)
         for (id, name) in self.name_get(cr, uid, ids):
-            message = _("The meeting '%s' has been confirmed.") % name
             id=base_calendar.base_calendar_id2real_id(id)
-            self.log(cr, uid, id, message)
         return res
 
 crm_meeting()

=== modified file 'crm/crm_meeting_view.xml'
--- crm/crm_meeting_view.xml	2012-01-31 13:36:57 +0000
+++ crm/crm_meeting_view.xml	2012-03-06 10:31:27 +0000
@@ -216,6 +216,7 @@
 
                     </page>
                 </notebook>
+                <field name="message_ids_social" widget="ThreadView"/>
             </form>
         </field>
     </record>

=== modified file 'crm/crm_phonecall.py'
--- crm/crm_phonecall.py	2012-01-31 13:36:57 +0000
+++ crm/crm_phonecall.py	2012-03-06 10:31:27 +0000
@@ -32,6 +32,7 @@
     _name = "crm.phonecall"
     _description = "Phonecall"
     _order = "id desc"
+    _inherit = ['mail.thread']
     _columns = {
         # From crm.case
         'id': fields.integer('ID', readonly=True),
@@ -49,12 +50,12 @@
         'company_id': fields.many2one('res.company', 'Company'),
         'description': fields.text('Description'),
         'state': fields.selection([
-                                    ('draft', 'Draft'), 
-                                    ('open', 'Todo'), 
-                                    ('cancel', 'Cancelled'), 
-                                    ('done', 'Held'), 
+                                    ('draft', 'Draft'),
+                                    ('open', 'Todo'),
+                                    ('cancel', 'Cancelled'),
+                                    ('done', 'Held'),
                                     ('pending', 'Not Held'),
-                                ], 'State', size=16, readonly=True, 
+                                ], 'State', size=16, readonly=True,
                                   help='The state is set to \'Todo\', when a case is created.\
                                   \nIf the case is in progress the state is set to \'Open\'.\
                                   \nWhen the call is over, the state is set to \'Held\'.\
@@ -71,12 +72,17 @@
                                  type="char", string="Contact", size=128),
         'partner_mobile': fields.char('Mobile', size=32),
         'priority': fields.selection(crm.AVAILABLE_PRIORITIES, 'Priority'),
-        'date_closed': fields.datetime('Closed', readonly=True), 
-        'date': fields.datetime('Date'), 
-        'opportunity_id': fields.many2one ('crm.lead', 'Lead/Opportunity'), 
+        'date_closed': fields.datetime('Closed', readonly=True),
+        'date': fields.datetime('Date'),
+        'opportunity_id': fields.many2one ('crm.lead', 'Lead/Opportunity'),
         'message_ids': fields.one2many('mail.message', 'res_id', 'Messages', domain=[('model','=',_name)]),
     }
 
+    def create(self, cr, uid, vals, context=None):
+        obj_id = super(crm_phonecall, self).create(cr, uid, vals, context=context)
+        self.open_notification(cr, uid, [obj_id], context)
+        return obj_id
+
     def _get_default_state(self, cr, uid, context=None):
         if context and context.get('default_state', False):
             return context.get('default_state')
@@ -84,11 +90,34 @@
 
     _defaults = {
         'date': lambda *a: time.strftime('%Y-%m-%d %H:%M:%S'),
-        'priority': crm.AVAILABLE_PRIORITIES[2][0], 
-        'state':  _get_default_state, 
+        'priority': crm.AVAILABLE_PRIORITIES[2][0],
+        'state':  _get_default_state,
         'user_id': lambda self,cr,uid,ctx: uid,
         'active': 1,
     }
+    def _case_cancel_notification(self, phonecall, context=None):
+        phonecall[0].message_mark_done(context)
+        message = _("The Phonecall is <b>cancelled</b>.")
+        phonecall[0].message_append_note( _('System notification'),
+                        message, type='notification', context=context)
+
+    def _case_pending_notification(self, phonecall, context=None):
+        message = _("The Phonecall is <b>pending</b>.")
+        phonecall[0].message_append_note('' ,message)
+
+    def done_notification(self, cr, uid, ids, context=None):
+        for phonecall in self.browse(cr, uid, ids):
+            phonecall.message_mark_done(context)
+            message = _("The Phonecall is <b>done</b>.")
+            self.message_append_note(cr, uid, [phonecall.id], _('System notification'),
+                        message, type='notification', context=context)
+
+    def open_notification(self, cr, uid, ids, context=None):
+        for phonecall in self.browse(cr, uid, ids):
+            self.message_subscribe(cr, uid, ids, [phonecall.user_id.id], context=context)
+            message = _("The Phonecall is <b>open</b>.")
+            self.message_append_note(cr, uid, [phonecall.id], _('System notification'),message,
+                                     type='notification', need_action_user_id=phonecall.user_id.id, context=context)
 
     # From crm.case
     def onchange_partner_address_id(self, cr, uid, ids, add, email=False):
@@ -100,7 +129,7 @@
             res['value']['partner_mobile'] = address.mobile
         return res
 
-    def case_close(self, cr, uid, ids, *args):
+    def case_close(self, cr, uid, ids, context=None):
         """Overrides close for crm_case for setting close date
         """
         res = True
@@ -110,23 +139,26 @@
             if phone.duration <=0:
                 duration = datetime.now() - datetime.strptime(phone.date, '%Y-%m-%d %H:%M:%S')
                 data.update({'duration': duration.seconds/float(60)})
-            res = super(crm_phonecall, self).case_close(cr, uid, [phone_id], args)
+            res = super(crm_phonecall, self).case_close(cr, uid, [phone_id], context)
             self.write(cr, uid, [phone_id], data)
+            self.done_notification(cr, uid, [phone_id], context);
         return res
 
-    def case_reset(self, cr, uid, ids, *args):
+    def case_reset(self, cr, uid, ids, context=None):
         """Resets case as Todo
         """
-        res = super(crm_phonecall, self).case_reset(cr, uid, ids, args, 'crm.phonecall')
+        res = super(crm_phonecall, self).case_reset(cr, uid, ids, context)
         self.write(cr, uid, ids, {'duration': 0.0, 'state':'open'})
+        self.open_notification(cr, uid, ids, context)
         return res
 
 
-    def case_open(self, cr, uid, ids, *args):
+    def case_open(self, cr, uid, ids, context=None):
         """Overrides cancel for crm_case for setting Open Date
         """
-        res = super(crm_phonecall, self).case_open(cr, uid, ids, *args)
+        res = super(crm_phonecall, self).case_open(cr, uid, ids, context)
         self.write(cr, uid, ids, {'date_open': time.strftime('%Y-%m-%d %H:%M:%S')})
+        self.open_notification(cr, uid, ids, context)
         return res
 
     def schedule_another_phonecall(self, cr, uid, ids, schedule_time, call_summary, \
@@ -158,7 +190,7 @@
                     'partner_mobile' : call.partner_mobile,
                     'priority': call.priority,
             }
-            
+
             new_id = self.create(cr, uid, vals, context=context)
             self.case_open(cr, uid, [new_id])
             if action == 'log':
@@ -243,13 +275,13 @@
                             'planned_revenue': planned_revenue,
                             'probability': probability,
                             'partner_id': partner_id or False,
-                            'partner_address_id': default_contact and default_contact.id, 
+                            'partner_address_id': default_contact and default_contact.id,
                             'phone': default_contact and default_contact.phone,
                             'mobile': default_contact and default_contact.mobile,
                             'section_id': call.section_id and call.section_id.id or False,
                             'description': call.description or False,
                             'priority': call.priority,
-                            'type': 'opportunity', 
+                            'type': 'opportunity',
                             'phone': call.partner_phone or False,
                             'email_from': default_contact and default_contact.email,
                         })
@@ -261,7 +293,7 @@
             self.case_close(cr, uid, [call.id])
             opportunity.case_open(cr, uid, [opportunity_id])
             opportunity_dict[call.id] = opportunity_id
-        return opportunity_dict   
+        return opportunity_dict
 
     def action_make_meeting(self, cr, uid, ids, context=None):
         """

=== modified file 'crm/crm_phonecall_view.xml'
--- crm/crm_phonecall_view.xml	2011-12-21 13:10:28 +0000
+++ crm/crm_phonecall_view.xml	2012-03-06 10:31:27 +0000
@@ -123,6 +123,7 @@
                         states="cancel" type="object"
                         icon="gtk-convert" />
                 </group>
+                <field name="message_ids_social" widget="ThreadView"/>
             </form>
         </field>
     </record>

=== modified file 'mail/mail_message.py'
--- mail/mail_message.py	2012-02-29 10:50:32 +0000
+++ mail/mail_message.py	2012-03-06 10:31:27 +0000
@@ -281,6 +281,7 @@
                 'headers': headers, # serialize the dict on the fly
                 'mail_server_id': mail_server_id,
                 'state': 'outgoing',
+                'type': 'email',
                 'auto_delete': auto_delete
             }
         email_msg_id = self.create(cr, uid, msg_vals, context)

=== modified file 'sale_crm/wizard/crm_make_sale.py'
--- sale_crm/wizard/crm_make_sale.py	2012-02-14 12:25:20 +0000
+++ sale_crm/wizard/crm_make_sale.py	2012-03-06 10:31:27 +0000
@@ -106,9 +106,8 @@
                 sale_order = sale_obj.browse(cr, uid, new_id, context=context)
                 case_obj.write(cr, uid, [case.id], {'ref': 'sale.order,%s' % new_id})
                 new_ids.append(new_id)
-                message = _("Opportunity  '%s' is converted to Quotation.") % (case.name)
-                self.log(cr, uid, case.id, message)
-                case_obj.message_append(cr, uid, [case], _("Converted to Sales Quotation(%s).") % (sale_order.name), context=context)
+                message = _("Opportunity %s is converted to Quotation %s.") % (case.name, sale_order.name)
+                case.message_append_note( _("Converted to Sales Quotation(%s).") % (sale_order.name),message,need_action_user_id=sale_order.user_id.id)
 
             if make.close:
                 case_obj.case_close(cr, uid, data)

_______________________________________________
Mailing list: https://launchpad.net/~openerp-dev-gtk
Post to     : [email protected]
Unsubscribe : https://launchpad.net/~openerp-dev-gtk
More help   : https://help.launchpad.net/ListHelp

Reply via email to