19.0 vanilla

This commit is contained in:
Ernad Husremovic 2026-03-09 09:30:53 +01:00
parent dc68f80d3f
commit 7221b9ac46
610 changed files with 135477 additions and 161677 deletions

View file

@ -1,11 +1,9 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from itertools import product
from odoo import SUPERUSER_ID
from odoo.addons.crm.tests import common as crm_common
from odoo.fields import Datetime
from odoo.tests.common import tagged, users
from odoo.tests.common import Form
from odoo.tests import Form, tagged, users
@tagged('lead_manage')
class TestLeadConvertForm(crm_common.TestLeadConvertCommon):
@ -59,13 +57,13 @@ class TestLeadConvertForm(crm_common.TestLeadConvertCommon):
@tagged('lead_manage')
class TestLeadConvert(crm_common.TestLeadConvertCommon):
"""
TODO: created partner (handle assignation) has team of lead
TODO: created partner (handle assignment) has team of lead
TODO: create partner has user_id coming from wizard
"""
@classmethod
def setUpClass(cls):
super(TestLeadConvert, cls).setUpClass()
super().setUpClass()
date = Datetime.from_string('2020-01-20 16:00:00')
cls.crm_lead_dt_mock.now.return_value = date
@ -80,6 +78,11 @@ class TestLeadConvert(crm_common.TestLeadConvertCommon):
'email_from': test_lead.email_from,
'probability': 0, 'active': False,
},
{'name': 'Duplicate lead: same email_from, archived (not lost)',
'type': 'lead',
'email_from': test_lead.email_from,
'probability': 50, 'active': False,
},
{'name': 'Duplicate lead: same email_from, proba 0 but not lost',
'type': 'lead',
'email_from': test_lead.email_from,
@ -94,37 +97,50 @@ class TestLeadConvert(crm_common.TestLeadConvertCommon):
'type': 'opportunity',
'email_from': test_lead.email_from,
'probability': 100, 'stage_id': self.stage_team1_2.id,
},
{'name': 'Duplicate opp: same email_from, archived (not lost)',
'type': 'opportunity',
'email_from': test_lead.email_from,
'probability': 50, 'stage_id': self.stage_team1_2.id,
'active': False,
}
])
lead_lost = dup_leads.filtered(lambda lead: lead.name == 'Duplicate lead: same email_from, lost')
_opp_proba100 = dup_leads.filtered(lambda lead: lead.name == 'Duplicate opp: same email_from, proba 100 but not won')
opp_won = dup_leads.filtered(lambda lead: lead.name == 'Duplicate opp: same email_from, won')
opp_lost = dup_leads.filtered(lambda lead: lead.name == 'Duplicate: lost opportunity')
self.assertEqual(len(dup_leads), 10, 'Be sure below quick access are relevant')
opp_lost = dup_leads[3]
lead_lost = dup_leads[4]
lead_archived = dup_leads[5]
opp_won = dup_leads[7]
_opp_proba100 = dup_leads[8]
opp_archived = dup_leads[9]
test_lead.write({'partner_id': customer.id})
# not include_lost = remove archived leads as well as 'won' opportunities
# not include_lost = remove archived leads/opps, lost leads/opps as well
# as 'won' opportunities
result = test_lead._get_lead_duplicates(
partner=test_lead.partner_id,
email=test_lead.email_from,
include_lost=False
)
self.assertEqual(result, test_lead + dup_leads - (lead_lost + opp_won + opp_lost))
self.assertEqual(
result,
test_lead + dup_leads - (lead_lost + lead_archived + opp_won + opp_archived + opp_lost),
'Should not include: lost lead or opp, archived lead / opp (aka: only active lead/opp not won nor lost)'
)
# include_lost = remove archived opp only
# include_lost = remove archived lead only (archived opp is ok)
result = test_lead._get_lead_duplicates(
partner=test_lead.partner_id,
email=test_lead.email_from,
include_lost=True
include_lost=True,
)
self.assertEqual(result, test_lead + dup_leads - (lead_lost))
self.assertEqual(result, test_lead + dup_leads - (lead_lost + lead_archived + opp_won))
def test_initial_data(self):
""" Ensure initial data to avoid spaghetti test update afterwards """
self.assertFalse(self.lead_1.date_conversion)
self.assertEqual(self.lead_1.date_open, Datetime.from_string('2020-01-15 11:30:00'))
self.assertEqual(self.lead_1.lang_id, self.lang_fr)
self.assertFalse(self.lead_1.mobile)
self.assertEqual(self.lead_1.phone, '+1 202 555 9999')
self.assertEqual(self.lead_1.user_id, self.user_sales_leads)
self.assertEqual(self.lead_1.team_id, self.sales_team_1)
@ -149,7 +165,6 @@ class TestLeadConvert(crm_common.TestLeadConvertCommon):
self.assertEqual(lead.partner_id, self.contact_2)
self.assertEqual(lead.email_from, self.contact_2.email)
self.assertEqual(lead.lang_id, self.lang_en)
self.assertEqual(lead.mobile, self.contact_2.mobile)
self.assertEqual(lead.phone, '123456789')
self.assertEqual(lead.team_id, self.sales_team_1)
self.assertEqual(lead.stage_id, self.stage_team1_1)
@ -317,24 +332,6 @@ class TestLeadConvert(crm_common.TestLeadConvertCommon):
self.assertEqual(self.lead_1.type, 'opportunity')
self.assertEqual(self.lead_1.partner_id, self.contact_1)
@users('user_sales_manager')
def test_lead_convert_action_nothing(self):
""" Test specific use case of 'nothing' action in conver wizard """
self.lead_1.write({'contact_name': False})
convert = self.env['crm.lead2opportunity.partner'].with_context({
'active_model': 'crm.lead',
'active_id': self.lead_1.id,
'active_ids': self.lead_1.ids,
}).create({})
self.assertEqual(convert.action, 'nothing')
convert.action_apply()
self.assertEqual(self.lead_1.type, 'opportunity')
self.assertEqual(self.lead_1.user_id, self.user_sales_leads)
self.assertEqual(self.lead_1.team_id, self.sales_team_1)
self.assertEqual(self.lead_1.stage_id, self.stage_team1_1)
self.assertEqual(self.lead_1.partner_id, self.env['res.partner'])
@users('user_sales_manager')
def test_lead_convert_contact_mutlicompany(self):
""" Check the wizard convert to opp don't find contact
@ -396,19 +393,11 @@ class TestLeadConvert(crm_common.TestLeadConvertCommon):
}]
self.lead_1.convert_opportunity(False)
self.assertEqual(self.lead_1.team_id, initial_team)
self.assertEqual(self.lead_1.lead_properties, [{
'name': 'test',
'type': 'char',
'value': 'test value',
}])
self.assertEqual(self.lead_1.lead_properties, {'test': 'test value'})
# re-writing the team, but keeping the same value should not reset the properties
self.lead_1.write({'team_id': self.lead_1.team_id.id})
self.assertEqual(self.lead_1.lead_properties, [{
'name': 'test',
'type': 'char',
'value': 'test value',
}])
self.assertEqual(self.lead_1.lead_properties, {'test': 'test value'})
@users('user_sales_manager')
def test_lead_convert_properties_reset(self):
@ -424,6 +413,58 @@ class TestLeadConvert(crm_common.TestLeadConvertCommon):
self.assertNotEqual(self.lead_1.team_id, initial_team)
self.assertFalse(self.lead_1.lead_properties)
@users('user_sales_manager')
def test_lead_convert_wizard_new_partner(self):
no_partner = self.env['res.partner']
test_partner_lead, test_partner_wizard, commercial_partner = self.env['res.partner'].create([
{'name': 'Lead Test Partner'},
{'name': 'Wizard Test Partner'},
{'name': 'Company Partner', 'is_company': True},
])
case_values = product(
[no_partner, test_partner_lead],
[False, 'New Company'],
[no_partner, commercial_partner],
[no_partner, test_partner_wizard],
['create', 'exist'],
)
for (lead_partner, lead_company_name, wizard_company, wizard_contact, wizard_action) in case_values:
(test_partner_lead + test_partner_wizard).parent_id = False
commercial_partner.invalidate_recordset()
lead_contact_name = lead_partner.name or 'Test Contact Name'
lead = self.env['crm.lead'].create({
'name': 'Test Lead',
'contact_name': lead_contact_name,
'partner_id': lead_partner.id,
'partner_name': lead_company_name,
})
wizard = self.env['crm.lead2opportunity.partner'].with_context({
'active_model': 'crm.lead',
'active_id': lead.id,
'active_ids': lead.ids,
}).create({})
wizard.write({'action': wizard_action, 'name': 'convert'})
if wizard_contact:
wizard.partner_id = wizard_contact
if wizard_company:
wizard.commercial_partner_id = wizard_company
with self.subTest(
lead_company_name=lead_company_name, lead_partner=lead_partner.name,
wizard_company=wizard_company.name, wizard_contact=wizard_contact.name, wizard_action=wizard_action
):
wizard.action_apply()
self.assertEqual(lead.type, 'opportunity')
self.assertEqual(bool(lead.partner_id), bool(wizard_action == 'create' or lead_partner or wizard_contact))
if wizard_action == 'exist' and (lead_partner or wizard_contact):
self.assertEqual(lead.partner_id, wizard_contact or lead_partner)
if wizard_action == 'create' and not lead_partner and not wizard_contact and wizard_company:
self.assertTrue(lead.partner_id)
self.assertEqual(lead.partner_id.name, lead_contact_name)
self.assertEqual(lead.partner_id.parent_id, wizard_company)
if wizard_action == 'create' and (wizard_contact or lead_partner):
self.assertEqual(lead.partner_id, wizard_contact or lead_partner)
self.assertFalse(lead.partner_id.parent_id)
@users('user_sales_manager')
def test_lead_merge(self):
""" Test convert wizard working in merge mode """