[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:
Andrius Laukavičius
2019-05-14 10:09:24 +00:00
parent 99a12a94c2
commit 476a53bbf0
3 changed files with 50 additions and 1 deletions
+1 -1
View File
@@ -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
+1
View File
@@ -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)