diff --git a/addons/sales_team/tests/common.py b/addons/sales_team/tests/common.py index 8dcd51a2645..c1c3ce1e484 100644 --- a/addons/sales_team/tests/common.py +++ b/addons/sales_team/tests/common.py @@ -1,8 +1,47 @@ # -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. +from odoo.tests import TransactionCase + from odoo.addons.mail.tests.common import mail_new_test_user -from odoo.tests.common import TransactionCase +from odoo.addons.base.tests.common import DISABLED_MAIL_CONTEXT + +class SalesTeamCommon(TransactionCase): + + @classmethod + def setUpClass(cls): + super().setUpClass() + + cls.env = cls.env['base'].with_context(**DISABLED_MAIL_CONTEXT).env + + cls.group_sale_salesman = cls.env.ref('sales_team.group_sale_salesman') + cls.group_sale_manager = cls.env.ref('sales_team.group_sale_manager') + + cls.sale_user = cls.env['res.users'].create({ + 'name': 'Test Salesman', + 'login': 'salesman', + 'password': 'salesman', + 'email': 'default_user_salesman@example.com', + 'signature': '--\nMark', + 'notification_type': 'email', + 'groups_id': [(6, 0, cls.group_sale_salesman.ids)], + }) + cls.sale_manager = cls.env['res.users'].create({ + 'name': 'Test Sales Manager', + 'login': 'salesmanager', + 'password': 'salesmanager', + 'email': 'default_user_salesmanager@example.com', + 'signature': '--\nDamien', + 'notification_type': 'email', + 'groups_id': [(6, 0, cls.group_sale_manager.ids)], + }) + cls.sale_team = cls.env['crm.team'].create({ + 'name': 'Test Sales Team', + }) + # Disable other teams (demo data/existing data) + cls.env['crm.team'].search([ + ('id', '!=', cls.sale_team.id), + ]).action_archive() class TestSalesCommon(TransactionCase): diff --git a/addons/sales_team/tests/test_sales_team.py b/addons/sales_team/tests/test_sales_team.py index 06953959e31..04c0dcf7135 100644 --- a/addons/sales_team/tests/test_sales_team.py +++ b/addons/sales_team/tests/test_sales_team.py @@ -2,8 +2,9 @@ # Part of Odoo. See LICENSE file for full copyright and licensing details. from odoo import exceptions -from odoo.addons.sales_team.tests.common import TestSalesCommon, TestSalesMC -from odoo.tests.common import users +from odoo.tests import tagged, users + +from odoo.addons.sales_team.tests.common import SalesTeamCommon, TestSalesCommon, TestSalesMC class TestDefaultTeam(TestSalesCommon): @@ -202,3 +203,30 @@ class TestMultiCompany(TestSalesMC): # cannot change company as it breaks memberships mc check with self.assertRaises(exceptions.UserError): team_c2.write({'company_id': self.company_2.id}) + + +@tagged('post_install', '-at_install') +class TestAccessRights(SalesTeamCommon): + + @users('salesmanager') + def test_access_sales_manager(self): + """ Test sales manager's access rights """ + # Manager can create a Sales Team + india_channel = self.env['crm.team'].with_context(tracking_disable=True).create({ + 'name': 'India', + }) + self.assertIn( + india_channel.id, self.env['crm.team'].search([]).ids, + 'Sales manager should be able to create a Sales Team') + + # Manager can edit a Sales Team + india_channel.write({'name': 'new_india'}) + self.assertEqual( + india_channel.name, 'new_india', + 'Sales manager should be able to edit a Sales Team') + + # Manager can delete a Sales Team + india_channel.unlink() + self.assertNotIn( + india_channel.id, self.env['crm.team'].search([]).ids, + 'Sales manager should be able to delete a Sales Team')