Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FIX] website(_crm): fix email and phone computation of visitor
Currently there are several limitations in visitor email and phone computation, notably phone of partner is not taken into account (only mobile) and computation does not work in website_crm if there are no leads. In this commit we * support both mobile and phone fields of partner. Indeed generally all SMS flows check for those two fields and not only for mobile; * replace the SQL by standard ORM computation. As those fields are not stored and displayed in list views ORM should be capable of managing them; * avoid crash when creating visitors through the UI (no ids -> don't go into raw SQL); * correctly keep partner-based values when no lead is linked to the visitor; Tests are also added in order to ensure behavior. Task ID 2196869 closes #48369 X-original-commit: 02ceb42 Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
- Loading branch information
1 parent
a2e5514
commit 52ac7f2
Showing
4 changed files
with
81 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
# -*- coding: utf-8 -*- | ||
# Part of Odoo. See LICENSE file for full copyright and licensing details. | ||
|
||
from odoo.addons.crm.tests.common import TestCrmCommon | ||
from odoo.tests.common import users | ||
|
||
|
||
class TestWebsiteVisitor(TestCrmCommon): | ||
|
||
def setUp(self): | ||
super(TestWebsiteVisitor, self).setUp() | ||
self.test_partner = self.env['res.partner'].create({ | ||
'name': 'Test Customer', | ||
'email': '"Test Customer" <test@test.example.com>', | ||
'country_id': self.env.ref('base.be').id, | ||
'mobile': '+32456001122' | ||
}) | ||
|
||
@users('user_sales_manager') | ||
def test_compute_email_phone(self): | ||
visitor_sudo = self.env['website.visitor'].sudo().create({ | ||
'name': 'Mega Visitor', | ||
}) | ||
visitor = visitor_sudo.with_user(self.env.user) # as of 13.0 salesmen cannot create visitors, only read them | ||
customer = self.test_partner.with_user(self.env.user) | ||
self.assertFalse(visitor.email) | ||
self.assertFalse(visitor.mobile) | ||
|
||
# partner information copied on visitor -> behaves like related | ||
visitor_sudo.write({'partner_id': self.test_partner.id}) | ||
self.assertEqual(visitor.email, customer.email_normalized) | ||
self.assertEqual(visitor.mobile, customer.mobile) | ||
|
||
# if reset -> behaves like a related, also reset on visitor | ||
visitor_sudo.write({'partner_id': False}) | ||
self.assertFalse(visitor.email) | ||
self.assertFalse(visitor.mobile) | ||
|
||
# first lead created -> updates email | ||
lead_1 = self.env['crm.lead'].create({ | ||
'name': 'Test Lead 1', | ||
'email_from': 'Rambeau Fort <beaufort@test.example.com', | ||
'visitor_ids': [(4, visitor.id)], | ||
}) | ||
self.assertEqual(visitor.email, lead_1.email_normalized) | ||
self.assertFalse(visitor.mobile) | ||
|
||
# second lead created -> keep first email but takes mobile as not defined before | ||
lead_2 = self.env['crm.lead'].create({ | ||
'name': 'Test Lead 1', | ||
'email_from': 'Martino Brie <brie@test.example.com', | ||
'country_id': self.env.ref('base.be').id, | ||
'mobile': '+32456001122', | ||
'visitor_ids': [(4, visitor.id)], | ||
}) | ||
self.assertEqual(visitor.email, lead_1.email_normalized) | ||
self.assertEqual(visitor.mobile, lead_2.mobile) | ||
|
||
# partner win on leads | ||
visitor_sudo.write({'partner_id': self.test_partner.id}) | ||
self.assertEqual(visitor.email, customer.email_normalized) | ||
self.assertEqual(visitor.mobile, customer.mobile) | ||
|
||
# partner updated -> fallback on leads | ||
customer.write({'mobile': False}) | ||
self.assertEqual(visitor.email, customer.email_normalized) | ||
self.assertEqual(visitor.mobile, lead_2.mobile) |