[MERGE] base, mail, mass_mailing: allow data_merge deduplicate on models action menus
This merge is linked to the enterprise data_merge feature to allow to activate a 'Merge' button on the models contextual menu. - In order to be able to add a button to activate contextual merge action on the target model, the ir.model form view had to be adapted to add the header. - In mass_mailing model, a flag is added to avoid to activate the generic merge action on the model. - On order to allow to log a message (_message_log) using a xml template, a new method has been added to mail_thread model : _message_log_with_view. Task ID: 2459416 ENT PR: odoo/enterprise#17553 closes odoo/odoo#68960 Related: odoo/upgrade#2370 Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
This commit is contained in:
@@ -1887,12 +1887,12 @@ class MailThread(models.AbstractModel):
|
||||
# MESSAGE POST TOOLS
|
||||
# ------------------------------------------------------
|
||||
|
||||
def message_post_with_view(self, views_or_xmlid, **kwargs):
|
||||
""" Helper method to send a mail / post a message using a view_id to
|
||||
render using the ir.qweb engine. This method is stand alone, because
|
||||
there is nothing in template and composer that allows to handle
|
||||
views in batch. This method should probably disappear when templates
|
||||
handle ir ui views. """
|
||||
def _message_compose_with_view(self, views_or_xmlid, message_log=False, **kwargs):
|
||||
""" Helper method to send a mail / post a message / log a note using
|
||||
a view_id to render using the ir.qweb engine. This method is stand
|
||||
alone, because there is nothing in template and composer that allows
|
||||
to handle views in batch. This method should probably disappear when
|
||||
templates handle ir ui views. """
|
||||
values = kwargs.pop('values', None) or dict()
|
||||
try:
|
||||
from odoo.addons.http_routing.models.ir_http import slug
|
||||
@@ -1908,8 +1908,15 @@ class MailThread(models.AbstractModel):
|
||||
for record in self:
|
||||
values['object'] = record
|
||||
rendered_template = views._render(values, engine='ir.qweb', minimal_qcontext=True)
|
||||
kwargs['body'] = rendered_template
|
||||
record.message_post_with_template(False, **kwargs)
|
||||
if message_log:
|
||||
return record._message_log(body=rendered_template, **kwargs)
|
||||
else:
|
||||
kwargs['body'] = rendered_template
|
||||
return record.message_post_with_template(False, **kwargs)
|
||||
|
||||
def message_post_with_view(self, views_or_xmlid, **kwargs):
|
||||
""" Helper method to send a mail / post a message using a view_id """
|
||||
self._message_compose_with_view(views_or_xmlid, **kwargs)
|
||||
|
||||
def message_post_with_template(self, template_id, email_layout_xmlid=None, auto_commit=False, **kwargs):
|
||||
""" Helper method to send a mail with a template
|
||||
@@ -1986,6 +1993,10 @@ class MailThread(models.AbstractModel):
|
||||
MailThread._notify_thread(new_message, values, **notif_kwargs)
|
||||
return new_message
|
||||
|
||||
def _message_log_with_view(self, views_or_xmlid, **kwargs):
|
||||
""" Helper method to log a note using a view_id without notifying followers. """
|
||||
return self._message_compose_with_view(views_or_xmlid, message_log=True, **kwargs)
|
||||
|
||||
def _message_log(self, *, body='', author_id=None, email_from=None, subject=False, message_type='notification', **kwargs):
|
||||
""" Shortcut allowing to post note on a document. It does not perform
|
||||
any notification and pre-computes some values to have a short code
|
||||
|
||||
@@ -11,6 +11,8 @@ class MassMailingList(models.Model):
|
||||
_order = 'name'
|
||||
_description = 'Mailing List'
|
||||
_mailing_enabled = True
|
||||
# As this model has his own data merge, avoid to enable the generic data_merge on that model.
|
||||
_disable_data_merge = True
|
||||
|
||||
name = fields.Char(string='Mailing List', required=True)
|
||||
active = fields.Boolean(default=True)
|
||||
|
||||
@@ -14,8 +14,8 @@ tests independently to functional aspects of other models. """,
|
||||
'security/ir.model.access.csv',
|
||||
'security/test_mail_security.xml',
|
||||
'data/data.xml',
|
||||
'data/mail_template_data.xml',
|
||||
'data/subtype_data.xml',
|
||||
'data/template_data.xml',
|
||||
],
|
||||
'demo': [
|
||||
],
|
||||
|
||||
@@ -33,4 +33,8 @@
|
||||
</t>
|
||||
</template>
|
||||
|
||||
<template id="mail_template_simple_test">
|
||||
<p>Hello <t t-esc="partner.name"/>,</p>
|
||||
</template>
|
||||
|
||||
</odoo>
|
||||
@@ -280,6 +280,17 @@ class TestMessagePost(TestMailCommon, TestRecipients):
|
||||
self.assertEqual(new_note.email_from, formataddr((self.user_employee.name, self.user_employee.email)))
|
||||
self.assertEqual(new_note.notified_partner_ids, self.env['res.partner'])
|
||||
|
||||
def test_post_log_with_view(self):
|
||||
new_note = self.test_record.with_user(self.user_employee)._message_log_with_view(
|
||||
'test_mail.mail_template_simple_test', values={'partner': self.user_employee.partner_id}
|
||||
)
|
||||
|
||||
self.assertEqual(new_note.subtype_id, self.env.ref('mail.mt_note'))
|
||||
self.assertTrue('<p>Hello %s,</p>' % self.user_employee.name in new_note.body)
|
||||
self.assertEqual(new_note.author_id, self.user_employee.partner_id)
|
||||
self.assertEqual(new_note.email_from, formataddr((self.user_employee.name, self.user_employee.email)))
|
||||
self.assertEqual(new_note.notified_partner_ids, self.env['res.partner'])
|
||||
|
||||
@mute_logger('odoo.addons.mail.models.mail_mail')
|
||||
def test_post_notify(self):
|
||||
self.user_employee.write({'notification_type': 'inbox'})
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
<field name="model">ir.model</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Model Description">
|
||||
<header><!-- used for override --></header>
|
||||
<sheet>
|
||||
<group>
|
||||
<group>
|
||||
|
||||
Reference in New Issue
Block a user