mirror of
https://github.com/bringout/oca-ocb-sale.git
synced 2026-04-26 04:12:02 +02:00
19.0 vanilla
This commit is contained in:
parent
79f83631d5
commit
73afc09215
6267 changed files with 1534193 additions and 1130106 deletions
|
|
@ -1,19 +1,17 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo.tests import TransactionCase
|
||||
|
||||
from odoo.addons.base.tests.common import BaseCommon
|
||||
from odoo.addons.mail.tests.common import mail_new_test_user
|
||||
from odoo.addons.base.tests.common import DISABLED_MAIL_CONTEXT
|
||||
|
||||
class SalesTeamCommon(TransactionCase):
|
||||
|
||||
class SalesTeamCommon(BaseCommon):
|
||||
|
||||
@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')
|
||||
|
||||
|
|
@ -24,7 +22,7 @@ class SalesTeamCommon(TransactionCase):
|
|||
'email': 'default_user_salesman@example.com',
|
||||
'signature': '--\nMark',
|
||||
'notification_type': 'email',
|
||||
'groups_id': [(6, 0, cls.group_sale_salesman.ids)],
|
||||
'group_ids': [(6, 0, cls.group_sale_salesman.ids)],
|
||||
})
|
||||
cls.sale_manager = cls.env['res.users'].create({
|
||||
'name': 'Test Sales Manager',
|
||||
|
|
@ -33,7 +31,7 @@ class SalesTeamCommon(TransactionCase):
|
|||
'email': 'default_user_salesmanager@example.com',
|
||||
'signature': '--\nDamien',
|
||||
'notification_type': 'email',
|
||||
'groups_id': [(6, 0, cls.group_sale_manager.ids)],
|
||||
'group_ids': [(6, 0, cls.group_sale_manager.ids)],
|
||||
})
|
||||
cls.sale_team = cls.env['crm.team'].create({
|
||||
'name': 'Test Sales Team',
|
||||
|
|
@ -43,6 +41,11 @@ class SalesTeamCommon(TransactionCase):
|
|||
('id', '!=', cls.sale_team.id),
|
||||
]).action_archive()
|
||||
|
||||
@classmethod
|
||||
def get_default_groups(cls):
|
||||
groups = super().get_default_groups()
|
||||
return groups | cls.quick_ref('sales_team.group_sale_manager')
|
||||
|
||||
|
||||
class TestSalesCommon(TransactionCase):
|
||||
|
||||
|
|
|
|||
|
|
@ -1,10 +1,14 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo import exceptions
|
||||
from odoo.tests import tagged, users
|
||||
from odoo.addons.mail.tests.common import mail_new_test_user
|
||||
|
||||
from odoo.addons.sales_team.tests.common import SalesTeamCommon, TestSalesCommon, TestSalesMC
|
||||
from odoo.addons.sales_team.tests.common import (
|
||||
SalesTeamCommon,
|
||||
TestSalesCommon,
|
||||
TestSalesMC,
|
||||
)
|
||||
|
||||
|
||||
class TestDefaultTeam(TestSalesCommon):
|
||||
|
|
@ -164,7 +168,7 @@ class TestMultiCompany(TestSalesMC):
|
|||
team_c2.write({'member_ids': [(4, self.env.user.id)]})
|
||||
self.assertEqual(team_c2.member_ids, self.env.user)
|
||||
|
||||
# cannot add someone from another company
|
||||
# cannot add someone from another company (when user allowed only in c1 and team is in c2)
|
||||
with self.assertRaises(exceptions.UserError):
|
||||
team_c2.write({'member_ids': [(4, self.user_sales_salesman.id)]})
|
||||
|
||||
|
|
@ -174,10 +178,25 @@ class TestMultiCompany(TestSalesMC):
|
|||
team_c2.write({'member_ids': [(4, self.user_sales_salesman.id)]})
|
||||
self.assertEqual(team_c2.member_ids, self.user_sales_salesman)
|
||||
|
||||
# cannot change company as it breaks memberships mc check
|
||||
# cannot change team company if its users aren't allowed in the new company
|
||||
with self.assertRaises(exceptions.UserError):
|
||||
team_c2.write({'company_id': self.company_2.id})
|
||||
|
||||
# a user allowed in multiple companies can be added to a team of any of these companies
|
||||
team_c2.write({'member_ids': [(5, 0)]})
|
||||
team_c2.write({'company_id': self.company_2.id})
|
||||
c1, c2 = self.company_main, self.company_2
|
||||
with self.with_user('admin'): # user_sales_manager can't create user
|
||||
user_c1_c2 = mail_new_test_user(
|
||||
self.env,
|
||||
login=f"Test_user_default_to_c{c1.id}_allowed_c{'c'.join(map(str, [c1.id, c2.id]))}",
|
||||
company_id=c1.id,
|
||||
company_ids=[(4, company.id) for company in c1 + c2]
|
||||
)
|
||||
user_c1_c2 = user_c1_c2.with_env(self.env)
|
||||
team_c2.write({'member_ids': [(4, user_c1_c2.id)]})
|
||||
self.assertIn(user_c1_c2, team_c2.member_ids)
|
||||
|
||||
@users('user_sales_manager')
|
||||
def test_team_memberships(self):
|
||||
""" Test update of team member involving company check """
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo import exceptions
|
||||
from odoo.tests.common import TransactionCase, users
|
||||
from odoo.tools import mute_logger
|
||||
|
||||
from odoo.addons.mail.tests.common import mail_new_test_user
|
||||
from odoo.addons.sales_team.tests.common import TestSalesMC
|
||||
from odoo.tests.common import users, TransactionCase
|
||||
from odoo.tools import mute_logger
|
||||
|
||||
|
||||
class TestCornerCases(TransactionCase):
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# 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
|
||||
from odoo.tests.common import users
|
||||
from odoo.tools import mute_logger
|
||||
|
||||
from odoo.addons.sales_team.tests.common import TestSalesCommon
|
||||
|
||||
|
||||
class TestMembership(TestSalesCommon):
|
||||
"""Tests to ensure membership behavior """
|
||||
|
|
@ -19,6 +19,12 @@ class TestMembership(TestSalesCommon):
|
|||
})
|
||||
cls.env['ir.config_parameter'].set_param('sales_team.membership_multi', True)
|
||||
|
||||
def test_archive_user_archives_team_member(self):
|
||||
"""Test that archiving a user also archives their linked team member."""
|
||||
self.assertTrue(self.sales_team_1_m1.active)
|
||||
self.user_sales_leads.action_archive()
|
||||
self.assertFalse(self.sales_team_1_m1.active)
|
||||
|
||||
@users('user_sales_manager')
|
||||
def test_fields(self):
|
||||
self.assertTrue(self.sales_team_1.with_user(self.env.user).is_membership_multi)
|
||||
|
|
@ -52,7 +58,7 @@ class TestMembership(TestSalesCommon):
|
|||
self.assertEqual(sales_team_1.member_ids, self.user_admin)
|
||||
|
||||
# create a new user on the fly, just for testing
|
||||
self.user_sales_manager.write({'groups_id': [(4, self.env.ref('base.group_system').id)]})
|
||||
self.user_sales_manager.write({'group_ids': [(4, self.env.ref('base.group_system').id)]})
|
||||
new_team.write({'member_ids': [(0, 0, {
|
||||
'name': 'Marty OnTheMCFly',
|
||||
'login': 'mcfly@test.example.com',
|
||||
|
|
@ -60,7 +66,7 @@ class TestMembership(TestSalesCommon):
|
|||
new_user = self.env['res.users'].search([('login', '=', 'mcfly@test.example.com')])
|
||||
self.assertTrue(len(new_user))
|
||||
self.assertEqual(new_team.member_ids, self.env.user | self.user_sales_leads | new_user)
|
||||
self.user_sales_manager.write({'groups_id': [(3, self.env.ref('base.group_system').id)]})
|
||||
self.user_sales_manager.write({'group_ids': [(3, self.env.ref('base.group_system').id)]})
|
||||
|
||||
self.env.flush_all()
|
||||
memberships = self.env['crm.team.member'].with_context(active_test=False).search([('user_id', '=', self.user_sales_leads.id)])
|
||||
|
|
@ -95,7 +101,7 @@ class TestMembership(TestSalesCommon):
|
|||
self.assertEqual(sales_team_1.member_ids, self.user_sales_leads | self.user_admin)
|
||||
|
||||
# create a new user on the fly, just for testing
|
||||
self.user_sales_manager.write({'groups_id': [(4, self.env.ref('base.group_system').id)]})
|
||||
self.user_sales_manager.write({'group_ids': [(4, self.env.ref('base.group_system').id)]})
|
||||
new_team.write({'member_ids': [(0, 0, {
|
||||
'name': 'Marty OnTheMCFly',
|
||||
'login': 'mcfly@test.example.com',
|
||||
|
|
@ -103,7 +109,7 @@ class TestMembership(TestSalesCommon):
|
|||
new_user = self.env['res.users'].search([('login', '=', 'mcfly@test.example.com')])
|
||||
self.assertTrue(len(new_user))
|
||||
self.assertEqual(new_team.member_ids, self.env.user | self.user_sales_leads | new_user)
|
||||
self.user_sales_manager.write({'groups_id': [(3, self.env.ref('base.group_system').id)]})
|
||||
self.user_sales_manager.write({'group_ids': [(3, self.env.ref('base.group_system').id)]})
|
||||
self.env.flush_all()
|
||||
|
||||
# still avoid duplicated team / user entries
|
||||
|
|
@ -153,19 +159,19 @@ class TestMembership(TestSalesCommon):
|
|||
self.assertEqual(sales_team_1.member_ids, self.user_admin | self.user_sales_leads)
|
||||
|
||||
# activate another team membership: previous team membership should be de activated
|
||||
new_nt.toggle_active()
|
||||
new_nt.action_unarchive()
|
||||
self.assertTrue(new_nt.active)
|
||||
self.assertFalse(old_st_1.active)
|
||||
self.assertFalse(new_st_1.active)
|
||||
# activate another team membership: previous team membership should be de activated
|
||||
old_st_1.toggle_active()
|
||||
old_st_1.action_unarchive()
|
||||
self.assertFalse(new_nt.active)
|
||||
self.assertTrue(old_st_1.active)
|
||||
self.assertFalse(new_st_1.active)
|
||||
|
||||
# try to activate duplicate memberships again, which should trigger issues
|
||||
with self.assertRaises(exceptions.UserError):
|
||||
new_st_1.toggle_active()
|
||||
new_st_1.action_unarchive()
|
||||
|
||||
@users('user_sales_manager')
|
||||
def test_memberships_multi(self):
|
||||
|
|
@ -211,7 +217,7 @@ class TestMembership(TestSalesCommon):
|
|||
|
||||
# try to activate duplicate memberships again, which should trigger issues
|
||||
with self.assertRaises(exceptions.UserError):
|
||||
old_st_1.toggle_active()
|
||||
old_st_1.action_unarchive()
|
||||
|
||||
@users('user_sales_manager')
|
||||
def test_memberships_sync(self):
|
||||
|
|
@ -275,24 +281,6 @@ class TestMembership(TestSalesCommon):
|
|||
with self.assertRaises(exceptions.UserError), mute_logger('odoo.sql_db'):
|
||||
added.write({'crm_team_id': sales_team_1.id})
|
||||
|
||||
def test_sales_team_member_search(self):
|
||||
""" when a search is triggered on the member_ids field in crm.team
|
||||
it is currently returning the archived records also. this test will
|
||||
ensure that the search wont return archived record.
|
||||
|
||||
this is to fix unwanted ORM behavior
|
||||
"""
|
||||
self.env['res.partner'].create({'name': 'Test Partner', 'team_id': self.new_team.id})
|
||||
self.env['crm.team.member'].create({
|
||||
'user_id': self.env.uid,
|
||||
'crm_team_id': self.new_team.id,
|
||||
'active': False,
|
||||
})
|
||||
partner_exists = self.env['res.partner'].search([
|
||||
('team_id.member_ids', 'in', [self.env.uid])
|
||||
])
|
||||
self.assertFalse(partner_exists, msg="Partner should return empty as current user is removed from team")
|
||||
|
||||
def test_users_sale_team_id(self):
|
||||
self.assertTrue(self.sales_team_1.sequence < self.new_team.sequence)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue