Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Odoo CE
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
External wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Coopdevs
Comunitats Energètiques
Odoo CE
Merge requests
!156
Setup source_xml id on lead creation
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Setup source_xml id on lead creation
feature/crm_source_xml_id
into
dev
Overview
2
Commits
2
Pipelines
2
Changes
1
Merged
Dani Quilez
requested to merge
feature/crm_source_xml_id
into
dev
1 year ago
Overview
2
Commits
2
Pipelines
2
Changes
1
Expand
on crm lead API creation we define the utm source of the lead. This will allow us to maintain a lot of code from last year version in terms of UX. Basically fiter leads by the utm source for an easier managemnt.
0
0
Merge request reports
Compare
dev
version 1
65303aa5
1 year ago
dev (base)
and
latest version
latest version
fcb9838b
2 commits,
1 year ago
version 1
65303aa5
1 commit,
1 year ago
1 file
+
41
−
15
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
energy_communities/services/crm_lead_service.py
+
41
−
15
Options
@@ -17,32 +17,58 @@ class CRMLeadService(Component):
create_dict
=
super
().
create
(
params
)
crm_lead
=
json
.
loads
(
create_dict
.
response
[
0
].
decode
(
"
utf-8
"
))
# get utm source from payload
target_source_xml_id
=
self
.
_get_source_xml_id
(
params
)
if
target_source_xml_id
:
# setup utm source on crm lead
crm_lead_id
=
crm_lead
.
get
(
'
id
'
,
False
)
self
.
_setup_lead_utm_source
(
crm_lead_id
,
target_source_xml_id
)
# select autoresponder notification id based on utm source
template_external_id
=
self
.
_get_autoresponder_email_template
(
target_source_xml_id
)
# send auto responder email and notify admins
email_values
=
{
"
email_to
"
:
params
[
"
email_from
"
]}
if
template_external_id
:
template
=
self
.
env
.
ref
(
"
energy_communities.{}
"
.
format
(
template_external_id
)
)
template
.
sudo
().
send_mail
(
crm_lead
[
"
id
"
],
email_values
=
email_values
)
# Add template to chatter message
self
.
env
[
"
crm.lead
"
].
post_template_to_chatter
(
template
.
id
)
return
crm_lead
def
_setup_lead_utm_source
(
self
,
lead_id
,
source_xml_id
):
lead
=
self
.
env
[
'
crm.lead
'
].
browse
(
lead_id
)
if
lead
:
utm_source
=
self
.
env
.
ref
(
'
energy_communities.
'
+
source_xml_id
)
lead
.
write
({
'
source_id
'
:
utm_source
.
id
})
def
_get_source_xml_id
(
self
,
params
):
metadata
=
params
[
"
metadata
"
]
target_source_xml_id
=
None
for
data
in
metadata
:
if
data
[
"
key
"
]
==
"
source_xml_id
"
:
target_source_xml_id
=
data
[
"
value
"
]
return
target_source_xml_id
def
_get_autoresponder_email_template
(
self
,
source_xml_id
):
template_external_id
=
None
if
target_
source_xml_id
==
"
ce_source_creation_ce_proposal
"
:
if
source_xml_id
==
"
ce_source_creation_ce_proposal
"
:
template_external_id
=
"
email_templ_lead_ce_creation_receipt_confirm_id
"
elif
target_
source_xml_id
==
"
ce_source_existing_ce_contact
"
:
elif
source_xml_id
==
"
ce_source_existing_ce_contact
"
:
template_external_id
=
"
email_templ_lead_request_contact_confirm_id
"
elif
target_
source_xml_id
==
"
ce_source_existing_ce_info
"
:
elif
source_xml_id
==
"
ce_source_existing_ce_info
"
:
template_external_id
=
"
email_templ_lead_request_ce_news_confirm_id
"
elif
target_
source_xml_id
==
"
ce_source_future_location_ce_info
"
:
elif
source_xml_id
==
"
ce_source_future_location_ce_info
"
:
template_external_id
=
(
"
email_templ_lead_request_advise_future_ce_confirm_id
"
)
elif
target_
source_xml_id
==
"
ce_source_general_info
"
:
elif
source_xml_id
==
"
ce_source_general_info
"
:
template_external_id
=
"
email_templ_lead_request_platform_news_confirm_id
"
email_values
=
{
"
email_to
"
:
params
[
"
email_from
"
]}
if
template_external_id
:
template
=
self
.
env
.
ref
(
"
energy_communities.{}
"
.
format
(
template_external_id
)
)
template
.
sudo
().
send_mail
(
crm_lead
[
"
id
"
],
email_values
=
email_values
)
# Add template to chatter message
self
.
env
[
"
crm.lead
"
].
post_template_to_chatter
(
template
.
id
)
return
template_external_id
Loading