-
-
Notifications
You must be signed in to change notification settings - Fork 407
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ADD] module crm_lead_to_opportunity_contact
With this module, in the lead to opportunity wizard, you have a new option: create a new contact on an existing customer
- Loading branch information
1 parent
cf2a150
commit e04f0c8
Showing
13 changed files
with
128 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Will be auto-generated from the readme subdir |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
from . import models | ||
from . import wizards |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import crm_lead |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
* Alexis de Lattre <[email protected]> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Binary file added
BIN
+54.8 KB
...pportunity_contact/static/description/crm_lead_to_opportunity_contact-sshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
30
crm_lead_to_opportunity_contact/wizards/crm_lead_to_opportunity.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
24 changes: 24 additions & 0 deletions
24
crm_lead_to_opportunity_contact/wizards/crm_lead_to_opportunity_view.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
1 change: 1 addition & 0 deletions
1
setup/crm_lead_to_opportunity_contact/odoo/addons/crm_lead_to_opportunity_contact
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../../../crm_lead_to_opportunity_contact |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
) |