[FIX] sales_team: ignore inactive team
When using `sales_team.team_sales_department` as fall back default team, last condition that checks if such team can be default was incorrect, because `active` value check was mixed with lead type check. In other words: True or False and False => True But intention is: (True or False) and False => False opw 1997715 closes odoo/odoo#33316 Signed-off-by: Damien Bouvy (dbo) <dbo@odoo.com>
This commit is contained in:
@@ -38,7 +38,7 @@ class CrmTeam(models.Model):
|
||||
default_team_id.check_access_rule('read')
|
||||
except AccessError:
|
||||
return self.env['crm.team']
|
||||
if self.env.context.get('default_type') != 'lead' or default_team_id.use_leads and default_team_id.active:
|
||||
if (self.env.context.get('default_type') != 'lead' or default_team_id.use_leads) and default_team_id.active:
|
||||
team_id = default_team_id
|
||||
return team_id
|
||||
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
from . import test_default_team
|
||||
@@ -0,0 +1,48 @@
|
||||
from odoo.tests import common
|
||||
|
||||
|
||||
class TestDefaultTeam(common.SavepointCase):
|
||||
"""Tests to check if correct default team is found."""
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
"""Set up data for default team tests."""
|
||||
super(TestDefaultTeam, cls).setUpClass()
|
||||
cls.CrmTeam = cls.env['crm.team']
|
||||
ResUsers = cls.env['res.users'].with_context(
|
||||
{'no_reset_password': True})
|
||||
group_sale_manager = cls.env.ref('sales_team.group_sale_manager')
|
||||
cls.user = ResUsers.create({
|
||||
'name': 'Team User',
|
||||
'login': 'sales_team_user',
|
||||
'email': 'sales.team.user@example.com',
|
||||
'groups_id': [(6, 0, [group_sale_manager.id])]
|
||||
})
|
||||
cls.team_1 = cls.env['crm.team'].create({
|
||||
'name': 'Test Team',
|
||||
'member_ids': [(4, cls.user.id)],
|
||||
'company_id': False
|
||||
})
|
||||
# Europe Team (fall back team)
|
||||
cls.team_2 = cls.env.ref('sales_team.team_sales_department')
|
||||
|
||||
def test_01_user_team(self):
|
||||
"""Get default team, when user belongs to one."""
|
||||
team = self.CrmTeam.sudo(self.user)._get_default_team_id()
|
||||
self.assertEqual(team, self.team_1)
|
||||
|
||||
def test_02_fallback_team(self):
|
||||
"""Get default team when user does not belong to any team.
|
||||
|
||||
Case 1: fall back default team (from XML ref) is active.
|
||||
Case 2: fall back default team is not active.
|
||||
"""
|
||||
# Clear users from team.
|
||||
self.team_1.member_ids = [(5,)]
|
||||
# Case 1.
|
||||
team = self.CrmTeam.sudo(self.user)._get_default_team_id()
|
||||
self.assertEqual(team, self.team_2)
|
||||
# Case 2.
|
||||
self.team_2.active = False
|
||||
team = self.CrmTeam.sudo(self.user)._get_default_team_id()
|
||||
self.assertEqual(team, self.CrmTeam)
|
||||
Reference in New Issue
Block a user