[FIX] sales_team: display correct alias in pipeline

Steps to reproduce:
- Create a new user with no affiliated sales team
- Activate custom mail server with an alias domain
- Login with new user
- Check pipeline in CRM
- The empty pipeline message will show the wrong alias

Issues:
The alias displayed is not for the team of the user.

opw-3608263

closes odoo/odoo#152563

X-original-commit: f862673885aa8fad9b8b225d020cd2757d7be013
Signed-off-by: Mattis Megevand (mmeg) <mmeg@odoo.com>
This commit is contained in:
Mattis Megevand (mmeg)
2024-02-06 14:29:04 +00:00
parent a015f17ce6
commit cac7a44dd2
2 changed files with 76 additions and 9 deletions
+12 -9
View File
@@ -1285,15 +1285,18 @@ class Lead(models.Model):
help_title = _('Create a new lead')
else:
help_title = _('Create an opportunity to start playing with your pipeline.')
alias_record = self.env['mail.alias'].search([
('alias_name', '!=', False),
('alias_name', '!=', ''),
('alias_model_id.model', '=', 'crm.lead'),
('alias_parent_model_id.model', '=', 'crm.team'),
('alias_force_thread_id', '=', False)
], limit=1)
if alias_record.alias_domain and alias_record.alias_name:
alias_domain = [
('company_id', '=', self.env.company.id),
('alias_id.alias_name', '!=', False),
('alias_id.alias_name', '!=', ''),
('alias_id.alias_model_id.model', '=', 'crm.lead'),
]
# sort by use_leads, then by our membership of the team
alias_records = self.env['crm.team'].search(alias_domain).sorted(
lambda r: (r.use_leads, self.env.user in r.member_ids), reverse=True
)
alias_record = alias_records[0] if alias_records else None
if alias_record and alias_record.alias_domain and alias_record.alias_name:
sub_title = Markup(_('Use the <i>New</i> button, or send an email to %(email_link)s to test the email gateway.')) % {
'email_link': Markup("<b><a href='mailto:%s'>%s</a></b>") % (alias_record.display_name, alias_record.display_name),
}
+64
View File
@@ -654,6 +654,70 @@ class TestCRMLead(TestCrmCommon):
# self.assertFalse(new_team.alias_id.alias_name)
# self.assertFalse(new_team.alias_name)
@users('user_sales_manager')
def test_crm_team_alias_helper(self):
"""Test that the help message is the right one if we are on multiple team with different settings."""
# archive other teams
self.env['crm.team'].search([]).active = False
self._activate_multi_company()
team_other_comp = self.team_company2
user_team_leads, team_leads, user_team_opport, team_opport = self.env['crm.team'].create([{
'name': 'UserTeamLeads',
'use_leads': True,
'member_ids': [(6, 0, [self.env.user.id])],
}, {
'name': 'TeamLeads',
'use_leads': True,
'member_ids': [],
}, {
'name': 'UserTeamOpportunities',
'use_leads': False,
'member_ids': [(6, 0, [self.env.user.id])],
}, {
'name': 'TeamOpportunities',
'use_leads': False,
'member_ids': [],
}])
self.env['crm.lead'].create([{
'name': 'LeadOurTeam',
'team_id': user_team_leads.id,
'type': 'lead',
}, {
'name': 'LeadTeam',
'team_id': team_leads.id,
'type': 'lead',
}, {
'name': 'OpportunityOurTeam',
'team_id': user_team_opport.id,
'type': 'opportunity',
}, {
'name': 'OpportunityTeam',
'team_id': team_opport.id,
'type': 'opportunity',
}])
self.env['crm.lead'].with_user(self.user_sales_manager_mc).create({
'name': 'LeadOtherComp',
'team_id': team_other_comp.id,
'type': 'lead',
'company_id': self.company_2.id,
})
# archive our team one by one and check that we have the correct help message
teams = [user_team_leads, team_leads, user_team_opport, team_opport, team_other_comp]
for team in teams:
team.alias_id.sudo().write({'alias_name': team.name})
for team in teams:
with self.subTest(team=team):
if team != team_other_comp:
self.assertIn(f"<a href='mailto:{team.display_name}'>{team.display_name}</a>", self.env['crm.lead'].sudo().get_empty_list_help(""))
else:
self.assertNotIn(f"<a href='mailto:{team.display_name}'>{team.display_name}</a>", self.env['crm.lead'].sudo().get_empty_list_help(""))
team.active = False
@mute_logger('odoo.addons.mail.models.mail_thread')
def test_mailgateway(self):
new_lead = self.format_and_process(