summaryrefslogtreecommitdiff
path: root/addons/crm/tests
diff options
context:
space:
mode:
authorThibault Delavallée <tde@odoo.com>2020-01-14 13:30:18 +0000
committerThibault Delavallée <tde@odoo.com>2020-03-23 11:42:11 +0000
commitd8b6b35cb3c75b5c503b5b147fb8dd0e36e4ecfa (patch)
tree6d6333491f3755445be9af50b8f61730b47b3bc7 /addons/crm/tests
parent8b94dc17bfedf08ec497adf91e67bd8948d3bd79 (diff)
[REF] crm(_*): improve code of methods used in lead/opp convert/merge wizards
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)
Diffstat (limited to 'addons/crm/tests')
-rw-r--r--addons/crm/tests/test_crm_lead.py7
-rw-r--r--addons/crm/tests/test_crm_lead_convert.py16
2 files changed, 13 insertions, 10 deletions
diff --git a/addons/crm/tests/test_crm_lead.py b/addons/crm/tests/test_crm_lead.py
index d8c2e7d74f9..3ec5fde38f4 100644
--- a/addons/crm/tests/test_crm_lead.py
+++ b/addons/crm/tests/test_crm_lead.py
@@ -78,7 +78,6 @@ class TestCRMLead(TestCrmCommon):
subtype_xmlid='mail.mt_comment')
self.assertEqual(message.author_id, self.user_sales_manager.partner_id)
- new_partner_id = new_lead.handle_partner_assignation(action='create')[new_lead.id]
- new_partner = self.env['res.partner'].with_user(self.user_sales_manager).browse(new_partner_id)
- self.assertEqual(new_partner.email, 'unknown.sender@test.example.com')
- self.assertEqual(new_partner.team_id, self.sales_team_1)
+ 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)
diff --git a/addons/crm/tests/test_crm_lead_convert.py b/addons/crm/tests/test_crm_lead_convert.py
index e05bc8fb548..d12cb4e5ab2 100644
--- a/addons/crm/tests/test_crm_lead_convert.py
+++ b/addons/crm/tests/test_crm_lead_convert.py
@@ -8,6 +8,10 @@ from odoo.tests.common import tagged, users
@tagged('lead_manage')
class TestLeadConvert(crm_common.TestLeadConvertCommon):
+ """
+ TODO: created partner (handle assignation) has team of lead
+ TODO: create partner has user_id coming from wizard
+ """
@classmethod
def setUpClass(cls):
@@ -244,7 +248,7 @@ class TestLeadConvert(crm_common.TestLeadConvertCommon):
@users('user_sales_manager')
def test_lead_merge_duplicates(self):
- """ Test Lead._get_duplicated_leads_by_emails() """
+ """ Test Lead._get_lead_duplicates() """
# Check: partner / email fallbacks
self._create_duplicates(self.lead_1)
@@ -280,7 +284,7 @@ class TestLeadConvert(crm_common.TestLeadConvertCommon):
@users('user_sales_manager')
def test_lead_merge_duplicates_flow(self):
- """ Test Lead._get_duplicated_leads_by_emails() + merge with active_test """
+ """ Test Lead._get_lead_duplicates() + merge with active_test """
# Check: email formatting
self.lead_1.write({
@@ -431,7 +435,7 @@ class TestLeadConvertMass(crm_common.TestLeadConvertMassCommon):
self.assertEqual(mass_convert.user_id, self.user_sales_salesman)
self.assertEqual(mass_convert.team_id, self.sales_team_convert)
- mass_convert.mass_convert()
+ mass_convert.action_mass_convert()
for lead in self.lead_1 | self.lead_w_partner:
self.assertEqual(lead.type, 'opportunity')
if lead == self.lead_w_partner:
@@ -447,7 +451,7 @@ class TestLeadConvertMass(crm_common.TestLeadConvertMassCommon):
mass_convert.write({
'user_ids': self.user_sales_salesman.ids,
})
- mass_convert.mass_convert()
+ mass_convert.action_mass_convert()
self.assertEqual(self.lead_w_partner.user_id, self.user_sales_salesman)
self.assertEqual(self.lead_1.user_id, self.user_sales_leads) # existing value not forced
@@ -481,7 +485,7 @@ class TestLeadConvertMass(crm_common.TestLeadConvertMassCommon):
self.assertEqual(mass_convert.name, 'convert')
self.assertEqual(mass_convert.opportunity_ids, self.lead_1 | self.lead_w_partner)
- mass_convert.mass_convert()
+ mass_convert.action_mass_convert()
self.assertEqual(
(lead_1_dups | lead_w_partner_dups).exists(),
@@ -508,7 +512,7 @@ class TestLeadConvertMass(crm_common.TestLeadConvertMassCommon):
})
# TDE FIXME: what happens if we mix people from different sales team ? currently nothing, to check
- mass_convert.mass_convert()
+ mass_convert.action_mass_convert()
for idx, lead in enumerate(self.leads - self.lead_w_email_lost):
self.assertEqual(lead.type, 'opportunity')