[ADD] crm: use company/contact name for fill partner_info in chatter
authorDenis Ledoux <dle@odoo.com>
Thu, 31 Jul 2014 13:33:41 +0000 (15:33 +0200)
committerDenis Ledoux <dle@odoo.com>
Thu, 31 Jul 2014 13:33:41 +0000 (15:33 +0200)
Sometimes, when you send an email in the chatter, a pop-up is displayed to fill the partner details
This case happens when the email address you send the email is not associated to an existing partner
In such cases, in lead, we use the company name and contact name to fill the partner name

addons/crm/crm_lead.py

index b82f5a4..c4fd782 100644 (file)
@@ -29,6 +29,7 @@ from openerp import tools
 from openerp.addons.base.res.res_partner import format_address
 from openerp.osv import fields, osv, orm
 from openerp.tools.translate import _
+from openerp.tools import email_re
 
 CRM_LEAD_FIELDS_TO_MERGE = ['name',
     'partner_id',
@@ -1032,4 +1033,16 @@ class crm_lead(format_address, osv.osv):
             return {'value':{'country_id':country_id}}
         return {}
 
+    def message_partner_info_from_emails(self, cr, uid, id, emails, link_mail=False, context=None):
+        res = super(crm_lead, self).message_partner_info_from_emails(cr, uid, id, emails, link_mail=link_mail, context=context)
+        lead = self.browse(cr, uid, id, context=context)
+        for partner_info in res:
+            if not partner_info.get('partner_id') and (lead.partner_name or lead.contact_name):
+                emails = email_re.findall(partner_info['full_name'] or '')
+                email = emails and emails[0] or ''
+                if email and lead.email_from and email.lower() == lead.email_from.lower():
+                    partner_info['full_name'] = '%s <%s>' % (lead.partner_name or lead.contact_name, email)
+                    break
+        return res
+
 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: