Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
Coopdevs OCB mirror
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
Odoo
Coopdevs OCB mirror
Commits
9ca58db6
Commit
9ca58db6
authored
10 years ago
by
Jeremy Kersten
Browse files
Options
Downloads
Patches
Plain Diff
[IMP] crm: make code of merge opportunities overloadable
parent
e133e5fc
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
addons/crm/crm_lead.py
+36
-6
36 additions, 6 deletions
addons/crm/crm_lead.py
addons/crm/wizard/crm_lead_to_opportunity.py
+1
-17
1 addition, 17 deletions
addons/crm/wizard/crm_lead_to_opportunity.py
with
37 additions
and
23 deletions
addons/crm/crm_lead.py
+
36
−
6
View file @
9ca58db6
...
@@ -29,7 +29,8 @@ from openerp import tools
...
@@ -29,7 +29,8 @@ from openerp import tools
from
openerp.addons.base.res.res_partner
import
format_address
from
openerp.addons.base.res.res_partner
import
format_address
from
openerp.osv
import
fields
,
osv
,
orm
from
openerp.osv
import
fields
,
osv
,
orm
from
openerp.tools.translate
import
_
from
openerp.tools.translate
import
_
from
openerp.tools
import
email_re
from
openerp.tools
import
email_re
,
email_split
CRM_LEAD_FIELDS_TO_MERGE
=
[
'
name
'
,
CRM_LEAD_FIELDS_TO_MERGE
=
[
'
name
'
,
'
partner_id
'
,
'
partner_id
'
,
...
@@ -585,6 +586,37 @@ class crm_lead(format_address, osv.osv):
...
@@ -585,6 +586,37 @@ class crm_lead(format_address, osv.osv):
attachment
.
write
(
values
)
attachment
.
write
(
values
)
return
True
return
True
def
get_duplicated_leads
(
self
,
cr
,
uid
,
ids
,
partner_id
,
include_lost
=
False
,
context
=
None
):
"""
Search for opportunities that have the same partner and that arent done or cancelled
"""
lead
=
self
.
browse
(
cr
,
uid
,
ids
[
0
],
context
=
context
)
email
=
lead
.
partner_id
and
lead
.
partner_id
.
email
or
lead
.
email_from
return
self
.
pool
[
'
crm.lead
'
].
_get_duplicated_leads_by_emails
(
cr
,
uid
,
partner_id
,
email
,
include_lost
=
include_lost
,
context
=
context
)
def
_get_duplicated_leads_by_emails
(
self
,
cr
,
uid
,
partner_id
,
email
,
include_lost
=
False
,
context
=
None
):
"""
Search for opportunities that have the same partner and that arent done or cancelled
"""
final_stage_domain
=
[(
'
stage_id.probability
'
,
'
<
'
,
100
),
'
|
'
,
(
'
stage_id.probability
'
,
'
>
'
,
0
),
(
'
stage_id.sequence
'
,
'
<=
'
,
1
)]
partner_match_domain
=
[]
for
email
in
set
(
email_split
(
email
)
+
[
email
]):
partner_match_domain
.
append
((
'
email_from
'
,
'
=ilike
'
,
email
))
if
partner_id
:
partner_match_domain
.
append
((
'
partner_id
'
,
'
=
'
,
partner_id
))
partner_match_domain
=
[
'
|
'
]
*
(
len
(
partner_match_domain
)
-
1
)
+
partner_match_domain
if
not
partner_match_domain
:
return
[]
domain
=
partner_match_domain
if
not
include_lost
:
domain
+=
final_stage_domain
return
self
.
search
(
cr
,
uid
,
domain
,
context
=
context
)
def
merge_dependences
(
self
,
cr
,
uid
,
highest
,
opportunities
,
context
=
None
):
self
.
_merge_notify
(
cr
,
uid
,
highest
,
opportunities
,
context
=
context
)
self
.
_merge_opportunity_history
(
cr
,
uid
,
highest
,
opportunities
,
context
=
context
)
self
.
_merge_opportunity_attachments
(
cr
,
uid
,
highest
,
opportunities
,
context
=
context
)
def
merge_opportunity
(
self
,
cr
,
uid
,
ids
,
user_id
=
False
,
section_id
=
False
,
context
=
None
):
def
merge_opportunity
(
self
,
cr
,
uid
,
ids
,
user_id
=
False
,
section_id
=
False
,
context
=
None
):
"""
"""
Different cases of merge:
Different cases of merge:
...
@@ -627,14 +659,12 @@ class crm_lead(format_address, osv.osv):
...
@@ -627,14 +659,12 @@ class crm_lead(format_address, osv.osv):
if
section_id
:
if
section_id
:
merged_data
[
'
section_id
'
]
=
section_id
merged_data
[
'
section_id
'
]
=
section_id
# Merge messages and attachements into the first opportunity
self
.
_merge_opportunity_history
(
cr
,
uid
,
highest
.
id
,
tail_opportunities
,
context
=
context
)
self
.
_merge_opportunity_attachments
(
cr
,
uid
,
highest
.
id
,
tail_opportunities
,
context
=
context
)
# Merge notifications about loss of information
# Merge notifications about loss of information
opportunities
=
[
highest
]
opportunities
=
[
highest
]
opportunities
.
extend
(
opportunities_rest
)
opportunities
.
extend
(
opportunities_rest
)
self
.
_merge_notify
(
cr
,
uid
,
highest
.
id
,
opportunities
,
context
=
context
)
self
.
merge_dependences
(
cr
,
uid
,
highest
.
id
,
tail_opportunities
,
context
=
context
)
# Check if the stage is in the stages of the sales team. If not, assign the stage with the lowest sequence
# Check if the stage is in the stages of the sales team. If not, assign the stage with the lowest sequence
if
merged_data
.
get
(
'
section_id
'
):
if
merged_data
.
get
(
'
section_id
'
):
section_stage_ids
=
self
.
pool
.
get
(
'
crm.case.stage
'
).
search
(
cr
,
uid
,
[(
'
section_ids
'
,
'
in
'
,
merged_data
[
'
section_id
'
]),
(
'
type
'
,
'
=
'
,
merged_data
.
get
(
'
type
'
))],
order
=
'
sequence
'
,
context
=
context
)
section_stage_ids
=
self
.
pool
.
get
(
'
crm.case.stage
'
).
search
(
cr
,
uid
,
[(
'
section_ids
'
,
'
in
'
,
merged_data
[
'
section_id
'
]),
(
'
type
'
,
'
=
'
,
merged_data
.
get
(
'
type
'
))],
order
=
'
sequence
'
,
context
=
context
)
...
...
This diff is collapsed.
Click to expand it.
addons/crm/wizard/crm_lead_to_opportunity.py
+
1
−
17
View file @
9ca58db6
...
@@ -21,7 +21,6 @@
...
@@ -21,7 +21,6 @@
from
openerp.osv
import
fields
,
osv
from
openerp.osv
import
fields
,
osv
from
openerp.tools.translate
import
_
from
openerp.tools.translate
import
_
from
openerp.tools
import
email_split
import
re
import
re
class
crm_lead2opportunity_partner
(
osv
.
osv_memory
):
class
crm_lead2opportunity_partner
(
osv
.
osv_memory
):
...
@@ -46,21 +45,7 @@ class crm_lead2opportunity_partner(osv.osv_memory):
...
@@ -46,21 +45,7 @@ class crm_lead2opportunity_partner(osv.osv_memory):
"""
"""
Search for opportunities that have the same partner and that arent done or cancelled
Search for opportunities that have the same partner and that arent done or cancelled
"""
"""
lead_obj
=
self
.
pool
.
get
(
'
crm.lead
'
)
return
self
.
pool
.
get
(
'
crm.lead
'
).
_get_duplicated_leads_by_emails
(
cr
,
uid
,
partner_id
,
email
,
include_lost
=
include_lost
,
context
=
context
)
emails
=
set
(
email_split
(
email
)
+
[
email
])
final_stage_domain
=
[(
'
stage_id.probability
'
,
'
<
'
,
100
),
'
|
'
,
(
'
stage_id.probability
'
,
'
>
'
,
0
),
(
'
stage_id.sequence
'
,
'
<=
'
,
1
)]
partner_match_domain
=
[]
for
email
in
emails
:
partner_match_domain
.
append
((
'
email_from
'
,
'
=ilike
'
,
email
))
if
partner_id
:
partner_match_domain
.
append
((
'
partner_id
'
,
'
=
'
,
partner_id
))
partner_match_domain
=
[
'
|
'
]
*
(
len
(
partner_match_domain
)
-
1
)
+
partner_match_domain
if
not
partner_match_domain
:
return
[]
domain
=
partner_match_domain
if
not
include_lost
:
domain
+=
final_stage_domain
return
lead_obj
.
search
(
cr
,
uid
,
domain
)
def
default_get
(
self
,
cr
,
uid
,
fields
,
context
=
None
):
def
default_get
(
self
,
cr
,
uid
,
fields
,
context
=
None
):
"""
"""
...
@@ -243,7 +228,6 @@ class crm_lead2opportunity_mass_convert(osv.osv_memory):
...
@@ -243,7 +228,6 @@ class crm_lead2opportunity_mass_convert(osv.osv_memory):
leads_with_duplicates
.
append
(
lead
.
id
)
leads_with_duplicates
.
append
(
lead
.
id
)
return
{
'
value
'
:
{
'
opportunity_ids
'
:
leads_with_duplicates
}}
return
{
'
value
'
:
{
'
opportunity_ids
'
:
leads_with_duplicates
}}
def
_convert_opportunity
(
self
,
cr
,
uid
,
ids
,
vals
,
context
=
None
):
def
_convert_opportunity
(
self
,
cr
,
uid
,
ids
,
vals
,
context
=
None
):
"""
"""
When
"
massively
"
(more than one at a time) converting leads to
When
"
massively
"
(more than one at a time) converting leads to
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment