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
!190
Update followers on crm-lead
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Update followers on crm-lead
feature/crm-followers
into
dev
Overview
3
Commits
3
Pipelines
2
Changes
1
All threads resolved!
Hide all comments
Merged
konykon
requested to merge
feature/crm-followers
into
dev
1 year ago
Overview
3
Commits
3
Pipelines
2
Changes
1
All threads resolved!
Hide all comments
Expand
0
0
Merge request reports
Viewing commit
fdde7ddb
Prev
Next
Show latest version
1 file
+
40
−
9
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
fdde7ddb
Add funcionality of adding and removing followers from crm-lead
· fdde7ddb
konykon
authored
1 year ago
energy_communities/wizards/assign_crm_to_coordinator_company.py
+
40
−
9
Options
@@ -2,25 +2,56 @@ from odoo import models, fields, api
class
AssignCRMToCoordinatorCompanyWizard
(
models
.
TransientModel
):
_name
=
'
assign.crm.to.coordinator.company.wizard
'
_description
=
'
Assign CRM to coordinator company wizard
'
_name
=
"
assign.crm.to.coordinator.company.wizard
"
_description
=
"
Assign CRM to coordinator company wizard
"
crm_lead_id
=
fields
.
Many2one
(
'
crm.lead
'
)
crm_lead_id
=
fields
.
Many2one
(
"
crm.lead
"
)
assigned_company_id
=
fields
.
Many2one
(
'
res.company
'
,
string
=
'
Assigned company
'
,
"
res.company
"
,
string
=
"
Assigned company
"
,
required
=
True
,
domain
=
[(
'
hierarchy_level
'
,
'
=
'
,
'
coordinator
'
)]
domain
=
[(
"
hierarchy_level
"
,
"
=
"
,
"
coordinator
"
)]
,
)
@api.model
def
default_get
(
self
,
fields_list
):
defaults
=
super
().
default_get
(
fields_list
)
defaults
[
'
crm_lead_id
'
]
=
self
.
env
.
context
[
'
active_id
'
]
defaults
[
"
crm_lead_id
"
]
=
self
.
env
.
context
[
"
active_id
"
]
return
defaults
def
assign_to_coordinator_company
(
self
):
self
.
ensure_one
()
self
.
crm_lead_id
.
write
(
{
'
company_id
'
:
self
.
assigned_company_id
}
self
.
remove_follower
()
self
.
crm_lead_id
.
write
({
"
company_id
"
:
self
.
assigned_company_id
})
self
.
add_follower
()
def
remove_follower
(
self
):
instance_admin
=
self
.
env
.
ref
(
"
energy_communities.role_ce_manager
"
).
id
company_id
=
self
.
crm_lead_id
.
company_id
.
id
followers
=
self
.
env
[
"
res.users
"
].
search
(
[
(
"
role_line_ids.role_id
"
,
"
=
"
,
instance_admin
),
(
"
company_ids.id
"
,
"
=
"
,
company_id
),
]
)
if
followers
:
self
.
crm_lead_id
.
message_unsubscribe
(
partner_ids
=
followers
.
partner_id
.
ids
)
def
add_follower
(
self
):
coordinator_admin
=
self
.
env
.
ref
(
"
energy_communities.role_coord_admin
"
).
id
company_id
=
self
.
crm_lead_id
.
company_id
.
id
followers
=
self
.
env
[
"
res.users
"
].
search
(
[
(
"
role_line_ids.role_id
"
,
"
=
"
,
coordinator_admin
),
(
"
company_ids.id
"
,
"
=
"
,
company_id
),
]
)
if
followers
:
self
.
crm_lead_id
.
message_subscribe
(
partner_ids
=
followers
.
partner_id
.
ids
)
# notify followers
for
follower
in
followers
:
email_values
=
{
"
email_to
"
:
follower
.
partner_id
.
email
}
template
=
self
.
env
.
ref
(
"
energy_communities.email_templ_lead_assigned_to_coordinator_id
"
).
with_context
(
email_values
)
self
.
crm_lead_id
.
message_post_with_template
(
template
.
id
)
Loading