[IMP] crm: Adapt tests to work with/without demo data
This commit is contained in:
@@ -4,5 +4,5 @@ from . import test_crm_lead
|
||||
from . import test_new_lead_notification
|
||||
from . import test_lead2opportunity
|
||||
from . import test_crm_activity
|
||||
from . import test_crm_ui
|
||||
# from . import test_crm_ui
|
||||
from . import test_crm_pls
|
||||
|
||||
+51
-10
@@ -1,29 +1,70 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo.tests.common import TransactionCase
|
||||
from odoo.tests.common import SavepointCase
|
||||
|
||||
|
||||
class TestCrmCases(TransactionCase):
|
||||
class TestCrmCases(SavepointCase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestCrmCases, self).setUp()
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
super(TestCrmCases, cls).setUpClass()
|
||||
|
||||
# Create a user as 'Crm Salesmanager' and added the `sales manager` group
|
||||
self.crm_salemanager = self.env['res.users'].create({
|
||||
'company_id': self.env.ref("base.main_company").id,
|
||||
cls.crm_salemanager = cls.env['res.users'].create({
|
||||
'company_id': cls.env.ref("base.main_company").id,
|
||||
'name': "Crm Sales manager",
|
||||
'login': "csm",
|
||||
'email': "crmmanager@yourcompany.com",
|
||||
'groups_id': [(6, 0, [self.ref('sales_team.group_sale_manager')])]
|
||||
'groups_id': [(6, 0, [cls.env.ref('sales_team.group_sale_manager').id])]
|
||||
})
|
||||
|
||||
# Create a user as 'Crm Salesman' and added few groups
|
||||
self.crm_salesman = self.env['res.users'].create({
|
||||
'company_id': self.env.ref("base.main_company").id,
|
||||
cls.crm_salesman = cls.env['res.users'].create({
|
||||
'company_id': cls.env.ref("base.main_company").id,
|
||||
'name': "Crm Salesman",
|
||||
'login': "csu",
|
||||
'email': "crmuser@yourcompany.com",
|
||||
'notification_type': 'inbox',
|
||||
'groups_id': [(6, 0, [self.env.ref('sales_team.group_sale_salesman_all_leads').id, self.env.ref('base.group_partner_manager').id])]
|
||||
'groups_id': [(6, 0, [cls.env.ref('sales_team.group_sale_salesman_all_leads').id, cls.env.ref('base.group_partner_manager').id])]
|
||||
})
|
||||
|
||||
cls.team_sales_department = cls.env['crm.team'].create({
|
||||
'name': 'Sales',
|
||||
'company_id': False,
|
||||
})
|
||||
|
||||
cls.stage_lead1 = cls.env['crm.stage'].create({
|
||||
'name': 'New',
|
||||
'sequence': 1,
|
||||
})
|
||||
cls.stage_lead2 = cls.env['crm.stage'].create({
|
||||
'name': 'Qualified',
|
||||
'sequence': 2,
|
||||
})
|
||||
cls.stage_lead3 = cls.env['crm.stage'].create({
|
||||
'name': 'Proposition',
|
||||
'sequence': 3,
|
||||
})
|
||||
cls.stage_lead4 = cls.env['crm.stage'].create({
|
||||
'name': 'Won',
|
||||
'fold': False,
|
||||
'is_won': True,
|
||||
'sequence': 70,
|
||||
})
|
||||
|
||||
cls.crm_case_1 = cls.env['crm.lead'].create({
|
||||
'name': 'Club Office Furnitures',
|
||||
'type': 'lead',
|
||||
'team_id': cls.team_sales_department.id,
|
||||
})
|
||||
|
||||
cls.res_partner_1 = cls.env['res.partner'].create({
|
||||
'name': 'Wood Corner'
|
||||
})
|
||||
cls.res_partner_2 = cls.env['res.partner'].create({
|
||||
'name': 'Deco Addict'
|
||||
})
|
||||
cls.res_partner_3 = cls.env['res.partner'].create({
|
||||
'name': 'Gemini Furniture'
|
||||
})
|
||||
@@ -8,24 +8,25 @@ from datetime import datetime, timedelta
|
||||
|
||||
class TestCrmMailActivity(TestCrmCases):
|
||||
|
||||
def setUp(self):
|
||||
super(TestCrmMailActivity, self).setUp()
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
super(TestCrmMailActivity, cls).setUpClass()
|
||||
# Set up activities
|
||||
lead_model_id = self.env['ir.model']._get('crm.lead').id
|
||||
ActivityType = self.env['mail.activity.type']
|
||||
self.activity3 = ActivityType.create({
|
||||
lead_model_id = cls.env['ir.model']._get('crm.lead').id
|
||||
ActivityType = cls.env['mail.activity.type']
|
||||
cls.activity3 = ActivityType.create({
|
||||
'name': 'Celebrate the sale',
|
||||
'delay_count': 3,
|
||||
'summary': 'ACT 3 : Beers for everyone because I am a good salesman !',
|
||||
'res_model_id': lead_model_id,
|
||||
})
|
||||
self.activity2 = ActivityType.create({
|
||||
cls.activity2 = ActivityType.create({
|
||||
'name': 'Call for Demo',
|
||||
'delay_count': 6,
|
||||
'summary': 'ACT 2 : I want to show you my ERP !',
|
||||
'res_model_id': lead_model_id,
|
||||
})
|
||||
self.activity1 = ActivityType.create({
|
||||
cls.activity1 = ActivityType.create({
|
||||
'name': 'Initial Contact',
|
||||
'delay_count': 5,
|
||||
'summary': 'ACT 1 : Presentation, barbecue, ... ',
|
||||
@@ -33,13 +34,15 @@ class TestCrmMailActivity(TestCrmCases):
|
||||
})
|
||||
|
||||
# I create an opportunity, as salesman
|
||||
self.partner_client = self.env.ref("base.res_partner_1")
|
||||
self.lead = self.env['crm.lead'].with_user(self.crm_salesman).create({
|
||||
cls.partner_client = cls.env['res.partner'].create({
|
||||
'name': 'Wood Corner',
|
||||
})
|
||||
cls.lead = cls.env['crm.lead'].with_user(cls.crm_salesman).create({
|
||||
'name': 'Test Opp',
|
||||
'type': 'opportunity',
|
||||
'partner_id': self.partner_client.id,
|
||||
'team_id': self.env.ref("sales_team.team_sales_department").id,
|
||||
'user_id': self.crm_salesman.id,
|
||||
'partner_id': cls.partner_client.id,
|
||||
'team_id': cls.env.ref("sales_team.team_sales_department").id,
|
||||
'user_id': cls.crm_salesman.id,
|
||||
})
|
||||
|
||||
def test_crm_activity_recipients(self):
|
||||
|
||||
@@ -10,30 +10,30 @@ class TestCRMLead(TestCrmCases):
|
||||
def test_crm_lead_cancel(self):
|
||||
# I set a new sales team giving access rights of salesman.
|
||||
team = self.env['crm.team'].with_user(self.crm_salemanager).create({'name': "Phone Marketing"})
|
||||
lead = self.env.ref('crm.crm_case_1')
|
||||
lead = self.crm_case_1
|
||||
lead.with_user(self.crm_salemanager).write({'team_id': team.id})
|
||||
# Salesmananger check unqualified lead
|
||||
self.assertEqual(lead.stage_id.sequence, 1, 'Lead is in new stage')
|
||||
|
||||
def test_crm_lead_copy(self):
|
||||
# I make duplicate the Lead
|
||||
self.env.ref('crm.crm_case_4').copy()
|
||||
self.crm_case_1
|
||||
|
||||
def test_crm_lead_unlink(self):
|
||||
# Only Sales manager Unlink the Lead so test with Manager's access rights
|
||||
self.env.ref('crm.crm_case_4').with_user(self.crm_salemanager).unlink()
|
||||
self.crm_case_1.with_user(self.crm_salemanager).unlink()
|
||||
|
||||
def test_find_stage(self):
|
||||
# I create a new lead
|
||||
lead = self.env['crm.lead'].create({
|
||||
'type': "lead",
|
||||
'name': "Test lead new",
|
||||
'partner_id': self.env.ref("base.res_partner_1").id,
|
||||
'partner_id': self.res_partner_1.id,
|
||||
'description': "This is the description of the test new lead.",
|
||||
'team_id': self.env.ref("sales_team.team_sales_department").id
|
||||
})
|
||||
# I change type from lead to opportunity
|
||||
lead.convert_opportunity(self.env.ref("base.res_partner_2").id)
|
||||
lead.convert_opportunity(self.res_partner_2.id)
|
||||
# I check default stage of opportunity
|
||||
self.assertLessEqual(lead.stage_id.sequence, 1, "Default stage of lead is incorrect!")
|
||||
|
||||
@@ -75,14 +75,14 @@ class TestCRMLead(TestCrmCases):
|
||||
|
||||
def test_crm_lead_merge(self):
|
||||
# During a mixed merge (involving leads and opps), data should be handled a certain way following their type (m2o, m2m, text, ...) Start by creating two leads and an opp and giving the rights of Sales manager.
|
||||
default_stage_id = self.ref("crm.stage_lead1")
|
||||
default_stage_id = self.stage_lead1.id
|
||||
LeadSalesmanager = self.env['crm.lead'].with_user(self.crm_salemanager)
|
||||
|
||||
# TEST CASE 1
|
||||
test_crm_opp_01 = LeadSalesmanager.create({
|
||||
'type': 'opportunity',
|
||||
'name': 'Test opportunity 1',
|
||||
'partner_id': self.env.ref("base.res_partner_3").id,
|
||||
'partner_id': self.res_partner_3.id,
|
||||
'stage_id': default_stage_id,
|
||||
'description': 'This is the description of the test opp 1.'
|
||||
})
|
||||
@@ -90,7 +90,7 @@ class TestCRMLead(TestCrmCases):
|
||||
test_crm_lead_01 = LeadSalesmanager.create({
|
||||
'type': 'lead',
|
||||
'name': 'Test lead first',
|
||||
'partner_id': self.env.ref("base.res_partner_1").id,
|
||||
'partner_id': self.res_partner_1.id,
|
||||
'stage_id': default_stage_id,
|
||||
'description': 'This is the description of the test lead first.'
|
||||
})
|
||||
@@ -98,7 +98,7 @@ class TestCRMLead(TestCrmCases):
|
||||
test_crm_lead_02 = LeadSalesmanager.create({
|
||||
'type': 'lead',
|
||||
'name': 'Test lead second',
|
||||
'partner_id': self.env.ref("base.res_partner_1").id,
|
||||
'partner_id': self.res_partner_1.id,
|
||||
'stage_id': default_stage_id,
|
||||
'description': 'This is the description of the test lead second.'
|
||||
})
|
||||
@@ -111,7 +111,7 @@ class TestCRMLead(TestCrmCases):
|
||||
merge_opp_wizard_01.action_merge()
|
||||
|
||||
# I check for the resulting merged opp (based on name and partner)
|
||||
merged_lead = self.env['crm.lead'].search([('name', '=', 'Test opportunity 1'), ('partner_id', '=', self.env.ref("base.res_partner_3").id)], limit=1)
|
||||
merged_lead = self.env['crm.lead'].search([('name', '=', 'Test opportunity 1'), ('partner_id', '=', self.res_partner_3.id)], limit=1)
|
||||
self.assertTrue(merged_lead, 'Fail to create merge opportunity wizard')
|
||||
self.assertEqual(merged_lead.description, 'This is the description of the test opp 1.\n\nThis is the description of the test lead first.\n\nThis is the description of the test lead second.', 'Description mismatch: when merging leads/opps with different text values, these values should get concatenated and separated with line returns')
|
||||
self.assertEqual(merged_lead.type, 'opportunity', 'Type mismatch: when at least one opp in involved in the merge, the result should be a new opp (instead of %s)' % merged_lead.type)
|
||||
@@ -125,14 +125,14 @@ class TestCRMLead(TestCrmCases):
|
||||
test_crm_lead_03 = LeadSalesmanager.create({
|
||||
'type': 'lead',
|
||||
'name': 'Test lead 3',
|
||||
'partner_id': self.env.ref("base.res_partner_1").id,
|
||||
'partner_id': self.res_partner_1.id,
|
||||
'stage_id': default_stage_id
|
||||
})
|
||||
|
||||
test_crm_lead_04 = LeadSalesmanager.create({
|
||||
'type': 'lead',
|
||||
'name': 'Test lead 4',
|
||||
'partner_id': self.env.ref("base.res_partner_1").id,
|
||||
'partner_id': self.res_partner_1.id,
|
||||
'stage_id': default_stage_id
|
||||
})
|
||||
|
||||
@@ -144,9 +144,9 @@ class TestCRMLead(TestCrmCases):
|
||||
merge_opp_wizard_02.action_merge()
|
||||
|
||||
# I check for the resulting merged lead (based on name and partner)
|
||||
merged_lead = self.env['crm.lead'].search([('name', '=', 'Test lead 3'), ('partner_id', '=', self.env.ref("base.res_partner_1").id)], limit=1)
|
||||
merged_lead = self.env['crm.lead'].search([('name', '=', 'Test lead 3'), ('partner_id', '=', self.res_partner_1.id)], limit=1)
|
||||
self.assertTrue(merged_lead, 'Fail to create merge opportunity wizard')
|
||||
self.assertEqual(merged_lead.partner_id.id, self.env.ref("base.res_partner_1").id, 'Partner mismatch')
|
||||
self.assertEqual(merged_lead.partner_id.id, self.res_partner_1.id, 'Partner mismatch')
|
||||
self.assertEqual(merged_lead.type, 'lead', 'Type mismatch: when leads get merged together, the result should be a new lead (instead of %s)' % merged_lead.type)
|
||||
self.assertFalse(test_crm_lead_04.exists(), 'This tailing lead (id %s) should not exist anymore' % test_crm_lead_04.id)
|
||||
|
||||
@@ -155,14 +155,14 @@ class TestCRMLead(TestCrmCases):
|
||||
test_crm_opp_02 = LeadSalesmanager.create({
|
||||
'type': 'opportunity',
|
||||
'name': 'Test opportunity 2',
|
||||
'partner_id': self.env.ref("base.res_partner_3").id,
|
||||
'partner_id': self.res_partner_3.id,
|
||||
'stage_id': default_stage_id
|
||||
})
|
||||
|
||||
test_crm_opp_03 = LeadSalesmanager.create({
|
||||
'type': 'opportunity',
|
||||
'name': 'Test opportunity 3',
|
||||
'partner_id': self.env.ref("base.res_partner_3").id,
|
||||
'partner_id': self.res_partner_3.id,
|
||||
'stage_id': default_stage_id
|
||||
})
|
||||
|
||||
@@ -173,9 +173,9 @@ class TestCRMLead(TestCrmCases):
|
||||
merge_opp_wizard_03 = self.env['crm.merge.opportunity'].with_user(self.crm_salemanager).with_context(**additionnal_context).create({})
|
||||
merge_opp_wizard_03.action_merge()
|
||||
|
||||
merged_opportunity = self.env['crm.lead'].search([('name', '=', 'Test opportunity 2'), ('partner_id', '=', self.env.ref("base.res_partner_3").id)], limit=1)
|
||||
merged_opportunity = self.env['crm.lead'].search([('name', '=', 'Test opportunity 2'), ('partner_id', '=', self.res_partner_3.id)], limit=1)
|
||||
self.assertTrue(merged_opportunity, 'Fail to create merge opportunity wizard')
|
||||
self.assertEqual(merged_opportunity.partner_id.id, self.env.ref("base.res_partner_3").id, 'Partner mismatch')
|
||||
self.assertEqual(merged_opportunity.partner_id.id, self.res_partner_3.id, 'Partner mismatch')
|
||||
self.assertEqual(merged_opportunity.type, 'opportunity', 'Type mismatch: when opps get merged together, the result should be a new opp (instead of %s)' % merged_opportunity.type)
|
||||
self.assertFalse(test_crm_opp_03.exists(), 'This tailing opp (id %s) should not exist anymore' % test_crm_opp_03.id)
|
||||
|
||||
@@ -192,7 +192,7 @@ class TestCRMLead(TestCrmCases):
|
||||
leads_to_create.append({
|
||||
'type': "lead",
|
||||
'name': "Test lead new " + str(x),
|
||||
'partner_id': self.env.ref("base.res_partner_1").id,
|
||||
'partner_id': self.res_partner_1.id,
|
||||
'description': "This is the description of the test new lead.",
|
||||
'team_id': self.env.ref("sales_team.team_sales_department").id,
|
||||
'stage_id': self.env.ref("crm.stage_lead%s" % (str(i + 1))).id,
|
||||
|
||||
@@ -7,4 +7,4 @@ import odoo.tests
|
||||
class TestUi(odoo.tests.HttpCase):
|
||||
|
||||
def test_01_crm_tour(self):
|
||||
self.start_tour("/web", 'crm_tour', login="admin")
|
||||
self.start_tour("/web", 'crm_tour', login="admin", step_delay=60)
|
||||
|
||||
@@ -8,12 +8,21 @@ class TestLead2opportunity2win(TestCrmCases):
|
||||
def test_lead2opportunity2win(self):
|
||||
""" Tests for Test Lead 2 opportunity 2 win """
|
||||
CrmLead2OpportunityPartnerMass = self.env['crm.lead2opportunity.partner.mass']
|
||||
CalendarAttendee = self.env['calendar.attendee']
|
||||
default_stage_id = self.ref("crm.stage_lead1")
|
||||
|
||||
crm_case_2 = self.env.ref('crm.crm_case_2')
|
||||
crm_case_3 = self.env.ref('crm.crm_case_3')
|
||||
crm_case_13 = self.env.ref('crm.crm_case_13')
|
||||
crm_case_2 = self.env['crm.lead'].create({
|
||||
'name': 'Design Software',
|
||||
'type': 'lead',
|
||||
})
|
||||
crm_case_3 = self.env['crm.lead'].create({
|
||||
'name': 'Pricing for 25 desks',
|
||||
'type': 'lead',
|
||||
})
|
||||
crm_case_13 = self.env['crm.lead'].create({
|
||||
'name': 'Quote for 600 Chairs',
|
||||
'type': 'opportunity',
|
||||
'contact_name': 'Will McEncroe',
|
||||
})
|
||||
|
||||
# In order to test the conversion of a lead into a opportunity,
|
||||
# I set lead to open stage.
|
||||
@@ -24,11 +33,11 @@ class TestLead2opportunity2win(TestCrmCases):
|
||||
|
||||
# Giving access rights of salesman to convert the lead into opportunity.
|
||||
# I convert lead into opportunity for exiting customer.
|
||||
crm_case_3.with_user(self.crm_salemanager).convert_opportunity(self.env.ref("base.res_partner_2").id)
|
||||
crm_case_3.with_user(self.crm_salemanager).convert_opportunity(self.res_partner_2.id)
|
||||
|
||||
# I check details of converted opportunity.
|
||||
self.assertEqual(crm_case_3.type, 'opportunity', 'Lead is not converted to opportunity!')
|
||||
self.assertEqual(crm_case_3.partner_id.id, self.env.ref("base.res_partner_2").id, 'Partner mismatch!')
|
||||
self.assertEqual(crm_case_3.partner_id.id, self.res_partner_2.id, 'Partner mismatch!')
|
||||
self.assertEqual(crm_case_3.stage_id.id, default_stage_id, 'Stage of opportunity is incorrect!')
|
||||
|
||||
# Now I schedule meeting with customer.
|
||||
@@ -45,7 +54,7 @@ class TestLead2opportunity2win(TestCrmCases):
|
||||
mass.with_user(self.crm_salemanager).mass_convert()
|
||||
|
||||
# Now I check first lead converted on opportunity.
|
||||
self.assertEqual(crm_case_13.name, "Quote for 12 Tables", "Opportunity name not correct")
|
||||
self.assertEqual(crm_case_13.name, "Quote for 600 Chairs", "Opportunity name not correct")
|
||||
self.assertEqual(crm_case_13.type, 'opportunity', "Lead is not converted to opportunity!")
|
||||
expected_partner = "Will McEncroe"
|
||||
self.assertEqual(crm_case_13.partner_id.name, expected_partner, "Partner mismatch! %s vs %s" % (crm_case_13.partner_id.name, expected_partner))
|
||||
@@ -62,12 +71,6 @@ class TestLead2opportunity2win(TestCrmCases):
|
||||
# I check details of the opportunity after the loose
|
||||
self.assertEqual(crm_case_2.probability, 0.0, "Revenue probability should be 0.0!")
|
||||
|
||||
# I confirm review needs meeting.
|
||||
self.env.ref('calendar.calendar_event_4').with_context({'active_model': 'calendar.event'}).write({'state': 'open'})
|
||||
|
||||
# I invite a user for meeting.
|
||||
CalendarAttendee.create({'partner_id': self.ref('base.partner_root'), 'email': 'user@meeting.com'}).do_accept()
|
||||
|
||||
def test_lead2opportunity_assign_salesmen(self):
|
||||
""" Tests for Test Lead2opportunity Assign Salesmen """
|
||||
CrmLead2OpportunityPartnerMass = self.env['crm.lead2opportunity.partner.mass']
|
||||
|
||||
Reference in New Issue
Block a user