[FIX] mail: better support private recipient in full composer
Current behavior In the recruitment module, if you set an email template for the first step of a job recruitment process you cannot send any other email using the full composer. This happen because the partner type goes from 'contact' to 'private' and this type cannot be set as recipient in the full composer. Steps to reproduce - Go to any job recruitement and set an email template for the first step - Go on the website and apply for this job - Go back to the job application and send an email using the full composer, the email is not sent to the applicant. And the applicant is not added to the followers. Fix is to somehow improve support by adding asked partners from default in context. Note that this does not change anything from ACLs point of view, as trying to access private partners without the necessary group or ACLs will raise an access error anyway. Also note that private partners defined on a template are still stripped as they do not respect the new (nor the old) domain. That would be tricky to solve, better not use private partners in templates. opw-3010308 closes odoo/odoo#109451 X-original-commit: 12b25f21216b11511d5fed22fb3564d9dc297559 Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com> Part-of: odoo/odoo#109522 Co-authored-by: Robin Engels <roen@odoo.com>
This commit is contained in:
co-authored by
Robin Engels
parent
a45afdd830
commit
a2f9f26c85
@@ -126,9 +126,8 @@ class TestMailComposerForm(TestMailComposer):
|
||||
)
|
||||
saved_form = form.save()
|
||||
self.assertEqual(
|
||||
# saved_form.partner_ids, partner_private + partner_classic,
|
||||
saved_form.partner_ids, partner_classic,
|
||||
'Default value is kept at save (FIXME: loosing private partner)'
|
||||
saved_form.partner_ids, partner_private + partner_classic,
|
||||
'Default value is kept at save'
|
||||
)
|
||||
|
||||
with self.mock_mail_gateway():
|
||||
@@ -136,11 +135,7 @@ class TestMailComposerForm(TestMailComposer):
|
||||
|
||||
message = self.test_record.message_ids[0]
|
||||
self.assertEqual(message.body, '<p>Hello</p>')
|
||||
# self.assertEqual(message.partner_ids, partner_private + partner_classic)
|
||||
self.assertEqual(
|
||||
message.partner_ids, partner_classic,
|
||||
'FIXME: loosing private partner'
|
||||
)
|
||||
self.assertEqual(message.partner_ids, partner_private + partner_classic)
|
||||
self.assertEqual(message.subject, f'{test_record.name}')
|
||||
|
||||
@mute_logger('odoo.addons.base.models.ir_rule', 'odoo.addons.mail.models.mail_mail')
|
||||
|
||||
@@ -7,6 +7,7 @@ import re
|
||||
|
||||
from odoo import _, api, fields, models, tools, Command
|
||||
from odoo.exceptions import UserError
|
||||
from odoo.osv import expression
|
||||
from odoo.tools import email_re
|
||||
|
||||
|
||||
@@ -87,6 +88,12 @@ class MailComposer(models.TransientModel):
|
||||
filtered_result = dict((fname, result[fname]) for fname in result if fname in fields)
|
||||
return filtered_result
|
||||
|
||||
def _partner_ids_domain(self):
|
||||
return expression.OR([
|
||||
[('type', '!=', 'private')],
|
||||
[('id', 'in', self.env.context.get('default_partner_ids', []))],
|
||||
])
|
||||
|
||||
# content
|
||||
subject = fields.Char('Subject', compute=False)
|
||||
body = fields.Html(
|
||||
@@ -142,7 +149,7 @@ class MailComposer(models.TransientModel):
|
||||
partner_ids = fields.Many2many(
|
||||
'res.partner', 'mail_compose_message_res_partner_rel',
|
||||
'wizard_id', 'partner_id', 'Additional Contacts',
|
||||
domain=[('type', '!=', 'private')])
|
||||
domain=_partner_ids_domain)
|
||||
# sending
|
||||
auto_delete = fields.Boolean('Delete Emails',
|
||||
help='This option permanently removes any track of email after it\'s been sent, including from the Technical menu in the Settings, in order to preserve storage space of your Odoo database.')
|
||||
|
||||
Reference in New Issue
Block a user