From 5aa72a05f158fdb0b8e625f20b90a5b24d9e535a Mon Sep 17 00:00:00 2001 From: Mantavya Gajjar Date: Sun, 18 Apr 2010 02:37:21 +0530 Subject: [PATCH] [REVIEW]: improvement in to the crm module improvement in crm for email integration bzr revid: mga@tinyerp.com-20100417210721-9munqmiyynacaia4 --- addons/crm/__terp__.py | 37 ++++++++-------- addons/crm/crm.py | 2 + addons/crm/crm_mailgate.py | 5 +-- addons/crm/crm_view.xml | 33 +++++++++++---- .../openerp_mailgate/openerp_mailgate.py | 2 +- addons/crm/wizard/crm_send_email.py | 42 +++++++++++++------ 6 files changed, 78 insertions(+), 43 deletions(-) diff --git a/addons/crm/__terp__.py b/addons/crm/__terp__.py index f84d5bd5b69..b3e45a33978 100644 --- a/addons/crm/__terp__.py +++ b/addons/crm/__terp__.py @@ -44,21 +44,24 @@ The CRM module has a email gateway for the synchronisation interface between mails and Open ERP.""", 'author': 'Tiny', 'website': 'http://www.openerp.com', - 'depends': ['base', 'base_action_rule', - 'process', - 'mail_gateway', - 'base_calendar', - 'resource', - ], - 'init_xml': ['crm_data.xml', - 'crm_meeting_data.xml', - 'crm_claims_data.xml', - 'crm_fund_data.xml', - 'crm_helpdesk_data.xml', - 'crm_lead_data.xml', - 'crm_meeting_data.xml', - 'crm_opportunity_data.xml', - 'crm_phonecall_data.xml', + 'depends': [ + 'base', + 'base_action_rule', + 'process', + 'mail_gateway', + 'base_calendar', + 'resource', + ], + 'init_xml': [ + 'crm_data.xml', + 'crm_meeting_data.xml', + 'crm_claims_data.xml', + 'crm_fund_data.xml', + 'crm_helpdesk_data.xml', + 'crm_lead_data.xml', + 'crm_meeting_data.xml', + 'crm_opportunity_data.xml', + 'crm_phonecall_data.xml', ], 'update_xml': [ @@ -104,7 +107,6 @@ between mails and Open ERP.""", 'report/crm_phonecall_report_view.xml', 'process/crm_configuration_process.xml', - ], 'demo_xml': [ 'crm_demo.xml', @@ -114,7 +116,8 @@ between mails and Open ERP.""", 'crm_lead_demo.xml', 'crm_meeting_demo.xml', 'crm_opportunity_demo.xml', - 'crm_phonecall_demo.xml'], + 'crm_phonecall_demo.xml' + ], 'installable': True, 'active': False, 'certificate': '0079056041421', diff --git a/addons/crm/crm.py b/addons/crm/crm.py index 74f71f72931..09901defab4 100644 --- a/addons/crm/crm.py +++ b/addons/crm/crm.py @@ -64,6 +64,8 @@ class crm_case_section(osv.osv): 'parent_id': fields.many2one('crm.case.section', 'Parent Section'), 'child_ids': fields.one2many('crm.case.section', 'parent_id', 'Child Sections'), 'resource_calendar_id': fields.many2one('resource.calendar', "Resource's Calendar"), + 'server_id':fields.many2one('email.smtpclient', 'Server ID'), + 'note': fields.text('Description'), } _defaults = { diff --git a/addons/crm/crm_mailgate.py b/addons/crm/crm_mailgate.py index 5b8eaf2c5e8..17d182728a3 100644 --- a/addons/crm/crm_mailgate.py +++ b/addons/crm/crm_mailgate.py @@ -72,7 +72,7 @@ class crm_cases(osv.osv): self._history(cr, uid, cases, _('Receive'), history=True, details=body, email_from=msg_from, message_id=msg.get('id')) return res - def message_update(self, cr, uid, ids, msg, default_act='pending', context={}): + def message_update(self, cr, uid, ids, vals={}, msg="", default_act='pending', context={}): """ @param self: The object pointer @param cr: the current row, from the database cursor, @@ -80,7 +80,6 @@ class crm_cases(osv.osv): @param ids: List of update mail’s IDs """ - vals = { } if isinstance(ids, (str, int, long)): ids = [ids] @@ -102,7 +101,7 @@ class crm_cases(osv.osv): res = self.write(cr, uid, ids, vals) cases = self.browse(cr, uid, ids) - message_id = context.get('message_id', False) + message_id = context.get('references_id', False) self._history(cr, uid, cases, _('Receive'), history=True, details=msg['body'], email_from=msg_from, message_id=message_id) #getattr(self, act)(cr, uid, select) return res diff --git a/addons/crm/crm_view.xml b/addons/crm/crm_view.xml index 31dd875b7e0..356597fe10e 100644 --- a/addons/crm/crm_view.xml +++ b/addons/crm/crm_view.xml @@ -11,16 +11,31 @@ form
- + + + + + + + - - - - - - - - + + + + + + + + + + + + + + + + + diff --git a/addons/crm/scripts/openerp_mailgate/openerp_mailgate.py b/addons/crm/scripts/openerp_mailgate/openerp_mailgate.py index 497f1014eb9..bb0adb0444a 100755 --- a/addons/crm/scripts/openerp_mailgate/openerp_mailgate.py +++ b/addons/crm/scripts/openerp_mailgate/openerp_mailgate.py @@ -282,7 +282,7 @@ class email_parser(object): if actions['state'] in ['draft', 'close', 'cancel', 'open', 'pending']: act = 'case_' + actions['state'] - for k1, k2 in [('cost', 'planned_cost'), ('revenue', 'planned_revenue'), ('probability', 'probability')]: + for k1, k2 in [('cost', 'planned_cost'), ('revenue', 'planned_revenue'), ('probability', 'probability')]: try: data[k2] = float(actions[k1]) except: diff --git a/addons/crm/wizard/crm_send_email.py b/addons/crm/wizard/crm_send_email.py index ac8e321c8c1..5fe6b18d06b 100644 --- a/addons/crm/wizard/crm_send_email.py +++ b/addons/crm/wizard/crm_send_email.py @@ -56,6 +56,7 @@ class crm_send_new_email(osv.osv_memory): """ hist_obj = self.pool.get('crm.case.history') + smtp_pool = self.pool.get('email.smtpclient') if not context: context = {} @@ -73,8 +74,8 @@ class crm_send_new_email(osv.osv_memory): message_id = None + case = case_pool.browse(cr, uid, res_id) if context.get('mail', 'new') == 'new': - case = case_pool.browse(cr, uid, res_id) message_id = case.history_line[0].message_id else: hist = hist_obj.browse(cr, uid, res_id) @@ -91,19 +92,34 @@ class crm_send_new_email(osv.osv_memory): case_pool._history(cr, uid, [case], _('Send'), history=True, email=data['email_to'], details=body, email_from=email_from, message_id=message_id) x_headers = { - 'References':"%s" % (message_id) + 'References':"%s" % (message_id), + 'Reply-To':"%s" % case.section_id.reply_to, } - - flag = tools.email_send( - email_from, - emails, - data['subject'], - body, - attach=attach, - reply_to=case.section_id.reply_to, - openobject_id=str(case.id), - x_headers=x_headers - ) + flag = False + if case.section_id and case.section_id.server_id: + + flag = smtp_pool.send_email( + cr=cr, + uid=uid, + server_id=case.section_id.server_id.id, + emailto=emails, + subject=data['subject'], + body="
%s
" % body, + attachments=attach, + headers=x_headers + ) + else: + flag = tools.email_send( + email_from, + emails, + data['subject'], + body, + attach=attach, + reply_to=case.section_id.reply_to, + openobject_id=str(case.id), + x_headers=x_headers + ) + if flag: if data['state'] == 'unchanged': pass