[FIX] crm: missing company on default crm team on incoming emails

Commit 0edc854a84 introduces a company check on the salesperson, partner
& team on the lead model.

However 184334a97d1ccd19b9a7266a13ff51531d22cff4 was not able to find the expected company on a lead
created by email when the team did not have a company set. Which is the case by
default for the following crm.team:

  - Sales (3ad1867ea4)
  - Pre-Sales
  - Website (3ad1867ea4)
  - PoS

Having added the company check introduce an unexpected error:
  "Incompatible companies on records:\n-
  '[header subject of email]'
  belongs to company False and 'Customer'
  (partner_id: '[name in header from of email]')
  belongs to another company."

Error was hard to spot as the db logs are reporting that the routing of the
email was correctly done. But script to send eml using xmlrpc showed the error.

In this commit we fix the issue by removing the custom code trying to set
a company in ``message_new`` method of crm.lead. Indeed as it is a computed
field with a complete heuristic it is easier to let the ORM do its job and
remove that wrong value. It is now correctly computed as with any other
lead.

opw-2862509
opw-2783249
opw-2832435
opw-2881841

closes odoo/odoo#98746

X-original-commit: 2fec9c53314ef3f7c7e3305a6ee2417018d70ce5
Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
Co-authored-by: Xavier Alt <alt@odoo.com>
This commit is contained in:
bve-odoo
2022-08-24 09:29:27 +02:00
committed by Thibault Delavallée
co-authored by Xavier Alt
parent a2d5ddd165
commit 9d1cb826c7
2 changed files with 22 additions and 4 deletions
-3
View File
@@ -1889,9 +1889,6 @@ class Lead(models.Model):
defaults['priority'] = msg_dict.get('priority')
defaults.update(custom_values)
# assign right company
if 'company_id' not in defaults and 'team_id' in defaults:
defaults['company_id'] = self.env['crm.team'].browse(defaults['team_id']).company_id.id
return super(Lead, self).message_new(msg_dict, custom_values=defaults)
def _message_post_after_hook(self, message, msg_vals):
+22 -1
View File
@@ -1,7 +1,7 @@
# -*- 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.addons.crm.tests.common import TestCrmCommon, INCOMING_EMAIL
from odoo.exceptions import AccessError, UserError
from odoo.tests import Form, tagged
from odoo.tests.common import users
@@ -299,3 +299,24 @@ class TestCRMLeadMultiCompany(TestCrmCommon):
crm_lead_form.user_id = self.env['res.users']
# ensuring that company_id is not overwritten when the salesperson becomes empty (w\o any team_id)
self.assertEqual(crm_lead_form.company_id, self.company_2, 'Crm: company comes from partner')
def test_gateway_incompatible_company_error_on_incoming_email(self):
self.assertTrue(self.sales_team_1.alias_name)
self.assertFalse(self.sales_team_1.company_id)
customer_company = self.env['res.partner'].create({
'company_id': self.company_2.id,
'email': 'customer.another.company@test.customer.com',
'mobile': '+32455000000',
'name': 'InCompany Customer',
})
new_lead = self.format_and_process(
INCOMING_EMAIL,
customer_company.email,
'%s@%s' % (self.sales_team_1.alias_name, self.alias_domain),
subject='Team having partner in company',
target_model='crm.lead',
)
self.assertEqual(new_lead.company_id, self.company_2)
self.assertEqual(new_lead.email_from, customer_company.email)
self.assertEqual(new_lead.partner_id, customer_company)