diff --git a/addons/crm/crm.py b/addons/crm/crm.py
index 292169404a3..fdcd7a1a52a 100644
--- a/addons/crm/crm.py
+++ b/addons/crm/crm.py
@@ -258,7 +258,26 @@ class crm_base(object):
data.update(self.onchange_partner_address_id(cr, uid, ids, addr['contact'])['value'])
return {'value': data}
+ 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_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
@@ -269,7 +288,7 @@ class crm_base(object):
data = {'state': 'open', 'active': True}
if not case.user_id:
data['user_id'] = uid
- self.write(cr, uid, case.id, data)
+ self.write(cr, uid, [case.id], data)
self._case_open_notification(case, context=context)
self._action(cr, uid, cases, 'open')
@@ -283,6 +302,7 @@ class crm_base(object):
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
@@ -294,6 +314,7 @@ class crm_base(object):
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
@@ -304,6 +325,7 @@ class crm_base(object):
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
@@ -392,21 +414,6 @@ class crm_case(crm_base):
default.update({ 'date_open': False })
return super(crm_case, self).copy(cr, uid, id, default, context=context)
- 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_escalate_notification(self, case, context=None):
- return True
-
def case_open(self, cr, uid, ids, context=None):
"""Opens Case"""
cases = self.browse(cr, uid, ids)
@@ -414,7 +421,7 @@ class crm_case(crm_base):
data = {'state': 'open', 'active': True }
if not case.user_id:
data['user_id'] = uid
- self.write(cr, uid, case.id, data)
+ self.write(cr, uid, [case.id], data)
self._case_open_notification(case, context=context)
self._action(cr, uid, cases, 'open')
return True
diff --git a/addons/crm/crm_lead.py b/addons/crm/crm_lead.py
index 4a3ae69fba7..18f746880ca 100644
--- a/addons/crm/crm_lead.py
+++ b/addons/crm/crm_lead.py
@@ -189,9 +189,9 @@ class crm_lead(crm_case, osv.osv):
\nIf the case is in progress the state is set to \'Open\'.\
\nWhen the case is over, the state is set to \'Done\'.\
\nIf the case needs to be reviewed then the state is set to \'Pending\'.'),
+ '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"),
@@ -224,6 +224,12 @@ class crm_lead(crm_case, osv.osv):
'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
"""
@@ -265,44 +271,78 @@ class crm_lead(crm_case, osv.osv):
def stage_find_won(self, cr, uid, section_id):
return self.stage_find_percent(cr, uid, 100.0, section_id)
+ 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 created.")
+ elif obj.type=="lead" :
+ message = _("Lead is created.")
+ else:
+ message = _("The case has been created.")
+ 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':
+ if lead.state != 'draft' and lead.state != 'pending':
return False
if lead.type == 'lead':
- message = _("The lead %s has been opened and its state is now in progress. Salesman %s can now set this lead as pending, close it to mark it as done, or cancel it. If there is an opportunity to create from this lead, click on Convert to Opportunity.") % (lead.name, lead.user_id.name)
+ message = _("The lead has been opened.")
elif lead.type == 'opportunity':
- message = _("The opportunity %s has been opened.") % lead.name
+ message = _("The opportunity has been opened.")
else:
- message = _("The case %s has been opened.") % lead.name
+ message = _("The case has been opened.")
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 %s has been closed.") % lead[0].name
+ message = _("The lead has been closed.")
+ elif lead[0].type == 'opportunity':
+ message = _("The opportunity has been closed.")
else:
- message = _("The case %s has been closed.") % lead[0].name
-
- lead[0].message_append_note('' ,message, need_action_user_id=lead[0].user_id.id)
+ message = _("The case has been closed.")
+ lead[0].message_append_note('' ,message)
def _case_mark_lost_notification(self, lead, context=None):
- message = _("The opportunity %s has been marked as lost.") % lead.name
- lead.message_append_note('' ,message, need_action_user_id=lead.user_id.id)
+ lead.message_mark_done(context)
+ message = _("The opportunity has been marked as lost.")
+ lead.message_append_note('' ,message)
def _case_mark_won_notification(self, lead, context=None):
- message = _("The opportunity %s has been been won.") % lead.name
- lead.message_append_note('' ,message, need_action_user_id=lead.user_id.id)
+ lead.message_mark_done(context)
+ message = _("The opportunity has been won.")
+ lead.message_append_note('' ,message)
def _case_cancel_notification(self, lead, context=None):
- message = _("The lead %s has been cancelled.") % (lead[0].name)
- lead[0].message_append_note('' ,message, need_action_user_id=lead[0].user_id.id)
+ lead[0].message_mark_done(context)
+ if lead[0].type == 'lead':
+ message = _("The lead has been cancelled.")
+ elif lead[0].type == 'opportunity':
+ message = _("The opportunity has been cancelled.")
+ lead[0].message_append_note('' ,message)
def _case_pending_notification(self, case, context=None):
- message = _("The lead %s is pending.") % (case[0].name,)
- case[0].message_append_note('' ,message, need_action_user_id=case[0].user_id.id)
+ if case[0].type == 'lead':
+ message = _("The lead is pending.")
+ elif case[0].type == 'opportunity':
+ message = _("The opportunity is pending.")
+ case[0].message_append_note('' ,message)
def _case_escalate_notification(self, case, context=None):
- message = _("The lead %s is pending.") % (case.name,)
- case.message_append_note('' ,message, need_action_user_id=case.user_id.id)
+ message = _("The lead is escalated.")
+ case.message_append_note('' ,message)
+
+ 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 = _("%s a call for the %s.") % (action, obj.date)
+ else :
+ message = _("%s a call.") % (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)
@@ -343,7 +383,6 @@ class crm_lead(crm_case, osv.osv):
stage_id = self.stage_find_lost(cr, uid, lead.section_id.id or False)
if stage_id:
self.stage_set(cr, uid, [lead.id], stage_id)
- self._case_mark_lost_notification(lead, context=context)
return res
def case_mark_won(self, cr, uid, ids, context=None):
@@ -461,7 +500,7 @@ class crm_lead(crm_case, osv.osv):
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')
@@ -571,10 +610,8 @@ class crm_lead(crm_case, osv.osv):
}
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 converted to an opportunity.")
+ 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):
@@ -726,6 +763,7 @@ class crm_lead(crm_case, osv.osv):
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
@@ -868,14 +906,14 @@ class crm_lead(crm_case, osv.osv):
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 %s.") % (stage.name)
+ case.message_append_note(text, 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 %s.") % (stage.name)
+ case.message_append_note(text, message)
return super(crm_lead,self).write(cr, uid, ids, vals, context)
diff --git a/addons/crm/crm_lead_view.xml b/addons/crm/crm_lead_view.xml
index efeda5ac5fc..185f9f55ef8 100644
--- a/addons/crm/crm_lead_view.xml
+++ b/addons/crm/crm_lead_view.xml
@@ -77,6 +77,9 @@
icon="gtk-go-forward" context="{'stage_type': 'lead'}" />
+
@@ -143,18 +146,6 @@
type="object" icon="gtk-convert" />
-
-
-
-
-
-
-
@@ -165,13 +156,6 @@
-
-
-
-
-
-
-
@@ -184,7 +168,7 @@
-
+
@@ -450,6 +434,10 @@
+
+
@@ -536,37 +524,7 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -579,7 +537,7 @@
-
+
diff --git a/addons/crm/crm_meeting.py b/addons/crm/crm_meeting.py
index 40ba8662f13..5ba93d526af 100644
--- a/addons/crm/crm_meeting.py
+++ b/addons/crm/crm_meeting.py
@@ -80,6 +80,21 @@ class crm_meeting(crm_base, osv.osv):
'user_id': lambda self, cr, uid, ctx: uid,
}
+ 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')
+
+ for obj in self.browse(cr, uid, ids, context=context):
+ if(obj.opportunity_id.id):
+ newid = obj.opportunity_id.id
+ message = _("scheduled for meeting %s.") % (obj.date)
+ for lead in lead_obj.browse(cr, uid, [newid], context=context):
+ lead.message_append_note('', message)
+
def case_open(self, cr, uid, ids, *args):
"""Confirms meeting
@param self: The object pointer
diff --git a/addons/crm/crm_phonecall.py b/addons/crm/crm_phonecall.py
index 8d9a47b15eb..4063157aed9 100644
--- a/addons/crm/crm_phonecall.py
+++ b/addons/crm/crm_phonecall.py
@@ -32,6 +32,7 @@ class crm_phonecall(crm_base, osv.osv):
_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 @@ class crm_phonecall(crm_base, osv.osv):
'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,16 @@ class crm_phonecall(crm_base, osv.osv):
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)
+ 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,8 +89,8 @@ class crm_phonecall(crm_base, osv.osv):
_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,
}
@@ -117,7 +122,7 @@ class crm_phonecall(crm_base, osv.osv):
def case_reset(self, cr, uid, ids, *args):
"""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, args)
self.write(cr, uid, ids, {'duration': 0.0, 'state':'open'})
return res
@@ -158,7 +163,7 @@ class crm_phonecall(crm_base, osv.osv):
'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 +248,13 @@ class crm_phonecall(crm_base, osv.osv):
'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 +266,7 @@ class crm_phonecall(crm_base, osv.osv):
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):
"""
diff --git a/addons/sale_crm/wizard/crm_make_sale.py b/addons/sale_crm/wizard/crm_make_sale.py
index c3515cc5b0b..1d898c5cc8d 100644
--- a/addons/sale_crm/wizard/crm_make_sale.py
+++ b/addons/sale_crm/wizard/crm_make_sale.py
@@ -106,9 +106,8 @@ class crm_make_sale(osv.osv_memory):
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)