[FIX] mail: set correct reply_to company

Steps to reproduce:
- select a different company from the main one
- under settings/discuss enable External Email Servers
- set up an alias domain
- create an SO and send it by email
(you can catch the sent email using mailhog)
- reply to that email
(you can use the support-tools[1] and set In-Reply-To: "previous message_id")

Bug:
the reply_to field of incoming message defaults to the first company

Fix:
set the reply_to field to the company asociated to the record
(there's already a fallback to self.env.company  in
"_notify_get_reply_to_formatted_email")

opw-3060214
[1]: https://github.com/odoo/support-tools/tree/master/scripts/mail

closes odoo/odoo#115090

X-original-commit: d86e57404d540762fa51afeabeddd3a0fc45d4d5
Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
Signed-off-by: Walid Hanniche (waha) <waha@odoo.com>
This commit is contained in:
Walid HANNICHE (waha)
2023-03-13 18:45:11 +01:00
parent 93e5a2bfaa
commit 27d4a74724
2 changed files with 25 additions and 3 deletions
+4 -1
View File
@@ -168,7 +168,10 @@ class BaseModel(models.AbstractModel):
if len(record_email) >= 78:
return record_email
company_name = self.env.company.name
if 'company_id' in self and len(self.company_id) == 1:
company_name = self.sudo().company_id.name
else:
company_name = self.env.company.name
# try company_name + record_name, or record_name alone (or company_name alone)
name = f"{company_name} {record_name}" if record_name else company_name
@@ -38,6 +38,7 @@ class TestMultiCompanySetup(TestMailCommon, TestRecipients):
'company_id': cls.user_employee_c2.company_id.id},
])
cls.company_3 = cls.env['res.company'].create({'name': 'ELIT'})
cls.partner_1 = cls.env['res.partner'].with_context(cls._test_context).create({
'name': 'Valid Lelitre',
'email': 'valid.lelitre@agrolait.com',
@@ -149,7 +150,8 @@ class TestMultiCompanySetup(TestMailCommon, TestRecipients):
@users('employee_c2')
def test_notify_reply_to_computation_mc(self):
""" Test reply-to computation in multi company mode. Add notably tests
depending on user company_id / company_ids. """
depending on user and records company_id / company_ids. """
# Test1: no company_id field
test_record = self.env['mail.test.gateway'].browse(self.test_record.ids)
res = test_record._notify_get_reply_to()
@@ -160,7 +162,7 @@ class TestMultiCompanySetup(TestMailCommon, TestRecipients):
"%s@%s" % (self.alias_catchall, self.alias_domain)))
)
# Test2: company_id field, MC environment
# Test2: MC environment get default value from env
self.user_employee_c2.write({'company_ids': [(4, self.user_employee.company_id.id)]})
test_records = self.env['mail.test.multi.company'].create([
{'name': 'Test',
@@ -177,6 +179,23 @@ class TestMultiCompanySetup(TestMailCommon, TestRecipients):
"%s@%s" % (self.alias_catchall, self.alias_domain)))
)
# Test3: get company from record (company_id field)
self.user_employee_c2.write({'company_ids': [(4, self.company_3.id)]})
test_records = self.env['mail.test.multi.company'].create([
{'name': 'Test1',
'company_id': self.company_3.id},
{'name': 'Test2',
'company_id': self.company_3.id},
])
res = test_records._notify_get_reply_to()
for test_record in test_records:
self.assertEqual(
res[test_record.id],
formataddr((
"%s %s" % (self.company_3.name, test_record.name),
"%s@%s" % (self.alias_catchall, self.alias_domain)))
)
@users('employee_c2')
@mute_logger('odoo.addons.base.models.ir_rule')
def test_post_with_read_access(self):