[ADD] test_event_full: new module for testing all event capabilities
PURPOSE Introduce an automated tool to create leads from event registrations. Events are a powerful source of leads as they attract attention. This leads to leads with good quality as they mark interest while gathering contact information which allows to follow-up. This merge aims at automating this process by automatically creating leads based on user-defined rules. SPECIFICATIONS Add a module allowing to test a complete event install: add all event dependencies. Currently only crm rules are tested as part of the lead generation tasks. Future commits will add notably tours using all features of event. LINKS Task ID 2166679 PR #52334 Upgrade PR odoo/upgrade#1292
This commit is contained in:
@@ -0,0 +1,4 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from . import tests
|
||||
@@ -0,0 +1,25 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
{
|
||||
'name': 'Test Full Event Flow',
|
||||
'version': '1.0',
|
||||
'category': 'Hidden/Tests',
|
||||
'description': """
|
||||
This module will test the main event flows of Odoo, both frontend and backend.
|
||||
It installs sale capabilities, front-end flow, eCommerce, questions and
|
||||
automatic lead generation..
|
||||
""",
|
||||
'depends': [
|
||||
'event',
|
||||
'event_crm',
|
||||
'event_sale',
|
||||
'website_event_crm_questions',
|
||||
'website_event_questions',
|
||||
'website_event_sale',
|
||||
'website_event_track',
|
||||
],
|
||||
'demo': [],
|
||||
'data': [],
|
||||
'installable': True,
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from . import common
|
||||
from . import test_event_crm
|
||||
@@ -0,0 +1,102 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo.addons.event_crm.tests.common import TestEventCrmCommon
|
||||
|
||||
|
||||
class TestEventFullCommon(TestEventCrmCommon):
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
super(TestEventFullCommon, cls).setUpClass()
|
||||
|
||||
cls.event_product = cls.env['product.product'].create({
|
||||
'name': 'Test Registration Product',
|
||||
'description_sale': 'Mighty Description',
|
||||
'list_price': 10,
|
||||
'event_ok': True,
|
||||
'standard_price': 30.0,
|
||||
'type': 'service',
|
||||
})
|
||||
|
||||
cls.event_0.write({
|
||||
'event_ticket_ids': [
|
||||
(5, 0),
|
||||
(0, 0, {
|
||||
'name': 'First Ticket',
|
||||
'product_id': cls.event_product.id,
|
||||
'seats_max': 30,
|
||||
}), (0, 0, {
|
||||
'name': 'Second Ticket',
|
||||
'product_id': cls.event_product.id,
|
||||
})
|
||||
],
|
||||
})
|
||||
|
||||
cls.event_question_1 = cls.env['event.question'].create({
|
||||
'title': 'Question1',
|
||||
'question_type': 'simple_choice',
|
||||
'event_id': cls.event_0.id,
|
||||
'once_per_order': False,
|
||||
'answer_ids': [
|
||||
(0, 0, {'name': 'Q1-Answer1'}),
|
||||
(0, 0, {'name': 'Q1-Answer2'})
|
||||
],
|
||||
})
|
||||
cls.event_question_2 = cls.env['event.question'].create({
|
||||
'title': 'Question2',
|
||||
'question_type': 'simple_choice',
|
||||
'event_id': cls.event_0.id,
|
||||
'once_per_order': True,
|
||||
'answer_ids': [
|
||||
(0, 0, {'name': 'Q2-Answer1'}),
|
||||
(0, 0, {'name': 'Q2-Answer2'})
|
||||
],
|
||||
})
|
||||
cls.event_question_3 = cls.env['event.question'].create({
|
||||
'title': 'Question3',
|
||||
'question_type': 'text_box',
|
||||
'event_id': cls.event_0.id,
|
||||
'once_per_order': True,
|
||||
})
|
||||
|
||||
# make a SO for a customer, selling some tickets
|
||||
cls.customer_so = cls.env['sale.order'].with_user(cls.user_sales_salesman).create({
|
||||
'partner_id': cls.event_customer.id,
|
||||
})
|
||||
|
||||
cls.website_customer_data = [{
|
||||
'name': 'My Customer %02d' % x,
|
||||
'partner_id': cls.env.ref('base.public_partner').id,
|
||||
'email': 'email.%02d@test.example.com' % x,
|
||||
'phone': '04560000%02d' % x,
|
||||
'registration_answer_ids': [
|
||||
(0, 0, {
|
||||
'question_id': cls.event_question_1.id,
|
||||
'value_answer_id': cls.event_question_1.answer_ids[(x % 2)].id,
|
||||
}), (0, 0, {
|
||||
'question_id': cls.event_question_2.id,
|
||||
'value_answer_id': cls.event_question_2.answer_ids[(x % 2)].id,
|
||||
}), (0, 0, {
|
||||
'question_id': cls.event_question_3.id,
|
||||
'value_text_box': 'CustomerAnswer%s' % x,
|
||||
})
|
||||
],
|
||||
} for x in range(0, 4)]
|
||||
|
||||
def assertLeadConvertion(self, rule, registrations, partner=None, **expected):
|
||||
super(TestEventFullCommon, self).assertLeadConvertion(rule, registrations, partner=partner, **expected)
|
||||
lead = self.env['crm.lead'].sudo().search([
|
||||
('registration_ids', 'in', registrations.ids),
|
||||
('event_lead_rule_id', '=', rule.id)
|
||||
])
|
||||
|
||||
for registration in registrations:
|
||||
if not registration.registration_answer_ids:
|
||||
continue
|
||||
for answer in registration.registration_answer_ids:
|
||||
self.assertIn(answer.question_id.title, lead.description)
|
||||
if answer.question_type == 'simple_choice':
|
||||
self.assertIn(answer.value_answer_id.name, lead.description)
|
||||
else:
|
||||
self.assertIn(answer.value_text_box, lead.description) # better: check multi line
|
||||
@@ -0,0 +1,149 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo.addons.test_event_full.tests.common import TestEventFullCommon
|
||||
from odoo.tests import users
|
||||
|
||||
|
||||
class TestEventCrm(TestEventFullCommon):
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
super(TestEventCrm, cls).setUpClass()
|
||||
|
||||
cls.TICKET1_COUNT, cls.TICKET2_COUNT = 3, 1
|
||||
ticket1 = cls.event_0.event_ticket_ids[0]
|
||||
ticket2 = cls.event_0.event_ticket_ids[1]
|
||||
|
||||
# PREPARE SO DATA
|
||||
# ------------------------------------------------------------
|
||||
|
||||
# adding some tickets to SO
|
||||
cls.customer_so.write({
|
||||
'order_line': [
|
||||
(0, 0, {
|
||||
'event_id': cls.event_0.id,
|
||||
'event_ticket_id': ticket1.id,
|
||||
'product_id': ticket1.product_id.id,
|
||||
'product_uom_qty': cls.TICKET1_COUNT,
|
||||
}), (0, 0, {
|
||||
'event_id': cls.event_0.id,
|
||||
'event_ticket_id': ticket2.id,
|
||||
'product_id': ticket2.product_id.id,
|
||||
'product_uom_qty': cls.TICKET2_COUNT,
|
||||
'price_unit': 50,
|
||||
})
|
||||
]
|
||||
})
|
||||
|
||||
@users('user_sales_salesman')
|
||||
def test_event_crm_sale_customer(self):
|
||||
""" Test a SO with a real customer set on it, check partner propagation
|
||||
as well as group-based lead update. """
|
||||
customer_so = self.env['sale.order'].browse(self.customer_so.id)
|
||||
|
||||
# adding some tickets to SO
|
||||
t1_reg_vals = [
|
||||
dict(customer_data,
|
||||
partner_id=customer_so.partner_id.id,
|
||||
sale_order_line_id=customer_so.order_line[0].id)
|
||||
for customer_data in self.website_customer_data[:self.TICKET1_COUNT]
|
||||
]
|
||||
t1_registrations = self.env['event.registration'].create(t1_reg_vals)
|
||||
|
||||
# check effect: registrations, leads
|
||||
self.assertEqual(self.event_0.registration_ids, t1_registrations)
|
||||
self.assertEqual(len(self.test_rule_order.lead_ids), 1)
|
||||
self.assertEqual(self.test_rule_order_done.lead_ids, self.env['crm.lead'])
|
||||
# check lead converted based on registrations
|
||||
self.assertLeadConvertion(self.test_rule_order, t1_registrations, partner=customer_so.partner_id)
|
||||
|
||||
# SO is confirmed -> missing registrations should be automatically added
|
||||
# and added to the lead as part of the same group
|
||||
customer_so.action_confirm()
|
||||
self.assertEqual(customer_so.state, 'sale')
|
||||
self.assertEqual(len(self.event_0.registration_ids), self.TICKET1_COUNT + self.TICKET2_COUNT)
|
||||
self.assertEqual(len(self.test_rule_order.lead_ids), 1) # no new lead created
|
||||
self.assertEqual(self.test_rule_order_done.lead_ids, self.env['crm.lead']) # this one still not triggered
|
||||
|
||||
# check existing lead has been updated with new registrations
|
||||
self.assertLeadConvertion(self.test_rule_order, self.event_0.registration_ids, partner=customer_so.partner_id)
|
||||
|
||||
# Confirm registrations -> trigger the "DONE" rule, one new lead linked to all
|
||||
# event registrations created in this test as all belong to the same SO
|
||||
self.event_0.registration_ids.write({'state': 'done'})
|
||||
self.assertLeadConvertion(self.test_rule_order_done, self.event_0.registration_ids, partner=customer_so.partner_id)
|
||||
|
||||
@users('user_sales_salesman')
|
||||
def test_event_crm_sale_mixed_group(self):
|
||||
""" Test a mixed sale order line creation. This should not happen in a customer
|
||||
use case but should be supported by the code. """
|
||||
public_partner = self.env.ref('base.public_partner')
|
||||
public_so = self.env['sale.order'].create({
|
||||
'partner_id': public_partner.id,
|
||||
'order_line': [
|
||||
(0, 0, {
|
||||
'event_id': self.event_0.id,
|
||||
'event_ticket_id': self.event_0.event_ticket_ids[0].id,
|
||||
'product_id': self.event_0.event_ticket_ids[0].product_id.id,
|
||||
'product_uom_qty': 2,
|
||||
})
|
||||
]
|
||||
})
|
||||
customer_so = self.env['sale.order'].browse(self.customer_so.id)
|
||||
|
||||
# make a multi-SO create
|
||||
mixed_reg_vals = [
|
||||
dict(self.website_customer_data[0],
|
||||
partner_id=customer_so.partner_id.id,
|
||||
sale_order_line_id=customer_so.order_line[0].id),
|
||||
dict(self.website_customer_data[1],
|
||||
partner_id=customer_so.partner_id.id,
|
||||
sale_order_line_id=customer_so.order_line[0].id),
|
||||
dict(self.website_customer_data[2],
|
||||
partner_id=public_so.partner_id.id,
|
||||
sale_order_line_id=public_so.order_line[0].id),
|
||||
dict(self.website_customer_data[3],
|
||||
partner_id=public_so.partner_id.id,
|
||||
sale_order_line_id=public_so.order_line[0].id),
|
||||
]
|
||||
self.env['event.registration'].create(mixed_reg_vals)
|
||||
|
||||
public_regs = self.event_0.registration_ids.filtered(lambda reg: reg.sale_order_id == public_so)
|
||||
self.assertEqual(len(public_regs), 2)
|
||||
customer_regs = self.event_0.registration_ids.filtered(lambda reg: reg.sale_order_id == customer_so)
|
||||
self.assertEqual(len(customer_regs), 2)
|
||||
self.assertLeadConvertion(self.test_rule_order, public_regs, partner=None)
|
||||
self.assertLeadConvertion(self.test_rule_order, customer_regs, partner=customer_so.partner_id)
|
||||
|
||||
@users('user_sales_salesman')
|
||||
def test_event_crm_sale_public(self):
|
||||
""" Test a SO with a public partner on it, then updated when SO is confirmed.
|
||||
This somehow simulates a simplified website_event_sale flow. """
|
||||
public_partner = self.env.ref('base.public_partner')
|
||||
customer_so = self.env['sale.order'].browse(self.customer_so.id)
|
||||
customer_so.write({'partner_id': public_partner.id})
|
||||
|
||||
# adding some tickets to SO
|
||||
t1_reg_vals = [
|
||||
dict(customer_data,
|
||||
partner_id=public_partner.id,
|
||||
sale_order_line_id=customer_so.order_line[0].id)
|
||||
for customer_data in self.website_customer_data[:self.TICKET1_COUNT]
|
||||
]
|
||||
t1_registrations = self.env['event.registration'].create(t1_reg_vals)
|
||||
self.assertEqual(self.event_0.registration_ids, t1_registrations)
|
||||
|
||||
# check lead converted based on registrations
|
||||
self.assertLeadConvertion(self.test_rule_order, t1_registrations, partner=None)
|
||||
|
||||
# SO is confirmed -> missing registrations should be automatically added
|
||||
# BUT as public user -> no email -> not taken into account by rule
|
||||
customer_so.action_confirm()
|
||||
self.assertEqual(customer_so.state, 'sale')
|
||||
self.assertEqual(len(self.event_0.registration_ids), self.TICKET1_COUNT + self.TICKET2_COUNT)
|
||||
self.assertLeadConvertion(self.test_rule_order, t1_registrations, partner=None)
|
||||
|
||||
# SO has a customer set -> main contact of lead is updated accordingly
|
||||
customer_so.write({'partner_id': self.event_customer.id})
|
||||
self.assertLeadConvertion(self.test_rule_order, t1_registrations, partner=self.event_customer)
|
||||
Reference in New Issue
Block a user