Skip to content

Commit

Permalink
Merge badcb94 into c5aa7d5
Browse files Browse the repository at this point in the history
  • Loading branch information
yajo committed Mar 1, 2016
2 parents c5aa7d5 + badcb94 commit e33e79d
Show file tree
Hide file tree
Showing 10 changed files with 287 additions and 0 deletions.
73 changes: 73 additions & 0 deletions crm_lead_second_lastname/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
.. 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

========================
Second Lastname in Leads
========================

This module extends the functionality of CRM leads to support setting the
second last name field for contacts and allow you to port that information to
and from partners.

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

To install this module, you need to:

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

Usage
=====

To use this module, you need to:

* Go to *Sales > Sales > Leads > Create*.
* You have the new *Second Lastname*. Fill it.
* Press *Convert to Opportunity*.
* In *Related Customer* choose *Create a new customer*.
* Press *Create Opportunity*.
* In the new opportunity, go to *Lead* tab. There is the new field too.
* If you go to the partner you just created, you will see that its second
last name match that 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_second_lastname%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_second_lastname/__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_second_lastname/__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": "Second Lastname in Leads",
"summary": "Specify second lastname directly in the lead/opportunity",
"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_lead_firstname",
"partner_second_lastname",
],
"data": [
"views/crm_lead_view.xml",
],
}
34 changes: 34 additions & 0 deletions crm_lead_second_lastname/i18n/es.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * crm_lead_second_lastname
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 8.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2016-02-26 16:12+0000\n"
"PO-Revision-Date: 2016-02-26 17:13+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_second_lastname
#: model:ir.model,name:crm_lead_second_lastname.model_crm_lead
msgid "Lead/Opportunity"
msgstr "Iniciativa/Oportunidad"

#. module: crm_lead_second_lastname
#: field:crm.lead,contact_lastname2:0
msgid "Second last name"
msgstr "Segundo apellido"

#. module: crm_lead_second_lastname
#: view:crm.lead:crm_lead_second_lastname.crm_case_form_view_leads
#: view:crm.lead:crm_lead_second_lastname.crm_case_form_view_oppor
msgid "Second lastname"
msgstr "Segundo apellido"
5 changes: 5 additions & 0 deletions crm_lead_second_lastname/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
48 changes: 48 additions & 0 deletions crm_lead_second_lastname/models/crm_lead.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# -*- 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.addons.crm_lead_firstname.models.crm_lead \
import CrmLead as FirstnameCrmLead
from openerp import api, fields, models


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

contact_lastname2 = fields.Char("Second 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."""
# Skip method from :mod:`crm_lead_firstname`
partner_id = super(FirstnameCrmLead, 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(
sorted(
(("firstname", lead.contact_name),
("lastname", lead.contact_lastname),
("lastname2", lead.contact_lastname2)),
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_lastname2": partner.lastname2,
})

return result
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_second_lastname/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
59 changes: 59 additions & 0 deletions crm_lead_second_lastname/tests/test_crm_lead.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# -*- 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",
"contact_lastname2": u"Çecond last name",
})
self.partner = self.env["res.partner"].create({
"firstname": u"Firçt name",
"lastname": u"Laçt name",
"lastname2": u"Çecond last 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)
self.assertEqual(self.lead.contact_lastname2, partner.lastname2)

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

def test_create_contact_empty_first_last_name(self):
"""No problems creating a contact without first and last 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"])
self.assertEqual(
self.partner.lastname2, value["contact_lastname2"])
37 changes: 37 additions & 0 deletions crm_lead_second_lastname/views/crm_lead_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?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 second lastname</field>
<field name="model">crm.lead</field>
<field name="inherit_id"
ref="crm_lead_firstname.crm_case_form_view_leads"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='contact_lastname']" position="after">
<field
name="contact_lastname2"
placeholder="Second lastname"/>
</xpath>
</field>
</record>

<record id="crm_case_form_view_oppor" model="ir.ui.view">
<field name="name">Add second lastname</field>
<field name="model">crm.lead</field>
<field name="inherit_id"
ref="crm_lead_firstname.crm_case_form_view_oppor"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='contact_lastname']" position="after">
<field
name="contact_lastname2"
placeholder="Second lastname"/>
</xpath>
</field>
</record>

</data>
</openerp>

0 comments on commit e33e79d

Please sign in to comment.