[Merge] Merge bth branch for get changes on crm_base and crm_case.

bzr revid: jra@tinyerp.com-20120229114040-hdq38p599tdzhg7g
This commit is contained in:
Jiten (OpenERP)
2012-02-29 17:10:40 +05:30
6 changed files with 138 additions and 116 deletions
+24 -17
View File
@@ -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
+68 -30
View File
@@ -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 <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':
if lead.state != 'draft' and lead.state != 'pending':
return False
if lead.type == 'lead':
message = _("The lead <em>%s</em> 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 <b>opened</b>.")
elif lead.type == 'opportunity':
message = _("The opportunity <em>%s</em> has been opened.") % lead.name
message = _("The opportunity has been <b>opened</b>.")
else:
message = _("The case <em>%s</em> has been opened.") % lead.name
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 <em>%s</em> has been closed.") % lead[0].name
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 <em>%s</em> 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 <b>closed</b>.")
lead[0].message_append_note('' ,message)
def _case_mark_lost_notification(self, lead, context=None):
message = _("The opportunity <em>%s</em> 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 <b>marked as lost</b>.")
lead.message_append_note('' ,message)
def _case_mark_won_notification(self, lead, context=None):
message = _("The opportunity <em>%s</em> 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 <b>won</b>.")
lead.message_append_note('' ,message)
def _case_cancel_notification(self, lead, context=None):
message = _("The lead <em>%s</em> 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 <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):
message = _("The lead <em>%s</em> 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 <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 <em>%s</em> is pending.") % (case.name,)
case.message_append_note('' ,message, need_action_user_id=case.user_id.id)
message = _("The lead is <b>escalated</b>.")
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 = _("<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)
@@ -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 <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):
@@ -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 <b>%s</b>.") % (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 <b>%s</b>.") % (stage.name)
case.message_append_note(text, message)
return super(crm_lead,self).write(cr, uid, ids, vals, context)
+9 -51
View File
@@ -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,18 +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>
<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"/>
@@ -165,13 +156,6 @@
<field name="channel_id" select="1" widget="selection"/>
<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)"/>
@@ -184,7 +168,7 @@
</group>
</page>
</notebook>
<field name="message_ids_social" colspan="4" widget="ThreadView" nolabel="1"/>
<field name="message_ids_social" widget="ThreadView"/>
</form>
</field>
</record>
@@ -450,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"/>
@@ -536,37 +524,7 @@
<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"/>
@@ -579,7 +537,7 @@
<field name="ref2"/>
</page>
</notebook>
<field name="message_ids_social" colspan="4" widget="ThreadView" nolabel="1"/>
<field name="message_ids_social" widget="ThreadView"/>
</form>
</field>
</record>
+15
View File
@@ -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 = _("<b>scheduled for meeting</b> %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
+20 -15
View File
@@ -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):
"""
+2 -3
View File
@@ -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)