summaryrefslogtreecommitdiff
path: root/addons/crm/wizard
diff options
context:
space:
mode:
authorMeera Trambadia (OpenERP) <mtr@tinyerp.com>2011-09-16 11:11:38 +0530
committerMeera Trambadia (OpenERP) <mtr@tinyerp.com>2011-09-16 11:11:38 +0530
commitd979aad3de95ae24aa1db52cf17c4eecf3d3ce6b (patch)
tree592698c8e0dab53fcd157dd456a800bd4a80b5bf /addons/crm/wizard
parenteea80125f7d1c739260929fb1f38866ef21439e1 (diff)
parentd101d3fbaaffe2d0219ac6cfeef50338a2501664 (diff)
[MERGE] branch merged with lp:openobject-addons
bzr revid: mtr@tinyerp.com-20110916054138-93b3caomaij5dyp4
Diffstat (limited to 'addons/crm/wizard')
-rw-r--r--addons/crm/wizard/__init__.py2
-rw-r--r--addons/crm/wizard/crm_add_note.py27
-rw-r--r--addons/crm/wizard/crm_lead_to_opportunity.py25
-rw-r--r--addons/crm/wizard/crm_lead_to_partner.py4
-rw-r--r--addons/crm/wizard/crm_merge_opportunities.py62
-rw-r--r--addons/crm/wizard/crm_opportunity_to_phonecall.py35
-rw-r--r--addons/crm/wizard/crm_opportunity_to_phonecall_view.xml19
-rw-r--r--addons/crm/wizard/crm_phonecall_to_opportunity.py29
-rw-r--r--addons/crm/wizard/crm_phonecall_to_phonecall.py16
-rw-r--r--addons/crm/wizard/crm_phonecall_to_phonecall_view.xml13
-rw-r--r--addons/crm/wizard/crm_send_email.py303
-rw-r--r--addons/crm/wizard/crm_send_email_view.xml154
-rw-r--r--addons/crm/wizard/mail_compose_message.py63
-rw-r--r--addons/crm/wizard/wizard_history_event.py2
14 files changed, 172 insertions, 582 deletions
diff --git a/addons/crm/wizard/__init__.py b/addons/crm/wizard/__init__.py
index 9730b8d1d55..3ebdceda437 100644
--- a/addons/crm/wizard/__init__.py
+++ b/addons/crm/wizard/__init__.py
@@ -19,7 +19,7 @@
#
##############################################################################
-import crm_send_email
+import mail_compose_message
import crm_add_note
import crm_lead_to_partner
diff --git a/addons/crm/wizard/crm_add_note.py b/addons/crm/wizard/crm_add_note.py
index 3419c89d33a..478f051fe58 100644
--- a/addons/crm/wizard/crm_add_note.py
+++ b/addons/crm/wizard/crm_add_note.py
@@ -1,11 +1,10 @@
from crm import crm
from osv import fields, osv
from tools.translate import _
-import base64
+from mail.mail_message import truncate_text
AVAILABLE_STATES = crm.AVAILABLE_STATES + [('unchanged', 'Unchanged')]
-
class crm_add_note(osv.osv_memory):
"""Adds a new note to the case."""
_name = 'crm.add.note'
@@ -14,8 +13,11 @@ class crm_add_note(osv.osv_memory):
_columns = {
'body': fields.text('Note Body', required=True),
'state': fields.selection(AVAILABLE_STATES, string='Set New State To',
- required=True),
- 'attachment_ids' : fields.one2many('crm.send.mail.attachment', 'wizard_id'),
+ required=True),
+ }
+
+ _defaults = {
+ 'state': 'unchanged'
}
def action_add(self, cr, uid, ids, context=None):
@@ -32,14 +34,8 @@ class crm_add_note(osv.osv_memory):
case_list = case_pool.browse(cr, uid, context['active_ids'],
context=context)
case = case_list[0]
- user_obj = self.pool.get('res.users')
- user_name = user_obj.browse(cr, uid, [uid], context=context)[0].name
- attach = [
- (x.name, base64.decodestring(x.binary)) for x in obj.attachment_ids
- ]
- case_pool.history(cr, uid, [case], self.pool.get('mailgate.message').truncate_data(cr, uid, obj.body, context=context), history=False,
- details=obj.body, email_from=user_name, attach=attach)
-
+ case_pool.message_append(cr, uid, [case], truncate_text(obj.body),
+ body_text=obj.body)
if obj.state == 'unchanged':
pass
elif obj.state == 'done':
@@ -52,11 +48,4 @@ class crm_add_note(osv.osv_memory):
return {'type': 'ir.actions.act_window_close'}
- def default_get(self, cr, uid, fields, context=None):
- """
- This function gets default values
- """
- return {'state': u'unchanged'}
-
-
crm_add_note()
diff --git a/addons/crm/wizard/crm_lead_to_opportunity.py b/addons/crm/wizard/crm_lead_to_opportunity.py
index 4b6e047f475..8200dbd1675 100644
--- a/addons/crm/wizard/crm_lead_to_opportunity.py
+++ b/addons/crm/wizard/crm_lead_to_opportunity.py
@@ -132,26 +132,25 @@ class crm_lead2opportunity_partner(osv.osv_memory):
vals['partner_address_id'] = False
lead.write(vals, context=context)
- leads.history(cr, uid, [lead], _('Converted to opportunity'), details='Converted to Opportunity', context=context)
+ text = _('Converted to opportunity')
+ leads.message_append(cr, uid, [lead], text, body_text=text, context=context)
if lead.partner_id:
msg_ids = [ x.id for x in lead.message_ids]
- self.pool.get('mailgate.message').write(cr, uid, msg_ids, {
+ self.pool.get('mail.message').write(cr, uid, msg_ids, {
'partner_id': lead.partner_id.id
}, context=context)
leads.log(cr, uid, lead.id, _("Lead '%s' has been converted to an opportunity.") % lead.name)
- def send_mail_to_salesman(self, lead):
+ def send_mail_to_salesman(self, cr, uid, lead):
email_to = lead.user_id and lead.user_id.user_email
if not email_to:
- return
+ return False
+ message_pool = self.pool.get('mail.message')
email_from = lead.section_id and lead.section_id.user_id and lead.section_id.user_id.user_email or email_to
- partner = lead.partner_id and lead.partner_id.name or lead.partner_name
+ partner = lead.partner_id and lead.partner_id.name or lead.partner_name
subject = "lead %s converted into opportunity" % lead.name
- body = "Info \n Id : %s \n Subject: %s \n Partner: %s \n Description : %s " % (lead.id, lead.name, lead.partner_id.name, lead.description)
- try :
- tools.email_send(email_from, [email_to], subject, body)
- except:
- pass
+ body = "Info \n Id : %s \n Subject: %s \n Partner: %s \n Description : %s " % (lead.id, lead.name, lead.partner_id.name, lead.description)
+ return message_pool.schedule_with_attach(cr, uid, email_from, [email_to], subject, body)
def action_apply(self, cr, uid, ids, context=None):
"""
@@ -188,9 +187,9 @@ class crm_lead2opportunity_partner(osv.osv_memory):
for lead in leads.browse(cr, uid, record_id, context=context):
if lead.section_id:
- stage_ids = self.pool.get('crm.case.stage').search(cr, uid, [('type','=','opportunity'),('sequence','>=',1), ('section_ids','=', lead.section_id.id)])
+ stage_ids = self.pool.get('crm.case.stage').search(cr, uid, [('sequence','>=',1), ('section_ids','=', lead.section_id.id)])
else:
- stage_ids = self.pool.get('crm.case.stage').search(cr, uid, [('type','=','opportunity'),('sequence','>=',1)])
+ stage_ids = self.pool.get('crm.case.stage').search(cr, uid, [('sequence','>=',1)])
data = self.browse(cr, uid, ids[0], context=context)
@@ -205,7 +204,7 @@ class crm_lead2opportunity_partner(osv.osv_memory):
partner_id = False
self._convert(cr, uid, ids, lead, partner_id, stage_ids, context=context)
- self.send_mail_to_salesman(lead)
+ self.send_mail_to_salesman(cr, uid, lead)
#If we convert in mass, don't merge if there is no other opportunity but no warning
if data.name == 'merge' and (len(data.opportunity_ids) > 1 or not context.get('mass_convert') ):
merge_obj = self.pool.get('crm.merge.opportunity')
diff --git a/addons/crm/wizard/crm_lead_to_partner.py b/addons/crm/wizard/crm_lead_to_partner.py
index 5dc7e489f26..790c6222de6 100644
--- a/addons/crm/wizard/crm_lead_to_partner.py
+++ b/addons/crm/wizard/crm_lead_to_partner.py
@@ -149,7 +149,6 @@ class crm_lead2partner(osv.osv_memory):
contact_obj = self.pool.get('res.partner.address')
partner_ids = []
partner_id = False
- contact_id = False
rec_ids = context and context.get('active_ids', [])
for data in self.browse(cr, uid, ids, context=context):
@@ -160,7 +159,7 @@ class crm_lead2partner(osv.osv_memory):
'user_id': lead.user_id.id,
'comment': lead.description,
})
- contact_id = contact_obj.create(cr, uid, {
+ contact_obj.create(cr, uid, {
'partner_id': partner_id,
'name': lead.contact_name,
'phone': lead.phone,
@@ -180,7 +179,6 @@ class crm_lead2partner(osv.osv_memory):
else:
if data.partner_id:
partner_id = data.partner_id.id
- contact_id = partner_obj.address_get(cr, uid, [partner_id])['default']
self.assign_partner(cr, uid, lead.id, partner_id)
partner_ids.append(partner_id)
return partner_ids
diff --git a/addons/crm/wizard/crm_merge_opportunities.py b/addons/crm/wizard/crm_merge_opportunities.py
index 248bff2e0e4..d2d46749746 100644
--- a/addons/crm/wizard/crm_merge_opportunities.py
+++ b/addons/crm/wizard/crm_merge_opportunities.py
@@ -1,4 +1,3 @@
-# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
@@ -50,14 +49,9 @@ class crm_merge_opportunity(osv.osv_memory):
def get_attachments(self, cr, uid, id, context=None):
- attach_obj = self.pool.get('ir.attachment')
- attach_ids = attach_obj.search(cr, uid, [('res_model' , '=', 'crm.lead'), ('res_id', '=', id)])
- return attach_ids
-
- def set_attachements_res_id(self, cr, uid, op_id, attach_ids, context=None):
- attach_obj = self.pool.get('ir.attachment')
- attach_obj.write(cr, uid, attach_ids, {'res_id' : op_id})
-
+ proxy = self.pool.get('ir.attachment')
+ ids = proxy.search(cr, uid, [('res_model', '=', 'crm.lead'), ('res_id', '=', id)], context=context)
+ return proxy.browse(cr, uid, ids, context=context)
def find_oldest(self, cr, uid, op_ids, context=None):
if not context:
@@ -67,11 +61,13 @@ class crm_merge_opportunity(osv.osv_memory):
ids = list(set(ids) - set(context.get('lead_ids', False)) )
lead_obj = self.pool.get('crm.lead')
op_id = lead_obj.search(cr, uid, [('id', 'in', ids)], order='create_date' , context=context)
+ if not op_id:
+ return False
opps = lead_obj.browse(cr, uid, [op_id[0]], context=context)
return opps[0]
-
+
def _update_data(self, op_ids, oldest_opp):
- data = {
+ data = {
'partner_id': self._get_first_not_null_id('partner_id', op_ids, oldest_opp), # !!
'title': self._get_first_not_null_id('title', op_ids, oldest_opp),
'name' : self._get_first_not_null('name', op_ids, oldest_opp), #not lost
@@ -104,16 +100,15 @@ class crm_merge_opportunity(osv.osv_memory):
'email_from' : self._get_first_not_null('email_from', op_ids, oldest_opp),
'email_cc' : self._get_first_not_null('email_cc', op_ids, oldest_opp),
'partner_name' : self._get_first_not_null('partner_name', op_ids, oldest_opp),
-
- }
- return data
+ }
+ return data
def merge(self, cr, uid, op_ids, context=None):
"""
- @param opp_ids : list of opportunities ids to merge
+ :param opp_ids: list of opportunities ids to merge
"""
opp_obj = self.pool.get('crm.lead')
- message_obj = self.pool.get('mailgate.message')
+ message_obj = self.pool.get('mail.message')
lead_ids = context and context.get('lead_ids', []) or []
@@ -129,17 +124,25 @@ class crm_merge_opportunity(osv.osv_memory):
else:
first_opportunity = opportunities_list[0]
tail_opportunities = opportunities_list[1:]
-
-
-
data = self._update_data(op_ids, oldest_opp)
+
#copy message into the first opportunity + merge attachement
-
- for opp in tail_opportunities + [first_opportunity]:
- attach_ids = self.get_attachments(cr, uid, opp, context=context)
- self.set_attachements_res_id(cr, uid, first_opportunity.id, attach_ids)
+ count = 1
+ first_attachments = self.get_attachments(cr, uid, first_opportunity, context=context)
+ for opp in tail_opportunities:
+ attachments = self.get_attachments(cr, uid, opp, context=context)
+ for first in first_attachments:
+ for attachment in attachments:
+ if attachment.name == first.name:
+ values = dict(
+ name = "%s (%s)" % (attachment.name, count,),
+ res_id = first_opportunity.id,
+ )
+ attachment.write(values)
+ count+=1
+
for history in opp.message_ids:
- new_history = message_obj.write(cr, uid, history.id, {'res_id': first_opportunity.id, 'name' : _("From %s : %s") % (opp.name, history.name) }, context=context)
+ message_obj.write(cr, uid, history.id, {'res_id': first_opportunity.id, 'name' : _("From %s : %s") % (opp.name, history.name) }, context=context)
#Notification about loss of information
details = []
@@ -171,19 +174,15 @@ class crm_merge_opportunity(osv.osv_memory):
subject = subject[0] + ", ".join(subject[1:])
details = "\n\n".join(details)
- opp_obj._history(cr, uid, [first_opportunity], subject, details=details)
+ opp_obj.message_append(cr, uid, [first_opportunity], subject, body_text=details)
#data.update({'message_ids' : [(6, 0 ,self._concat_o2m('message_ids', op_ids))]})
- opp_obj.write(cr, uid, [first_opportunity.id], data)
+ opp_obj.write(cr, uid, [first_opportunity.id], data, context=context)
unlink_ids = map(lambda x: x.id, tail_opportunities)
opp_obj.unlink(cr, uid, unlink_ids, context=context)
models_data = self.pool.get('ir.model.data')
-
-
# Get Opportunity views
- result = models_data._get_id(
- cr, uid, 'crm', 'view_crm_case_opportunities_filter')
opportunity_view_form = models_data._get_id(
cr, uid, 'crm', 'crm_case_form_view_oppor')
opportunity_view_tree = models_data._get_id(
@@ -217,7 +216,6 @@ class crm_merge_opportunity(osv.osv_memory):
context['lead_ids'] = [op_ids[0].id]
return self.merge(cr, uid, op_ids, context)
-
_columns = {
'opportunity_ids' : fields.many2many('crm.lead', 'merge_opportunity_rel', 'merge_id', 'opportunity_id', 'Opportunities', domain=[('type', '=', 'opportunity')]),
}
@@ -227,7 +225,7 @@ class crm_merge_opportunity(osv.osv_memory):
This function gets default values
@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 uid: the current users ID for security checks,
@param fields: List of fields for default value
@param context: A standard dictionary for contextual values
diff --git a/addons/crm/wizard/crm_opportunity_to_phonecall.py b/addons/crm/wizard/crm_opportunity_to_phonecall.py
index 8fc7ffb310d..714376766f6 100644
--- a/addons/crm/wizard/crm_opportunity_to_phonecall.py
+++ b/addons/crm/wizard/crm_opportunity_to_phonecall.py
@@ -21,6 +21,10 @@
from osv import osv, fields
from tools.translate import _
+import pprint
+pp = pprint.PrettyPrinter(indent=4)
+
+import time
class crm_opportunity2phonecall(osv.osv_memory):
"""Converts Opportunity to Phonecall"""
@@ -31,11 +35,13 @@ class crm_opportunity2phonecall(osv.osv_memory):
_columns = {
'name' : fields.char('Call summary', size=64, required=True, select=1),
'user_id' : fields.many2one('res.users', "Assign To"),
- 'date': fields.datetime('Date' , required=True),
+ 'partner_id' : fields.many2one('res.partner', "Partner"),
+ 'date': fields.datetime('Date'),
'section_id': fields.many2one('crm.case.section', 'Sales Team'),
- 'categ_id': fields.many2one('crm.case.categ', 'Category', required=True, \
+ 'categ_id': fields.many2one('crm.case.categ', 'Category', \
domain="['|',('section_id','=',False),('section_id','=',section_id),\
- ('object_id.model', '=', 'crm.phonecall')]"),
+ ('object_id.model', '=', 'crm.phonecall')]"),
+ 'action': fields.selection([('schedule','Schedule a call'), ('log','Log a call')], 'Action', required=True),
}
def default_get(self, cr, uid, fields, context=None):
@@ -58,6 +64,7 @@ class crm_opportunity2phonecall(osv.osv_memory):
record_ids = context and context.get('active_ids', []) or []
res = super(crm_opportunity2phonecall, self).default_get(cr, uid, fields, context=context)
+ res.update({'action': 'schedule', 'date': time.strftime('%Y-%m-%d %H:%M:%S')})
for opp in opp_obj.browse(cr, uid, record_ids, context=context):
if 'name' in fields:
res.update({'name': opp.name})
@@ -67,6 +74,8 @@ class crm_opportunity2phonecall(osv.osv_memory):
res.update({'section_id': opp.section_id and opp.section_id.id or False})
if 'categ_id' in fields:
res.update({'categ_id': categ_id})
+ if 'partner_id' in fields:
+ res.update({'partner_id': opp.partner_id and opp.partner_id.id or False})
return res
def action_cancel(self, cr, uid, ids, context=None):
@@ -112,23 +121,27 @@ class crm_opportunity2phonecall(osv.osv_memory):
for this in self.browse(cr, uid, ids, context=context):
for opp in opp_obj.browse(cr, uid, record_ids, context=context):
- new_case = phonecall_obj.create(cr, uid, {
+ vals = {
'name' : opp.name,
- 'case_id' : opp.id ,
+ 'case_id' : opp.id,
'user_id' : this.user_id and this.user_id.id or False,
'categ_id' : this.categ_id.id,
'description' : opp.description or False,
'date' : this.date,
- 'section_id' : this.section_id.id or opp.section_id.id or False,
+ 'section_id' : this.section_id.id or False,
'partner_id': opp.partner_id and opp.partner_id.id or False,
'partner_address_id': opp.partner_address_id and opp.partner_address_id.id or False,
'partner_phone' : opp.phone or (opp.partner_address_id and opp.partner_address_id.phone or False),
'partner_mobile' : opp.partner_address_id and opp.partner_address_id.mobile or False,
'priority': opp.priority,
- 'opportunity_id': opp.id
- }, context=context)
-
- phonecall_obj.case_open(cr, uid, [new_case])
+ 'opportunity_id': opp.id,
+ 'date_open': time.strftime('%Y-%m-%d %H:%M:%S')
+ }
+
+ new_case = phonecall_obj.create(cr, uid, vals, context=context)
+
+ if this.action == 'log':
+ phonecall_obj.case_close(cr, uid, [new_case])
value = {
'name': _('Phone Call'),
@@ -139,7 +152,7 @@ class crm_opportunity2phonecall(osv.osv_memory):
'res_id' : new_case,
'views': [(id3, 'form'), (id2, 'tree'), (False, 'calendar')],
'type': 'ir.actions.act_window',
- 'search_view_id': res['res_id']
+ 'search_view_id': res['res_id'],
}
return value
diff --git a/addons/crm/wizard/crm_opportunity_to_phonecall_view.xml b/addons/crm/wizard/crm_opportunity_to_phonecall_view.xml
index 9a623d2eaab..764648a877b 100644
--- a/addons/crm/wizard/crm_opportunity_to_phonecall_view.xml
+++ b/addons/crm/wizard/crm_opportunity_to_phonecall_view.xml
@@ -9,19 +9,22 @@
<field name="model">crm.opportunity2phonecall</field>
<field name="type">form</field>
<field name="arch" type="xml">
- <form string="Schedule a PhoneCall">
- <separator string="Schedule a PhoneCall" colspan="4"/>
+ <form string="Schedule/Log a call">
+ <separator string="Schedule/Log a call" colspan="4"/>
+ <field name="action"/>
+ <separator string="Call Details" colspan="4"/>
<field name="name"/>
- <field name="date" string="Planned Date"/>
+ <field name="date" string="Planned Date" attrs="{'invisible': [('action','=','log')]}"/>
<newline/>
- <field name="user_id" />
+ <field name="partner_id" readonly="True"/>
+ <field name="user_id" />
<field name="section_id" widget="selection" />
<field name="categ_id" string="Type" widget="selection" domain="[('object_id.model', '=', 'crm.phonecall')]"/>
<separator string="" colspan="4"/>
- <group colspan="4">
- <label string ="" colspan="2"/>
+ <group colspan="4" col="3">
<button name="action_cancel" string="_Cancel" icon="gtk-cancel" special="cancel" />
- <button name="action_apply" type="object" string="_Schedule Call" icon="gtk-ok" />
+ <button name="action_apply" type="object" string="Log call" icon="gtk-ok" attrs="{'invisible' : [('action', '!=', 'log')]}" />
+ <button name="action_apply" type="object" string="Schedule call" icon="gtk-ok" attrs="{'invisible' : [('action', '!=', 'schedule')]}" />
</group>
</form>
</field>
@@ -30,7 +33,7 @@
<!-- Opportunity to Phonecall action -->
<record model="ir.actions.act_window" id="opportunity2phonecall_act">
- <field name="name">Schedule Call</field>
+ <field name="name">Schedule/Log Call</field>
<field name="res_model">crm.opportunity2phonecall</field>
<field name="view_type">form</field>
<field name="view_mode">form</field>
diff --git a/addons/crm/wizard/crm_phonecall_to_opportunity.py b/addons/crm/wizard/crm_phonecall_to_opportunity.py
index 32810d2f15e..549afa0559b 100644
--- a/addons/crm/wizard/crm_phonecall_to_opportunity.py
+++ b/addons/crm/wizard/crm_phonecall_to_opportunity.py
@@ -31,43 +31,14 @@ class crm_phonecall2opportunity(osv.osv_memory):
def action_cancel(self, cr, uid, ids, context=None):
"""
Closes Phonecall to Opportunity form
- @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 Phonecall to Opportunity's IDs
- @param context: A standard dictionary for contextual values
"""
return {'type':'ir.actions.act_window_close'}
- def view_init(self, cr, uid, fields, context=None):
- """
- This function checks for precondition before wizard executes
- @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 fields: List of fields for default value
- @param context: A standard dictionary for contextual values
-
- """
- phonecall_obj = self.pool.get('crm.phonecall')
- record_id = context and context.get('active_id', False) or False
- case = phonecall_obj.browse(cr, uid, record_id, context=context)
- if case.state in ['done', 'cancel']:
- raise osv.except_osv(_("Warning"), _("Closed/Cancelled Phone \
-Call can not be converted into Opportunity"))
-
def action_apply(self, cr, uid, ids, context=None):
"""
This converts Phonecall to Opportunity and opens Phonecall view
- @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 Phonecall to Opportunity IDs
- @param context: A standard dictionary for contextual values
-
- @return : Dictionary value for created Opportunity form
"""
record_id = context and context.get('active_id', False) or False
if record_id:
diff --git a/addons/crm/wizard/crm_phonecall_to_phonecall.py b/addons/crm/wizard/crm_phonecall_to_phonecall.py
index aaba8e082c5..2872acad4eb 100644
--- a/addons/crm/wizard/crm_phonecall_to_phonecall.py
+++ b/addons/crm/wizard/crm_phonecall_to_phonecall.py
@@ -22,6 +22,8 @@
from osv import osv, fields
from tools.translate import _
+import time
+
class crm_phonecall2phonecall(osv.osv_memory):
""" Converts Phonecall to Phonecall"""
@@ -84,6 +86,10 @@ class crm_phonecall2phonecall(osv.osv_memory):
'date': this.date
}
phonecall_id = phonecall_obj.create(cr, uid, values, context=context)
+ if this.action == 'schedule':
+ phonecall_obj.case_open(cr, uid, [phonecall_id])
+ elif this.action == 'log':
+ phonecall_obj.case_close(cr, uid, [phonecall_id])
res = {
'name': _('Phone Call'),
@@ -102,11 +108,13 @@ class crm_phonecall2phonecall(osv.osv_memory):
_columns = {
'name' : fields.char('Call summary', size=64, required=True, select=1),
'user_id' : fields.many2one('res.users',"Assign To"),
- 'categ_id': fields.many2one('crm.case.categ', 'Category', required=True, \
+ 'categ_id': fields.many2one('crm.case.categ', 'Category', \
domain="['|',('section_id','=',False),('section_id','=',section_id),\
('object_id.model', '=', 'crm.phonecall')]"),
- 'date': fields.datetime('Date', required=True),
+ 'date': fields.datetime('Date'),
'section_id':fields.many2one('crm.case.section','Sales Team'),
+ 'action': fields.selection([('schedule','Schedule a call'), ('log','Log a call')], 'Action', required=True),
+ 'partner_id' : fields.many2one('res.partner', "Partner"),
}
def default_get(self, cr, uid, fields, context=None):
@@ -122,7 +130,7 @@ class crm_phonecall2phonecall(osv.osv_memory):
"""
res = super(crm_phonecall2phonecall, self).default_get(cr, uid, fields, context=context)
record_id = context and context.get('active_id', False) or False
-
+ res.update({'action': 'schedule', 'date': time.strftime('%Y-%m-%d %H:%M:%S')})
if record_id:
phonecall = self.pool.get('crm.phonecall').browse(cr, uid, record_id, context=context)
@@ -142,6 +150,8 @@ class crm_phonecall2phonecall(osv.osv_memory):
res.update({'section_id': phonecall.section_id and phonecall.section_id.id or False})
if 'categ_id' in fields:
res.update({'categ_id': categ_id})
+ if 'partner_id' in fields:
+ res.update({'partner_id': phonecall.partner_id and phonecall.partner_id.id or False})
return res
crm_phonecall2phonecall()
diff --git a/addons/crm/wizard/crm_phonecall_to_phonecall_view.xml b/addons/crm/wizard/crm_phonecall_to_phonecall_view.xml
index 82c3191a17b..794634da4f1 100644
--- a/addons/crm/wizard/crm_phonecall_to_phonecall_view.xml
+++ b/addons/crm/wizard/crm_phonecall_to_phonecall_view.xml
@@ -9,18 +9,21 @@
<field name="model">crm.phonecall2phonecall</field>
<field name="type">form</field>
<field name="arch" type="xml">
- <form string="Schedule Other Call">
- <separator string="Schedule Other Call" colspan="4"/>
+ <form string="Schedule/Log a call">
+ <separator string="Schedule/Log a call" colspan="4"/>
+ <field name="action"/>
+ <separator string="Call Details" colspan="4"/>
<field name="name"/>
- <field name="date" string="Planned Date"/>
+ <field name="date" string="Planned Date" attrs="{'invisible': [('action','=','log')]}"/>
+ <field name="partner_id" readonly="True"/>
<field name="user_id" />
<field name="section_id"/>
<field name="categ_id" string="Type" widget="selection" domain="[('object_id.model', '=', 'crm.phonecall')]"/>
<separator string=" " colspan="4"/>
<group colspan="4" col="3" >
- <label string=" " />
<button name="action_cancel" string="_Cancel" icon="gtk-cancel" special="cancel" />
- <button name="action_apply" type="object" string="_Schedule" icon="gtk-go-forward" />
+ <button name="action_apply" type="object" string="Log call" icon="gtk-ok" attrs="{'invisible' : [('action', '!=', 'log')]}" />
+ <button name="action_apply" type="object" string="Schedule call" icon="gtk-ok" attrs="{'invisible' : [('action', '!=', 'schedule')]}" />
</group>
</form>
</field>
diff --git a/addons/crm/wizard/crm_send_email.py b/addons/crm/wizard/crm_send_email.py
deleted file mode 100644
index d4ba8b476a1..00000000000
--- a/addons/crm/wizard/crm_send_email.py
+++ /dev/null
@@ -1,303 +0,0 @@
-# -*- coding: utf-8 -*-
-##############################################################################
-#
-# OpenERP, Open Source Management Solution
-# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>). All Rights Reserved
-# $Id$
-#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU Affero General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU Affero General Public License for more details.
-#
-# You should have received a copy of the GNU Affero General Public License
-# along with this program. If not, see <http://www.gnu.org/licenses/>.
-#
-##############################################################################
-
-from crm import crm
-from osv import osv, fields
-from tools.translate import _
-import base64
-import itertools
-import tools
-import re
-
-
-AVAILABLE_STATES = crm.AVAILABLE_STATES + [('unchanged', 'Unchanged')]
-
-
-class crm_send_new_email_attachment(osv.osv_memory):
- _name = 'crm.send.mail.attachment'
-
- _columns = {
- 'binary' : fields.binary('Attachment', required=True),
- 'name' : fields.char('Name', size=128, required=True),
- 'wizard_id' : fields.many2one('crm.send.mail', 'Wizard', required=True),
- }
-
-crm_send_new_email_attachment()
-
-class crm_send_new_email(osv.osv_memory):
- """ Sends new email for the case"""
- _name = "crm.send.mail"
- _description = "Send new email"
-
- _columns = {
- 'email_to' : fields.char('To', size=512, required=True),
- 'email_from' : fields.char('From', size=128, required=True),
- 'reply_to' : fields.char('Reply To', size=128, required=True, help="Reply-to of the Sales team defined on this case"),
- 'email_cc' : fields.char('CC', size=512, help="These addresses will receive a copy of this email. To modify the permanent CC list, edit the global CC field of this case"),
- 'subject': fields.char('Subject', size=512, required=True),
- 'body': fields.text('Message Body', required=True),
- 'state': fields.selection(AVAILABLE_STATES, string='Set New State To', required=True),
- 'attachment_ids' : fields.one2many('crm.send.mail.attachment', 'wizard_id', 'Attachment'),
- 'html': fields.boolean('HTML formatting?', help="Select this if you want to send email with HTML formatting."),
- }
-
- def action_mass_send(self, cr, uid, ids, context=None):
-
- if not context:
- context = {}
-
- context.update({'mail' : 'new'})
- actives_ids = context.get('active_ids')
- model = context.get('active_model')
- case_pool = self.pool.get(model)
- for id in actives_ids:
- context.update({'active_id' : id})
- self.action_send(cr, uid, ids, context=context)
-
- return {'type': 'ir.actions.act_window_close'}
-
- def action_send(self, cr, uid, ids, context=None):
- """ This sends an email to ALL the addresses of the selected partners.
- """
- hist_obj = self.pool.get('mailgate.message')
-
- if context is None:
- context = {}
-
- if not context.get('active_model'):
- raise osv.except_osv(_('Error'), _('Can not send mail!'))
-
- model = context.get('active_model')
- case_pool = self.pool.get(model)
- res_id = context and context.get('active_id', False) or False
-
-
-
- for obj in self.browse(cr, uid, ids, context=context):
- attach = [
- (x.name, base64.decodestring(x.binary)) for x in obj.attachment_ids
- ]
-
- subtype = 'plain'
- message_id = None
- ref_id = None
-
- case = case_pool.browse(cr, uid, res_id, context=context)
- if context.get('mail', 'new') == 'new':
- if case.message_ids:
- message_id = case.message_ids[0].message_id
- elif context.get('mail') == 'forward':
- # extract attachements from case and emails according to mode
- attachments = []
- attach_pool = self.pool.get('ir.attachment')
- direct_attachments = attach_pool.search(cr, uid, [('res_model', '=', 'crm.lead'), ('res_id', '=', res_id)], context=context)
- attachments += attach_pool.browse(cr, uid, direct_attachments, context=context)
- if obj.history in ['latest', 'whole'] and case.message_ids:
- msgs = case.message_ids
- if obj.history == 'latest':
- msgs = msgs[:1]
- attachments.extend(itertools.chain(*[m.attachment_ids for m in msgs]))
- attach_all = [(a.datas_fname or a.name, base64.decodestring(a.datas)) for a in attachments if a.datas]
- attach += attach_all
-
- else:
- hist = hist_obj.browse(cr, uid, res_id, context=context)
- message_id = hist.message_id
- model = hist.model
- case_pool = self.pool.get(model)
- res_id = hist.res_id
- ref_id = hist.ref_id
- case = case_pool.browse(cr, uid, res_id, context=context)
-
- if context.get('mass_mail'):
- email_temp = case.email_from and tools.ustr(case.email_from) or ''
- emails = re.findall(r'([^ ,<@]+@[^> ,]+)', email_temp)
- else:
- emails = re.findall(r'([^ ,<@]+@[^> ,]+)', obj.email_to or '')
-
- email_cc = re.findall(r'([^ ,<@]+@[^> ,]+)', obj.email_cc or '')
-
- emails = filter(None, emails)
- body = obj.body
-
- body = body and tools.ustr(body) or ''
- email_from = getattr(obj, 'email_from', False)
- x_headers = {}
- if message_id:
- x_headers['References'] = "%s" % (message_id)
-
- if obj.html:
- subtype = 'html'
-
- flag = tools.email_send(
- email_from,
- emails,
- obj.subject,
- body,
- email_cc=email_cc,
- attach=attach,
- subtype=subtype,
- reply_to=obj.reply_to,
- openobject_id=str(case.id),
- x_headers=x_headers
- )
-
- if not flag:
- raise osv.except_osv(_('Error!'), _('Unable to send mail. Please check SMTP is configured properly.'))
-
- msg_dict = {'new': 'Send', 'reply': 'Reply', 'forward': 'Forward'}
- case_pool.history(cr, uid, [case], _(msg_dict[context.get('mail', 'new')]), history=True, \
- email=obj.email_to, details=body, \
- subject=obj.subject, email_from=email_from, \
- email_cc=', '.join(email_cc), message_id=message_id, \
- references=ref_id or message_id, attach=attach)
- if obj.state == 'unchanged':
- pass
- elif obj.state == 'done':
- case_pool.case_close(cr, uid, [case.id])
- elif obj.state == 'draft':
- case_pool.case_reset(cr, uid, [case.id])
- elif obj.state in ['cancel', 'open', 'pending']:
- act = 'case_' + obj.state
- getattr(case_pool, act)(cr, uid, [case.id])
-
- return {'type': 'ir.actions.act_window_close'}
-
- def default_get(self, cr, uid, fields, context=None):
- """
- This function gets default values
- """
- if context is None:
- context = {}
-
- if not context.get('active_model'):
- raise osv.except_osv(_('Error'), _('Can not send mail!'))
-
- res = super(crm_send_new_email, self).default_get(cr, uid, fields, context=context)
-
- if context.get('mail') == 'reply':
- res.update(self.get_reply_defaults(cr, uid, fields, context=context))
- return res
-
- model = context.get('active_model')
- mod_obj = self.pool.get(model)
- res_id = context and context.get('active_ids', []) or []
-
- user_obj = self.pool.get('res.users')
- user_mail_from = user_obj._get_email_from(cr, uid, [uid], context=context)[uid]
- for case in mod_obj.browse(cr, uid, res_id, context=context):
- if 'email_to' in fields:
- res.update({'email_to': case.email_from and tools.ustr(case.email_from) or ''})
- if context.get('mass_mail'):
- res.update({'email_to': ''})
- if 'email_from' in fields:
- res.update({'email_from': user_mail_from and tools.ustr(user_mail_from) or ''})
- if 'reply_to' in fields:
- if hasattr(case, 'section_id'):
- res.update({'reply_to': case.section_id and case.section_id.reply_to or False})
- if 'subject' in fields:
- res.update({'subject': tools.ustr(context.get('subject', case.name) or '')})
- if context.get('mass_mail'):
- res.update({'subject': ''})
- if 'email_cc' in fields:
- res.update({'email_cc': tools.ustr(case.email_cc or '')})
- if context.get('mass_mail'):
- res.update({'email_cc': ''})
- if 'body' in fields:
- res.update({'body': u'\n'+(tools.ustr(case.user_id.signature or ''))})
- if 'state' in fields:
- res.update({'state': u'pending'})
-
- return res
-
- def get_reply_defaults(self, cr, uid, fields, context=None):
- """
- This function gets default values for reply mail
- """
- hist_obj = self.pool.get('mailgate.message')
- res_ids = context and context.get('active_ids', []) or []
-
- user_obj = self.pool.get('res.users')
- user_mail_from = user_obj._get_email_from(cr, uid, [uid], context=context)[uid]
-
- include_original = context and context.get('include_original', False) or False
- res = {}
- for hist in hist_obj.browse(cr, uid, res_ids, context=context):
- model = hist.model
-
- # In the case where the crm.case does not exist in the database
- if not model:
- return {'type': 'ir.actions.act_window_close'}
-
- model_pool = self.pool.get(model)
- res_id = hist.res_id
- case = model_pool.browse(cr, uid, res_id)
- if 'email_to' in fields:
- res.update({'email_to': case.email_from and tools.ustr(case.email_from) or False})
- if 'email_from' in fields:
- res.update({'email_from': user_mail_from and tools.ustr(user_mail_from) or False})
-
- signature = u'\n' + (tools.ustr(case.user_id.signature or '')) + u'\n'
- original = [signature]
-
- if include_original == True and 'body' in fields:
- header = u'-------- Original Message --------'
- sender = u'From: %s' %(tools.ustr(hist.email_from or ''))
- to = u'To: %s' % (tools.ustr(hist.email_to or ''))
- sentdate = u'Date: %s' % (tools.ustr(hist.date))
- desc = u'\n%s'%(tools.ustr(hist.description))
-
- original = [signature, header, sender, to, sentdate, desc]
-
- res['body']= u'\n' + u'\n'.join(original)
-
- if 'subject' in fields:
- res.update({u'subject': u'Re: %s' %(tools.ustr(hist.name or ''))})
- if 'email_cc' in fields:
- email_cc = (case.email_cc and tools.ustr(case.email_cc) + ', ' or '') + (hist.email_cc or '')
- res.update({'email_cc': email_cc})
- if 'reply_to' in fields:
- if hasattr(case, 'section_id'):
- res.update({'reply_to': case.section_id.reply_to or ''})
- if 'state' in fields:
- res['state'] = u'pending'
- return res
-
- def view_init(self, cr, uid, fields_list, context=None):
- """
- This function checks for precondition before wizard executes
- @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 fields: List of fields for default value
- @param context: A standard dictionary for contextual values
-
- """
- if context is None:
- context = {}
-
- if not context.get('active_model'):
- raise osv.except_osv(_('Error'), _('Can not send mail!'))
- return True
-
-crm_send_new_email()
-
diff --git a/addons/crm/wizard/crm_send_email_view.xml b/addons/crm/wizard/crm_send_email_view.xml
deleted file mode 100644
index be1644b6bbb..00000000000
--- a/addons/crm/wizard/crm_send_email_view.xml
+++ /dev/null
@@ -1,154 +0,0 @@
-<?xml version="1.0"?>
-<openerp>
- <data>
-
-<!-- Send New Mail view -->
-
- <record model="ir.ui.view" id="crm_send_new_mail_view">
- <field name="name">crm.new.send.mail.form</field>
- <field name="model">crm.send.mail</field>
- <field name="type">form</field>
- <field name="arch" type="xml">
- <form string="Send Mail" col="4">
- <group colspan="4" col="2">
- <field name="email_from"/>
- <field name="reply_to"/>
- <field name="email_to" />
- <field name="email_cc"/>
- <field name="subject"/>
- <field name="html"/>
- </group>
- <notebook colspan="6">
- <page string="Message">
- <field name="body" nolabel="1" colspan="4" default_focus="1"/>
- </page>
- <page string="Attachments">
- <field name="attachment_ids" colspan="4" nolabel="1">
- <form string="Attachment">
- <field name="binary" filename="name" />
- <field name="name" />
- </form>
- <tree string="Attachments">
- <field name="name" />
- </tree>
- </field>
- </page>
- </notebook>
- <separator string="" colspan="6"/>
- <group colspan="6" col="4" >
- <field name="state" />
- <button string="_Cancel" icon="gtk-close" special="cancel" />
- <button name="action_send" type="object" string="_Send" icon="gtk-go-forward" />
- </group>
- </form>
- </field>
- </record>
-
- <record model="ir.ui.view" id="crm_send_new_mass_mail_view">
- <field name="name">crm.new.send.mass.mail.form</field>
- <field name="model">crm.send.mail</field>
- <field name="type">form</field>
- <field name="arch" type="xml">
- <form string="Send Mail" col="4">
- <group colspan="4" col="2">
- <field name="email_from"/>
- <field name="reply_to"/>
- <field name="email_cc"/>
- <field name="subject" />
- <field name="html"/>
- </group>
- <notebook colspan="6">
- <page string="Message">
- <field name="body" nolabel="1" colspan="4" default_focus="1"/>
- </page>
- <page string="Attachments">
- <field name="attachment_ids" colspan="4" nolabel="1">
- <form string="Attachment">
- <field name="binary" filename="name" />
- <field name="name" />
- </form>
- <tree string="Attachments">
- <field name="name" />
- </tree>
- </field>
- </page>
- </notebook>
- <separator string="" colspan="6"/>
- <group colspan="6" col="4" >
- <field name="state" />
- <button string="_Cancel" icon="gtk-cancel" special="cancel" />
- <button name="action_mass_send" type="object" string="_Send to All" icon="gtk-go-forward" />
- </group>
- </form>
- </field>
- </record>
-
-<!-- Send New Mail action -->
-
- <record model="ir.actions.act_window" id="action_crm_send_mail">
- <field name="name">Send Mail</field>
- <field name="res_model">crm.send.mail</field>
- <field name="view_type">form</field>
- <field name="view_mode">form</field>
- <field name="view_id" ref="crm_send_new_mail_view"/>
- <field name="target">new</field>
- </record>
-
-
- <act_window id="action_crm_send_mass_mail"
- multi="True"
- key2="client_action_multi" name="Send emails"
- res_model="crm.send.mail" src_model="crm.lead"
- view_mode="form" target="new" view_type="form"
- context="{'mass_mail' : True}"
- view_id="crm_send_new_mass_mail_view"/>
-
- <!-- Reply to Mail view -->
-
- <record model="ir.ui.view" id="crm_reply_mail_view">
- <field name="name">crm.mail.reply.form</field>
- <field name="model">crm.send.mail</field>
- <field name="type">form</field>
- <field name="arch" type="xml">
- <form string="Reply to last Mail" col="2">
- <field name="email_from" />
- <field name="email_to" />
- <field name="email_cc" />
- <field name="subject" />
- <field name="attachment_ids" colspan="4" nolabel="1">
- <form string="Attachment">
- <field name="binary" filename="name" />
- <field name="name" />
- </form>
- <tree string="Attachments">
- <field name="name" />
- </tree>
- </field>
- <separator string="" colspan="4"/>
- <field name="body" nolabel="1" colspan="4"/>
- <separator string=" " colspan="4"/>
- <group colspan="4" col="3" >
- <label string=" " />
- <button string="_Cancel" icon="gtk-close" special="cancel" />
- <button name="action_send" type="object" string="_Send Reply" icon="gtk-go-forward" />
- </group>
- </form>
- </field>
- </record>
-
-
-
-
-<!-- Reply to Mail action -->
-
- <record model="ir.actions.act_window" id="action_crm_reply_mail">
- <field name="name">Reply to last Mail</field>
- <field name="res_model">crm.send.mail</field>
- <field name="view_type">form</field>
- <field name="view_mode">form</field>
- <field name="view_id" ref="crm_reply_mail_view"/>
- <field name="target">new</field>
- </record>
-
- </data>
-</openerp>
diff --git a/addons/crm/wizard/mail_compose_message.py b/addons/crm/wizard/mail_compose_message.py
new file mode 100644
index 00000000000..512d9ece77a
--- /dev/null
+++ b/addons/crm/wizard/mail_compose_message.py
@@ -0,0 +1,63 @@
+# -*- coding: utf-8 -*-
+##############################################################################
+#
+# OpenERP, Open Source Management Solution
+# Copyright (C) 2010-Today OpenERP SA (<http://www.openerp.com>)
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>
+#
+##############################################################################
+
+from osv import osv
+from osv import fields
+import tools
+
+SUPPORTED_MODELS = ['crm.lead',]
+
+class mail_compose_message(osv.osv_memory):
+ _inherit = 'mail.compose.message'
+
+ def get_value(self, cr, uid, model, res_id, context=None):
+ """Returns a defaults-like dict with initial values for the composition
+ wizard when sending an email related to the document record identified
+ by ``model`` and ``res_id``.
+
+ Overrides the default implementation to provide more default field values
+ related to the corresponding CRM case.
+
+ :param str model: model name of the document record this mail is related to.
+ :param int res_id: id of the document record this mail is related to.
+ :param dict context: several context values will modify the behavior
+ of the wizard, cfr. the class description.
+ """
+ result = super(mail_compose_message, self).get_value(cr, uid, model, res_id, context=context)
+ if model in SUPPORTED_MODELS and res_id:
+ model_obj = self.pool.get(model)
+ data = model_obj.browse(cr, uid , res_id, context)
+ user = self.pool.get('res.users').browse(cr, uid, uid, context=context)
+ result.update({
+ 'subject' : data.name or False,
+ 'email_to' : data.email_from or False,
+ 'email_from' : user.user_email or tools.config.get('email_from', False),
+ 'body_text' : '\n' + tools.ustr(user.signature),
+ 'email_cc' : tools.ustr(data.email_cc or ''),
+ 'model': model,
+ 'res_id': res_id,
+ 'subtype': 'plain',
+ })
+ if hasattr(data, 'section_id'):
+ result.update({'reply_to' : data.section_id and data.section_id.reply_to or False})
+ return result
+
+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
diff --git a/addons/crm/wizard/wizard_history_event.py b/addons/crm/wizard/wizard_history_event.py
index caaf37a88d8..bb501e0b750 100644
--- a/addons/crm/wizard/wizard_history_event.py
+++ b/addons/crm/wizard/wizard_history_event.py
@@ -32,7 +32,7 @@ def _open_history_event(self, cr, uid, data, context=None):
if id2:
id2 = data_obj.browse(cr, uid, id2, context=context).res_id
res = ''
- if data.get('model',False) and data.get('ids',False):
+ if data.get('model') and data.get('ids'):
model_obj = pooler.get_pool(cr.dbname).get(data['model'])
res = model_obj.browse(cr, uid, data['ids'], context=context)
if len(res):