diff options
| author | Thibault Delavallée <tde@odoo.com> | 2020-04-06 12:57:16 +0000 |
|---|---|---|
| committer | Thibault Delavallée <tde@odoo.com> | 2020-04-14 11:53:16 +0000 |
| commit | 2d0db1a0bf57bc70a5a5a18771154be322d436b9 (patch) | |
| tree | f1142ad5394ee73e5c282f954a3d242a499aa4bc /addons | |
| parent | 150095ebc7ef112a03f3e6a4704e06cde6e7c5f0 (diff) | |
[IMP] sales_team, crm: clean sales team tests and extract common test data from crm
PURPOSE
Prepare enhancements of sales team membership.
SPECIFICATIONS
Purpose of this commit is to prepare modifications in sales team management
notably by cleaning sales team tests. We also move some data preparation in
sales team. It allows to rely on some common data while doing sales team
then crm tests.
LINKS
Task ID 2086889 (sales team enhancements)
Task ID 2234698 (preparation lint)
Community PR odoo/odoo#49520
Diffstat (limited to 'addons')
| -rw-r--r-- | addons/crm/tests/common.py | 36 | ||||
| -rw-r--r-- | addons/sales_team/tests/__init__.py | 6 | ||||
| -rw-r--r-- | addons/sales_team/tests/common.py | 62 | ||||
| -rw-r--r-- | addons/sales_team/tests/test_default_team.py | 53 | ||||
| -rw-r--r-- | addons/sales_team/tests/test_sales_team_membership.py | 60 |
5 files changed, 134 insertions, 83 deletions
diff --git a/addons/crm/tests/common.py b/addons/crm/tests/common.py index c1171e4c44d..ce936bb2e3b 100644 --- a/addons/crm/tests/common.py +++ b/addons/crm/tests/common.py @@ -4,8 +4,8 @@ from unittest.mock import patch from odoo.addons.mail.tests.common import MailCase, mail_new_test_user +from odoo.addons.sales_team.tests.common import TestSalesCommon from odoo.fields import Datetime -from odoo.tests.common import SavepointCase INCOMING_EMAIL = """Return-Path: {return_path} X-Original-To: {to} @@ -39,43 +39,21 @@ Cheers, Somebody.""" -class TestCrmCommon(SavepointCase, MailCase): +class TestCrmCommon(TestSalesCommon, MailCase): @classmethod def setUpClass(cls): super(TestCrmCommon, cls).setUpClass() cls._init_mail_gateway() - cls.user_sales_manager = mail_new_test_user( - cls.env, login='user_sales_manager', - name='Martin Sales Manager', email='crm_manager@test.example.com', - company_id=cls.env.ref("base.main_company").id, - notification_type='inbox', - groups='sales_team.group_sale_manager,base.group_partner_manager,crm.group_use_lead', - ) - cls.user_sales_leads = mail_new_test_user( - cls.env, login='user_sales_leads', - name='Laetitia Sales Leads', email='crm_leads@test.example.com', - company_id=cls.env.ref("base.main_company").id, - notification_type='inbox', - groups='sales_team.group_sale_salesman_all_leads,base.group_partner_manager,crm.group_use_lead', - ) - cls.user_sales_salesman = mail_new_test_user( - cls.env, login='user_sales_salesman', - name='Orteil Sales Own', email='crm_salesman@test.example.com', - company_id=cls.env.ref("base.main_company").id, - notification_type='inbox', - groups='sales_team.group_sale_salesman,crm.group_use_lead', - ) - - cls.sales_team_1 = cls.env['crm.team'].create({ - 'name': 'Test Sales Team', + cls.sales_team_1.write({ 'alias_name': 'sales.test', 'use_leads': True, 'use_opportunities': True, - 'company_id': False, - 'user_id': cls.user_sales_manager.id, - 'member_ids': [(4, cls.user_sales_leads.id), (4, cls.env.ref('base.user_admin').id)], + }) + + (cls.user_sales_manager | cls.user_sales_leads | cls.user_sales_salesman).write({ + 'groups_id': [(4, cls.env.ref('crm.group_use_lead').id)] }) cls.env['crm.stage'].search([]).write({'sequence': 9999}) # ensure search will find test data first diff --git a/addons/sales_team/tests/__init__.py b/addons/sales_team/tests/__init__.py index 7bb8a11fc5e..828034121fe 100644 --- a/addons/sales_team/tests/__init__.py +++ b/addons/sales_team/tests/__init__.py @@ -1 +1,5 @@ -from . import test_default_team +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from . import common +from . import test_sales_team_membership diff --git a/addons/sales_team/tests/common.py b/addons/sales_team/tests/common.py new file mode 100644 index 00000000000..a06f97c02c2 --- /dev/null +++ b/addons/sales_team/tests/common.py @@ -0,0 +1,62 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from odoo.addons.mail.tests.common import mail_new_test_user +from odoo.tests.common import SavepointCase + + +class TestSalesCommon(SavepointCase): + + @classmethod + def setUpClass(cls): + super(TestSalesCommon, cls).setUpClass() + + cls.company_main = cls.env.user.company_id + cls.user_sales_manager = mail_new_test_user( + cls.env, login='user_sales_manager', + name='Martin Sales Manager', email='crm_manager@test.example.com', + company_id=cls.company_main.id, + notification_type='inbox', + groups='sales_team.group_sale_manager,base.group_partner_manager', + ) + cls.user_sales_leads = mail_new_test_user( + cls.env, login='user_sales_leads', + name='Laetitia Sales Leads', email='crm_leads@test.example.com', + company_id=cls.company_main.id, + notification_type='inbox', + groups='sales_team.group_sale_salesman_all_leads,base.group_partner_manager', + ) + cls.user_sales_salesman = mail_new_test_user( + cls.env, login='user_sales_salesman', + name='Orteil Sales Own', email='crm_salesman@test.example.com', + company_id=cls.company_main.id, + notification_type='inbox', + groups='sales_team.group_sale_salesman', + ) + + cls.env['crm.team'].search([]).write({'sequence': 9999}) + cls.sales_team_1 = cls.env['crm.team'].create({ + 'name': 'Test Sales Team', + 'sequence': 5, + 'company_id': False, + 'user_id': cls.user_sales_manager.id, + 'member_ids': [(4, cls.user_sales_leads.id), (4, cls.env.ref('base.user_admin').id)], + }) + + +class TestSalesMC(TestSalesCommon): + """ Multi Company / Multi Sales Team environment """ + + @classmethod + def setUpClass(cls): + super(TestSalesMC, cls).setUpClass() + cls.company_2 = cls.env['res.company'].create({ + 'name': 'New Test Company', + 'email': 'company.2@test.example.com', + 'country_id': cls.env.ref('base.fr'), + }) + cls.team_c2 = cls.env['crm.team'].create({ + 'name': 'C2 Team1', + 'sequence': 1, + 'company_id': cls.company_2.id, + }) diff --git a/addons/sales_team/tests/test_default_team.py b/addons/sales_team/tests/test_default_team.py deleted file mode 100644 index 8d7b24d0357..00000000000 --- a/addons/sales_team/tests/test_default_team.py +++ /dev/null @@ -1,53 +0,0 @@ -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') - cls.team_3 = cls.env['crm.team'].create({ - 'name': 'Team 3', - 'sequence': 2, - 'company_id': False - }) - - def test_01_user_team(self): - """Get default team, when user belongs to one.""" - team = self.CrmTeam.with_user(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.with_user(self.user)._get_default_team_id() - self.assertEqual(team, self.team_2) - # Case 2. If default team is not active, fall back is the next team with the higher sequence - self.team_2.active = False - team = self.CrmTeam.with_user(self.user)._get_default_team_id() - self.assertEqual(team, self.team_3) diff --git a/addons/sales_team/tests/test_sales_team_membership.py b/addons/sales_team/tests/test_sales_team_membership.py new file mode 100644 index 00000000000..8e08178915f --- /dev/null +++ b/addons/sales_team/tests/test_sales_team_membership.py @@ -0,0 +1,60 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from odoo.addons.sales_team.tests.common import TestSalesMC + + +class TestDefaultTeam(TestSalesMC): + """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.team_sequence = cls.env['crm.team'].create({ + 'name': 'Team LowSequence', + 'sequence': 0, + 'company_id': False, + }) + cls.team_responsible = cls.env['crm.team'].create({ + 'name': 'Team 3', + 'user_id': cls.user_sales_manager.id, + 'sequence': 3, + 'company_id': cls.company_main.id + }) + + def test_default_team_member(self): + with self.with_user('user_sales_leads'): + team = self.env['crm.team']._get_default_team_id() + self.assertEqual(team, self.sales_team_1) + + # responsible with lower sequence better than member with higher sequence + self.team_responsible.user_id = self.user_sales_leads.id + with self.with_user('user_sales_leads'): + team = self.env['crm.team']._get_default_team_id() + self.assertEqual(team, self.team_responsible) + + def test_default_team_fallback(self): + """ Test fallback: domain, order """ + self.sales_team_1.member_ids = [(5,)] + + with self.with_user('user_sales_leads'): + team = self.env['crm.team']._get_default_team_id() + self.assertEqual(team, self.team_sequence) + + # next one is team_responsible with sequence = 3 (team_c2 is in another company) + self.team_sequence.active = False + with self.with_user('user_sales_leads'): + team = self.env['crm.team']._get_default_team_id() + self.assertEqual(team, self.team_responsible) + + self.user_sales_leads.write({ + 'company_ids': [(4, self.company_2.id)], + 'company_id': self.company_2.id, + }) + # multi company: switch company + self.user_sales_leads.write({'company_id': self.company_2.id}) + with self.with_user('user_sales_leads'): + team = self.env['crm.team']._get_default_team_id() + self.assertEqual(team, self.team_c2) |
