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

[14.0] New module crm_lead_to_opportunity_contact #469

Closed
Closed
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
1 change: 1 addition & 0 deletions crm_lead_to_opportunity_contact/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Will be auto-generated from the readme subdir
2 changes: 2 additions & 0 deletions crm_lead_to_opportunity_contact/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import models
from . import wizards
20 changes: 20 additions & 0 deletions crm_lead_to_opportunity_contact/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Copyright 2023 Akretion France (http://www.akretion.com/)
# @author: Alexis de Lattre <[email protected]>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

{
"name": "CRM Lead to opportunity - Contact",
"version": "14.0.1.0.0",
"category": "CRM",
"license": "AGPL-3",
"summary": "Lead to opportunity: option to create a contact on an existing "
"customer",
"author": "Akretion,Odoo Community Association (OCA)",
"maintainers": ["alexis-via"],
"website": "https://github.com/OCA/crm",
"depends": ["crm"],
"data": [
"wizards/crm_lead_to_opportunity_view.xml",
],
"installable": True,
}
1 change: 1 addition & 0 deletions crm_lead_to_opportunity_contact/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import crm_lead
31 changes: 31 additions & 0 deletions crm_lead_to_opportunity_contact/models/crm_lead.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Copyright 2023 Akretion France (http://www.akretion.com/)
# @author: Alexis de Lattre <[email protected]>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import _, models
from odoo.exceptions import UserError


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

def _create_child_partner(self, parent_partner_id):
self.ensure_one()
assert parent_partner_id
rpo = self.env["res.partner"]
contact_name = self.contact_name
if not contact_name and self.email_from:
contact_name = rpo._parse_partner_name(self.email_from)[0]
if not contact_name:
raise UserError(
_("Contact name is not set on lead '%s'.") % self.display_name
)
vals = self.with_context(
default_user_id=self.user_id.id
)._prepare_customer_values(
contact_name,
is_company=False,
parent_id=parent_partner_id,
)
partner = rpo.create(vals)
return partner
1 change: 1 addition & 0 deletions crm_lead_to_opportunity_contact/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Alexis de Lattre <[email protected]>
10 changes: 10 additions & 0 deletions crm_lead_to_opportunity_contact/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
In the wizard to convert a lead to an opportunity, you have 3 options:

* Create a new customer
* Link to an existing customer
* Do not link to a customer

This modules adds a fourth option: **Create a new contact on an existing customer**.

.. figure:: ../static/description/crm_lead_to_opportunity_contact-sshot.png
:alt: Screenshot lead to opportunity wizard
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions crm_lead_to_opportunity_contact/wizards/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import crm_lead_to_opportunity
30 changes: 30 additions & 0 deletions crm_lead_to_opportunity_contact/wizards/crm_lead_to_opportunity.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Copyright 2023 Akretion France (http://www.akretion.com/)
# @author: Alexis de Lattre <[email protected]>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import _, fields, models
from odoo.exceptions import UserError


class CrmLead2OpportunityPartner(models.TransientModel):
_inherit = "crm.lead2opportunity.partner"

action = fields.Selection(
selection_add=[
("create_child", "Create a new contact on an existing customer")
],
ondelete={"create_child": "set null"},
)
# I don't re-use the native field 'partner_id' because I need a specific domain
create_child_partner_id = fields.Many2one(
"res.partner", string="Existing Customer", domain=[("parent_id", "=", False)]
)

def _convert_handle_partner(self, lead, action, partner_id):
if action == "create_child":
if not self.create_child_partner_id:
raise UserError(_("You must select an Existing Customer."))
partner = lead._create_child_partner(self.create_child_partner_id.id)
lead.write({"partner_id": partner.id})
else:
super()._convert_handle_partner(lead, action, partner_id)
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8" ?>
<!--
Copyright 2023 Akretion France (http://www.akretion.com/)
@author: Alexis de Lattre <[email protected]>
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
-->
<odoo>

<record id="view_crm_lead2opportunity_partner" model="ir.ui.view">
<field name="model">crm.lead2opportunity.partner</field>
<field name="inherit_id" ref="crm.view_crm_lead2opportunity_partner" />
<field name="arch" type="xml">
<field name="partner_id" position="after">
<field
name="create_child_partner_id"
widget="res_partner_many2one"
context="{'res_partner_search_mode': 'customer', 'show_vat': True}"
attrs="{'required': [('action', '=', 'create_child')], 'invisible': [('action', '!=', 'create_child')]}"
/>
</field>
</field>
</record>

</odoo>
6 changes: 6 additions & 0 deletions setup/crm_lead_to_opportunity_contact/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
Loading