Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[8.0][crm_lead_firstname] Link crm and partner_firstname modules. #75

Merged
merged 7 commits into from
Feb 29, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 78 additions & 0 deletions crm_lead_firstname/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3

===============================
Firstname and Lastname in Leads
===============================

This module extends the functionality of CRM leads to support split first and
last name fields for contacts and allow you to port that information to and
from partners.


Installation
============

Since leads are expected to create partners only when needed and after
information is correctly set up, in leads there is no inverse logic to
transform the old single name in the new split names automatically. The old
single name will simply be the firstname now.

To install this module, you need to:

* Install `OCA/partner-contact <https://github.com/OCA/partner-contact>`_ repo.

Usage
=====

To use this module, you need to:

* Go to *Sales > Sales > Leads > Create*.
* You have the new split fields *Firstname* and *Lastname*. Fill them.
* Press *Convert to Opportunity*.
* In *Related Customer* choose *Create a new customer*.
* Press *Create Opportunity*.
* In the new opportunity, go to *Lead* tab. There are the new fields too.
* If you go to the partner you just created, you will see that its first and
last names match those in the lead.

.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
:alt: Try me on Runbot
:target: https://runbot.odoo-community.org/runbot/134/8.0

Bug Tracker
===========

Bugs are tracked on `GitHub Issues
<https://github.com/OCA/crm/issues>`_. In case of trouble, please
check there if your issue has already been reported. If you spotted it first,
help us smashing it by providing a detailed and welcomed `feedback
<https://github.com/OCA/
crm/issues/new?body=module:%20
crm_lead_firstname%0Aversion:%20
8.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Credits
=======

Contributors
------------

* Rafael Blasco <rafabn@antiun.com>
* Jairo Llopis <yajo.sk8@gmail.com>

Maintainer
----------

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

This module is maintained by the OCA.

OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

To contribute to this module, please visit https://odoo-community.org.
5 changes: 5 additions & 0 deletions crm_lead_firstname/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# -*- coding: utf-8 -*-
# © 2016 Antiun Ingeniería S.L. - Jairo Llopis
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from . import models
21 changes: 21 additions & 0 deletions crm_lead_firstname/__openerp__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# -*- coding: utf-8 -*-
# © 2016 Antiun Ingeniería S.L. - Jairo Llopis
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
{
"name": "Firstname and Lastname in Leads",
"summary": "Specify split names for contacts in leads",
"version": "8.0.1.0.0",
"category": "Customer Relationship Management",
"website": "http://www.antiun.com",
"author": "Antiun Ingeniería S.L., Odoo Community Association (OCA)",
"license": "AGPL-3",
"application": False,
"installable": True,
"depends": [
"crm",
"partner_firstname",
],
"data": [
"views/crm_lead_view.xml",
],
}
46 changes: 46 additions & 0 deletions crm_lead_firstname/i18n/es.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * crm_lead_firstname
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 8.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2016-02-15 17:25+0000\n"
"PO-Revision-Date: 2016-02-15 18:27+0100\n"
"Last-Translator: <>\n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: \n"
"Language: es\n"
"X-Generator: Poedit 1.8.6\n"

#. module: crm_lead_firstname
#: view:crm.lead:crm_lead_firstname.crm_case_form_view_leads
#: view:crm.lead:crm_lead_firstname.crm_case_form_view_oppor
msgid "Contact Name"
msgstr "Nombre del contacto"

#. module: crm_lead_firstname
#: view:crm.lead:crm_lead_firstname.crm_case_form_view_leads
#: view:crm.lead:crm_lead_firstname.crm_case_form_view_oppor
msgid "Firstname"
msgstr "Nombre de pila"

#. module: crm_lead_firstname
#: field:crm.lead,contact_lastname:0
msgid "Last name"
msgstr "Apellido"

#. module: crm_lead_firstname
#: view:crm.lead:crm_lead_firstname.crm_case_form_view_leads
#: view:crm.lead:crm_lead_firstname.crm_case_form_view_oppor
msgid "Lastname"
msgstr "Apellido"

#. module: crm_lead_firstname
#: model:ir.model,name:crm_lead_firstname.model_crm_lead
msgid "Lead/Opportunity"
msgstr "Iniciativa/Oportunidad"
5 changes: 5 additions & 0 deletions crm_lead_firstname/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# -*- coding: utf-8 -*-
# © 2016 Antiun Ingeniería S.L. - Jairo Llopis
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from . import crm_lead
46 changes: 46 additions & 0 deletions crm_lead_firstname/models/crm_lead.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# -*- coding: utf-8 -*-
# © 2016 Antiun Ingeniería S.L. - Jairo Llopis
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from collections import OrderedDict
from openerp import api, fields, models


class CrmLead(models.Model):
_inherit = "crm.lead"

contact_name = fields.Char("First name")
contact_lastname = fields.Char("Last name")

@api.model
def _lead_create_contact(self, lead, name, is_company, parent_id=False):
"""Ensure first and last names of contact match those in lead."""
partner_id = super(CrmLead, self)._lead_create_contact(
lead, name, is_company, parent_id)
if not is_company and partner_id:
partner = self.env["res.partner"].browse(partner_id)

# Write fields with values first
partner.update(
OrderedDict(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you use this strange construction?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See 2ae3a2c

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should write the same commit text as comment for clarifying it to the next code reader

sorted(
(("firstname", lead.contact_name),
("lastname", lead.contact_lastname)),
key=lambda item: item[1],
reverse=True)))
return partner_id

@api.multi
def on_change_partner_id(self, partner_id):
"""Recover first and last names from partner if available."""
result = super(CrmLead, self).on_change_partner_id(partner_id)

if result.get("value") and partner_id:
partner = self.env["res.partner"].browse(partner_id)
if not partner.is_company:
result["value"].update({
"contact_name": partner.firstname,
"contact_lastname": partner.lastname,
})

return result
Binary file added crm_lead_firstname/static/description/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions crm_lead_firstname/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# -*- coding: utf-8 -*-
# © 2016 Antiun Ingeniería S.L. - Jairo Llopis
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from . import test_crm_lead
45 changes: 45 additions & 0 deletions crm_lead_firstname/tests/test_crm_lead.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# -*- coding: utf-8 -*-
# © 2016 Antiun Ingeniería S.L. - Jairo Llopis
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from openerp.tests.common import TransactionCase


class FirstnameCase(TransactionCase):
def setUp(self):
super(FirstnameCase, self).setUp()
self.lead = self.env["crm.lead"].create({
"name": u"Léad",
"partner_name": u"Pärtner",
"contact_name": u"Firçt name",
"contact_lastname": u"Laçt name",
})
self.partner = self.env["res.partner"].create({
"firstname": u"Firçt name",
"lastname": u"Laçt name",
})

def test_create_contact(self):
"""Contact correctly created."""
partner_id = self.lead.handle_partner_assignation()[self.lead.id]
partner = self.env["res.partner"].browse(partner_id)
self.assertEqual(self.lead.contact_name, partner.firstname)
self.assertEqual(self.lead.contact_lastname, partner.lastname)

def test_create_contact_empty(self):
"""No problems creating a contact without names."""
self.lead.write({
"contact_name": False,
"contact_lastname": False,
})
self.lead.handle_partner_assignation()

def test_onchange_partner(self):
"""When changing partner, fields get correctly updated."""
with self.env.do_in_onchange():
self.lead.partner_id = self.partner
value = self.lead.on_change_partner_id(self.partner.id)["value"]
self.assertEqual(
self.partner.firstname, value["contact_name"])
self.assertEqual(
self.partner.lastname, value["contact_lastname"])
43 changes: 43 additions & 0 deletions crm_lead_firstname/views/crm_lead_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- © 2016 Antiun Ingeniería S.L. - Jairo Llopis
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -->

<openerp>
<data>

<record id="crm_case_form_view_leads" model="ir.ui.view">
<field name="name">Add firstname and lastname</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="//label[@for='contact_name']" position="attributes">
<attribute name="string">Contact Name</attribute>
</xpath>
<xpath expr="//field[@name='contact_name']" position="attributes">
<attribute name="placeholder">Firstname</attribute>
</xpath>
<xpath expr="//field[@name='contact_name']" position="after">
<field name="contact_lastname" placeholder="Lastname"/>
</xpath>
</field>
</record>

<record id="crm_case_form_view_oppor" model="ir.ui.view">
<field name="name">Add firstname and lastname</field>
<field name="model">crm.lead</field>
<field name="inherit_id" ref="crm.crm_case_form_view_oppor"/>
<field name="arch" type="xml">
<xpath expr="//label[@for='contact_name']" position="attributes">
<attribute name="string">Contact Name</attribute>
</xpath>
<xpath expr="//field[@name='contact_name']" position="attributes">
<attribute name="placeholder">Firstname</attribute>
</xpath>
<xpath expr="//field[@name='contact_name']" position="after">
<field name="contact_lastname" placeholder="Lastname"/>
</xpath>
</field>
</record>

</data>
</openerp>