← Back to team overview

openerp-community-reviewer team mailing list archive

[Merge] lp:~camptocamp/partner-contact-management/partner_firstname_vre_firstname_crm into lp:partner-contact-management

 

Vincent Renaville@camptocamp has proposed merging lp:~camptocamp/partner-contact-management/partner_firstname_vre_firstname_crm into lp:partner-contact-management.

Requested reviews:
  Partner and Contact Core Editors (partner-contact-core-editors)

For more details, see:
https://code.launchpad.net/~camptocamp/partner-contact-management/partner_firstname_vre_firstname_crm/+merge/213673

This add the functionality :

- When a email is received , it will create the lead + the partner (Firstname and Lastname is discovered based on email address).

- The partner created is set as follower of the lead.


-- 
https://code.launchpad.net/~camptocamp/partner-contact-management/partner_firstname_vre_firstname_crm/+merge/213673
Your team Partner and Contact Core Editors is requested to review the proposed merge of lp:~camptocamp/partner-contact-management/partner_firstname_vre_firstname_crm into lp:partner-contact-management.
=== added directory 'crm_firstname'
=== added file 'crm_firstname/__init__.py'
--- crm_firstname/__init__.py	1970-01-01 00:00:00 +0000
+++ crm_firstname/__init__.py	2014-04-01 15:22:09 +0000
@@ -0,0 +1,21 @@
+# -*- coding: utf-8 -*-
+##############################################################################
+#
+#   Copyright (c) 2013 Camptocamp SA (http://www.camptocamp.com)
+#   @author Vincent Renaville
+#
+#    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 . import crm

=== added file 'crm_firstname/__openerp__.py'
--- crm_firstname/__openerp__.py	1970-01-01 00:00:00 +0000
+++ crm_firstname/__openerp__.py	2014-04-01 15:22:09 +0000
@@ -0,0 +1,37 @@
+# -*- coding: utf-8 -*-
+##############################################################################
+#
+#   Copyright (c) 2013 Camptocamp SA (http://www.camptocamp.com)
+#   @author Vincent Renaville
+#
+#    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/>.
+#
+##############################################################################
+
+{'name': 'CRM firstname lastname, and view improvement',
+ 'version': '1.0.0',
+ 'category': 'other',
+ 'description': """CRM firstname""",
+ 'author': 'Camptocamp',
+ 'website': 'http://www.camptocamp.com',
+ 'depends': ['crm','partner_firstname'],
+ 'data': [
+          'data.xml',
+          'crm_view.xml'
+          ],
+ 'demo_xml': [],
+ 'test': [],
+ 'installable': True,
+ 'active': False,
+ }

=== added file 'crm_firstname/crm.py'
--- crm_firstname/crm.py	1970-01-01 00:00:00 +0000
+++ crm_firstname/crm.py	2014-04-01 15:22:09 +0000
@@ -0,0 +1,190 @@
+# -*- coding: utf-8 -*-
+##############################################################################
+#
+#   Copyright (c) 2013 Camptocamp SA (http://www.camptocamp.com)
+#   @author Nicolas Bessi
+#
+#    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 openerp.osv import orm, fields
+from openerp import tools
+from openerp.tools.translate import _
+
+
+class CrmLead(orm.Model):
+
+    _inherit = "crm.lead"
+
+    def _compute_contact_name_custom(self, cursor,
+                                     uid, ids,
+                                     fname, arg, context=None):
+        res = {}
+        for rec in self.read(cursor, uid, ids, ['firstname', 'lastname']):
+            name = ("%s %s") % (rec['lastname'] if rec['lastname'] else u" ",
+                               (rec['firstname'] if rec['firstname'] else u" "))
+            res[rec['id']] = name.strip()
+        return res
+
+    _columns = {
+                'firstname': fields.char("Firstname"),
+                'lastname': fields.char("Lastname"),
+                'contact_name': fields.function(_compute_contact_name_custom,
+                                                string="Contact Name",
+                                                type="char", store=True,
+                                                select=True, readonly=True), 
+                }
+
+    def _lead_create_contact_with_firstname_lastname(self, cr, uid,
+                                                     lead, lastname, firstname,
+                                                     is_company,
+                                                     parent_id=False,
+                                                     context=None):
+        partner = self.pool.get('res.partner')
+        obj_data = self.pool.get('ir.model.data')
+        ## We search category for this contact :
+        obj_data = self.pool.get('ir.model.data')
+        ## 
+        category_record = False
+        category_record_ids = obj_data.search(cr, uid,
+                                              [('name',
+                                                '=',
+                                                'res_partner_category_automatic_from_email'),
+                                               ('model', '=', 'res.partner.category')])
+        if category_record_ids:
+            category_record = obj_data.browse(cr, uid, category_record_ids)
+        vals = {
+                'name': lastname,
+                'firstname': firstname,
+                'user_id': lead.user_id.id,
+                'comment': lead.description,
+                'section_id': lead.section_id.id or False,
+                'parent_id': parent_id,
+                'phone': lead.phone,
+                'mobile': lead.mobile,
+                'email': tools.email_split(lead.email_from) and tools.email_split(lead.email_from)[0] or False,
+                'fax': lead.fax,
+                'title': lead.title and lead.title.id or False,
+                'function': lead.function,
+                'street': lead.street,
+                'street2': lead.street2,
+                'zip': lead.zip,
+                'city': lead.city,
+                'category_id': category_record and [(6, 0, [category_record[0].res_id])] or False,
+                'notification_email_send': 'comment',
+                'country_id': lead.country_id and lead.country_id.id or False,
+                'state_id': lead.state_id and lead.state_id.id or False,
+                'is_company': is_company,
+                'type': 'contact'
+        }
+        partner_id = partner.create(cr, uid, vals, context=context)
+        if partner_id:
+            follower_obj = self.pool.get('mail.followers')
+            val_follow = {'res_model': 'crm.lead',
+                          'res_id': lead.id,
+                          'partner_id': partner_id
+                          }
+            follower_obj.create(cr, uid, val_follow, context=context)
+        return partner_id
+
+    def create(self, cr, uid, vals, context=None):
+        lead_id = super(CrmLead, self).create(cr, uid, vals, context=context)
+        if lead_id:
+            lead = self.browse(cr, uid, lead_id)
+            if not vals['partner_id']:
+                ## No partner created
+                partner_id = self._common_lead_partner(cr, uid, lead, context)
+                if partner_id:
+                    self.write(cr, uid, [lead.id], {'partner_id': partner_id})
+
+        create_context = dict(context, mail_create_nolog=True)
+        return lead_id
+
+    def _common_lead_partner(self, cr, uid, lead, context=None):
+        partner_id = False
+        partner_obj = self.pool.get('res.partner')
+        if lead.partner_name and lead.contact_name:
+            partner_id = self._lead_create_contact_with_firstname_lastname(cr, uid,
+                                                                           lead, lead.partner_name,
+                                                                           False, True, context=context)
+            partner_id = self._lead_create_contact_with_firstname_lastname(cr, uid,
+                                                                           lead, lead.lastname,
+                                                                           lead.firstname, False,
+                                                                           partner_id, context=context)
+        elif lead.partner_name and not lead.contact_name:
+            partner_id = self._lead_create_contact_with_firstname_lastname(cr, uid,
+                                                                           lead, lead.partner_name,
+                                                                           False, True, context=context)
+        elif not lead.partner_name and lead.contact_name:
+            partner_id = self._lead_create_contact_with_firstname_lastname(cr, uid,
+                                                                           lead, lead.lastname,
+                                                                           lead.firstname, False, context=context)
+        elif lead.email_from and partner_obj._parse_partner_name(lead.email_from,
+                                                                 context=context)[0]:
+            contact_dict = partner_obj._parse_partner_firstname_lastname(lead.email_from,
+                                                                         context=context)
+            partner_id = self._lead_create_contact_with_firstname_lastname(cr, uid, lead,
+                                                                           contact_dict['firstname'],
+                                                                           contact_dict['lastname'],
+                                                                           False, context=context)
+        elif lead.email_from:
+            contact_dict = partner_obj._parse_partner_firstname_lastname(lead.email_from,
+                                                                         context=context)
+            partner_id = self._lead_create_contact_with_firstname_lastname(cr, uid, lead,
+                                                                           contact_dict['firstname'],
+                                                                           contact_dict['lastname'],
+                                                                           False, context=context)
+        return partner_id
+
+    def _create_lead_partner(self, cr, uid, lead, context=None):
+        partner_id = False
+        partner_id = self._common_lead_partner(cr, uid, lead, context)
+        if not partner_id:
+            raise orm.except_orm(
+                _('Warning!'),
+                _('No customer name defined. Please fill one of the following fields: Company Name, Contact Name or Email ("Name <email@address>")')
+            )
+        return partner_id
+
+
+class ResPartner(orm.Model):
+
+    _inherit = "res.partner"
+
+    def _parse_partner_firstname_lastname(self, text, context=None):
+        """ Supported syntax:
+            - 'Raoul <raoul@xxxxxxxxxxxx>': will find name and email address
+            - otherwise: default, everything is set as the name """
+        firstname_lastname = {'firstname': '',
+                              'lastname': '',
+                              }
+        emails = tools.email_split(text)
+        if emails:
+            email = emails[0]
+            name = text[:text.index(email)].replace('"', '').replace('<', '').strip()
+            if name:
+                split_name = name.split(' ', 1)
+                if len(split_name) == 2:
+                    firstname_lastname['firstname'] = split_name[0]
+                    firstname_lastname['lastname'] = split_name[1]
+                else:
+                    firstname_lastname['firstname'] = split_name[0]
+                    firstname_lastname['lastname'] = ''
+            else:
+                firstname_lastname['firstname'] = email
+                firstname_lastname['lastname'] = ''
+        else:
+                firstname_lastname['firstname'] = text
+                firstname_lastname['lastname'] = ''
+        return firstname_lastname

=== added file 'crm_firstname/crm_view.xml'
--- crm_firstname/crm_view.xml	1970-01-01 00:00:00 +0000
+++ crm_firstname/crm_view.xml	2014-04-01 15:22:09 +0000
@@ -0,0 +1,20 @@
+<openerp>
+  <data>
+    <record id="crm_case_form_view_leads_firstname_lastname" model="ir.ui.view">
+      <field name="name">CRM - Leads Form Lastname Firstname</field>
+      <field name="model">crm.lead</field>
+      <field name="inherit_id" ref="crm.crm_case_form_view_leads"/>
+      <field name="arch" type="xml">
+        <xpath expr="//field[@name='title']" position="after">
+        	<div>
+			<label for="firstname" string="Firstname"/>
+                <field name="firstname"/>
+			<label for="lastname" string="Lastname"/>
+                <field name="lastname"/>
+            </div>
+        </xpath>  
+      </field>
+    </record>
+  
+  </data>
+</openerp>

=== added file 'crm_firstname/data.xml'
--- crm_firstname/data.xml	1970-01-01 00:00:00 +0000
+++ crm_firstname/data.xml	2014-04-01 15:22:09 +0000
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="utf-8"?>
+<openerp>
+    <data noupdate="1">
+        <!--
+        Resource: res.partner.category
+        -->
+        <record id="res_partner_category_automatic_from_email" model="res.partner.category">
+            <field name="name">Automatic Contact</field>
+        </record>
+    </data>
+</openerp>
+

=== added directory 'crm_firstname/i18n'
=== added file 'crm_firstname/i18n/crm_firstname.pot'
--- crm_firstname/i18n/crm_firstname.pot	1970-01-01 00:00:00 +0000
+++ crm_firstname/i18n/crm_firstname.pot	2014-04-01 15:22:09 +0000
@@ -0,0 +1,39 @@
+# Translation of OpenERP Server.
+# This file contains the translation of the following modules:
+#	* crm_firstname
+#
+msgid ""
+msgstr ""
+"Project-Id-Version: OpenERP Server 7.0\n"
+"Report-Msgid-Bugs-To: \n"
+"POT-Creation-Date: 2014-04-01 15:13+0000\n"
+"PO-Revision-Date: 2014-04-01 15:13+0000\n"
+"Last-Translator: <>\n"
+"Language-Team: \n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: \n"
+"Plural-Forms: \n"
+
+#. module: crm_firstname
+#: model:res.partner.category,name:crm_firstname.res_partner_category_automatic_from_email
+msgid "Automatic Contact"
+msgstr ""
+
+#. module: crm_firstname
+#: view:crm.lead:0
+msgid "Firstname"
+msgstr ""
+
+#. module: crm_firstname
+#: view:crm.lead:0
+msgid "Lastname"
+msgstr ""
+
+#. module: crm_firstname
+#: code:_description:0
+#, python-format
+msgid "Lead/Opportunity"
+msgstr ""
+
+

=== added file 'crm_firstname/i18n/fr.po'
--- crm_firstname/i18n/fr.po	1970-01-01 00:00:00 +0000
+++ crm_firstname/i18n/fr.po	2014-04-01 15:22:09 +0000
@@ -0,0 +1,39 @@
+# Translation of OpenERP Server.
+# This file contains the translation of the following modules:
+#	* crm_firstname
+#
+msgid ""
+msgstr ""
+"Project-Id-Version: OpenERP Server 7.0\n"
+"Report-Msgid-Bugs-To: \n"
+"POT-Creation-Date: 2014-04-01 15:13+0000\n"
+"PO-Revision-Date: 2014-04-01 15:13+0000\n"
+"Last-Translator: <>\n"
+"Language-Team: \n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: \n"
+"Plural-Forms: \n"
+
+#. module: crm_firstname
+#: model:res.partner.category,name:crm_firstname.res_partner_category_automatic_from_email
+msgid "Automatic Contact"
+msgstr "Contact automatique"
+
+#. module: crm_firstname
+#: view:crm.lead:0
+msgid "Firstname"
+msgstr "Prénom"
+
+#. module: crm_firstname
+#: view:crm.lead:0
+msgid "Lastname"
+msgstr "Nom"
+
+#. module: crm_firstname
+#: code:_description:0
+#, python-format
+msgid "Lead/Opportunity"
+msgstr "Piste/Opportunité"
+
+


Follow ups