PURPOSE
As CRM is going to be updated (onchange -> compute, code improvements, better
management of sales teams) cleaning and improving code is a necessary first
step.
SPECIFICATIONS
Purpose of this commit is to rewrite code located and/or used in convert or
merge wizards. Indeed it holds unnecessary variables, dictionaries manipulation
that hides the real business flow, badly named variables, unclear methods, ...
Logic of those wizards seem quite simple but is hidden behind a wall of
bloated code.
Notably for wizards
* try to set explicit arguments in methods;
* less use of context values, replaced by arguments when possible;
* try to make better use of lead2opportunity wizard in its mass wizard that
inherit from it, notably by correctly calling super;
Notably for tools
* ``get_duplicated_leads`` was just a shortcut to ``_get_duplicated_leads_by
_emails``;
* ``_get_duplicated_leads_by_emails`` is renamed to ``_get_lead_duplicates``
because email is not the only way of finding duplicates;
* try to make better use of record sets instead of propagating ids, notably
for partner. For example input of ``_get_lead_duplicates`` or output of
``_find_matching_partner``;
* ``_create_lead_partner`` rename to ``_create_customer``, and its sub
method ``_create_lead_partner_data`` to ``_prepare_customer_values``;
* ``handle_partner_assignation`` was difficult as its use is not documented
and its docstring was not updated. Parameter have been renamed to be more
explicit about what it does. Method is renamed to ``handle_partner_
assignment`` as assignation has other meaning in English;
* ``allocate_salesman`` is renamed to ``handle_salesmen_assignment`` to match
the partner assignement and code is slightly cleaned;
No functional change should occur with this commit. Tests have been gradually
added to try to ensure behavior does not change.
LINKS
Task ID 2088565 (crm: from onchange to compute)
84 lines
3.5 KiB
Python
84 lines
3.5 KiB
Python
# -*- coding: utf-8 -*-
|
|
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
|
|
|
from odoo.addons.crm.tests.common import TestCrmCommon, INCOMING_EMAIL
|
|
from odoo.tests.common import users
|
|
|
|
|
|
class TestCRMLead(TestCrmCommon):
|
|
|
|
@users('user_sales_manager')
|
|
def test_crm_lead_creation_partner(self):
|
|
lead = self.env['crm.lead'].create({
|
|
'name': 'TestLead',
|
|
'contact_name': 'Raoulette TestContact',
|
|
'email_from': '"Raoulette TestContact" <raoulette@test.example.com>',
|
|
})
|
|
self.assertEqual(lead.type, 'lead')
|
|
self.assertEqual(lead.user_id, self.user_sales_manager)
|
|
self.assertEqual(lead.team_id, self.sales_team_1)
|
|
self.assertEqual(lead.stage_id, self.stage_team1_1)
|
|
self.assertEqual(lead.contact_name, 'Raoulette TestContact')
|
|
self.assertEqual(lead.email_from, '"Raoulette TestContact" <raoulette@test.example.com>')
|
|
|
|
# update to a partner, should udpate address
|
|
lead.write({'partner_id': self.contact_1.id})
|
|
# self.assertEqual(lead.partner_name, self.contact_company_1.name)
|
|
# self.assertEqual(lead.contact_name, self.contact_1.name)
|
|
# self.assertEqual(lead.email_from, self.contact_1.email)
|
|
# self.assertEqual(lead.street, self.contact_1.street)
|
|
# self.assertEqual(lead.city, self.contact_1.city)
|
|
# self.assertEqual(lead.zip, self.contact_1.zip)
|
|
# self.assertEqual(lead.country_id, self.contact_1.country_id)
|
|
|
|
@users('user_sales_manager')
|
|
def test_crm_lead_stages(self):
|
|
lead = self.lead_1.with_user(self.env.user)
|
|
self.assertEqual(lead.team_id, self.sales_team_1)
|
|
|
|
lead.convert_opportunity(self.contact_1.id)
|
|
self.assertEqual(lead.team_id, self.sales_team_1)
|
|
|
|
lead.action_set_won()
|
|
self.assertEqual(lead.probability, 100.0)
|
|
self.assertEqual(lead.stage_id, self.stage_gen_won) # generic won stage has lower sequence than team won stage
|
|
|
|
@users('user_sales_manager')
|
|
def test_crm_team_alias(self):
|
|
new_team = self.env['crm.team'].create({
|
|
'name': 'TestAlias',
|
|
'use_leads': True,
|
|
'use_opportunities': True,
|
|
'alias_name': 'test.alias'
|
|
})
|
|
self.assertEqual(new_team.alias_id.alias_name, 'test.alias')
|
|
self.assertEqual(new_team.alias_name, 'test.alias')
|
|
|
|
new_team.write({
|
|
'use_leads': False,
|
|
'use_opportunities': False,
|
|
})
|
|
# self.assertFalse(new_team.alias_id.alias_name)
|
|
# self.assertFalse(new_team.alias_name)
|
|
|
|
def test_mailgateway(self):
|
|
new_lead = self.format_and_process(
|
|
INCOMING_EMAIL,
|
|
'unknown.sender@test.example.com',
|
|
'%s@%s' % (self.sales_team_1.alias_name, self.alias_domain),
|
|
subject='Delivery cost inquiry',
|
|
target_model='crm.lead',
|
|
)
|
|
self.assertEqual(new_lead.email_from, 'unknown.sender@test.example.com')
|
|
self.assertFalse(new_lead.partner_id)
|
|
self.assertEqual(new_lead.name, 'Delivery cost inquiry')
|
|
|
|
message = new_lead.with_user(self.user_sales_manager).message_post(
|
|
body='Here is my offer !',
|
|
subtype_xmlid='mail.mt_comment')
|
|
self.assertEqual(message.author_id, self.user_sales_manager.partner_id)
|
|
|
|
new_lead.handle_partner_assignment(create_missing=True)
|
|
self.assertEqual(new_lead.partner_id.email, 'unknown.sender@test.example.com')
|
|
self.assertEqual(new_lead.partner_id.team_id, self.sales_team_1)
|