adds an option to disable the notification to existing followers

on a new email dropped to a record.
pull/467/head
Jordi Ballester Alomar 2019-11-22 12:28:56 +01:00
parent 9921383d76
commit 56f2057411
8 changed files with 101 additions and 1 deletions

View File

@ -18,5 +18,6 @@
},
"data": [
'views/templates.xml',
'views/res_config_settings_views.xml',
],
}

View File

@ -1,3 +1,4 @@
# Copyright 2018 Therp BV <https://therp.nl>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from . import mail_thread
from . import res_config_settings

View File

@ -15,7 +15,14 @@ class MailThread(models.AbstractModel):
def message_drop(self, model, message, custom_values=None,
save_original=False, strip_attachments=False,
thread_id=None):
result = self.message_process(
disable_notify_mail_drop_target = \
self.env["ir.config_parameter"].get_param(
"mail_drop_target.disable_notify", default=False)
self_message_process = self
if disable_notify_mail_drop_target:
self_message_process = self_message_process.with_context(
message_create_from_mail_mail=True)
result = self_message_process.message_process(
model, message, custom_values=custom_values,
save_original=save_original, strip_attachments=strip_attachments,
thread_id=thread_id

View File

@ -0,0 +1,33 @@
# Copyright 2019 Eficent Business and IT Consulting Services, S.L.
# <https//www.eficent.com>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from odoo import api, fields, models
class ResConfigSettings(models.TransientModel):
_inherit = 'res.config.settings'
disable_notify_mail_drop_target = fields.Boolean(
'Disable Notification followers on mail dropped to a Thread',
help="When this setting is set, when a user drops an "
"email into an existing thread the followers of the thread will "
"not be notified. This sets an ir.config.parameter "
"mail_drop_target.disable_notify")
@api.model
def get_values(self):
res = super(ResConfigSettings, self).get_values()
disable_notify_mail_drop_target = \
self.env["ir.config_parameter"].get_param(
"mail_drop_target.disable_notify", default=False)
res.update(
disable_notify_mail_drop_target=disable_notify_mail_drop_target,
)
return res
def set_values(self):
super(ResConfigSettings, self).set_values()
self.env['ir.config_parameter'].set_param(
"mail_drop_target.disable_notify",
self.disable_notify_mail_drop_target or '')

View File

@ -0,0 +1,3 @@
To disable the automatic notification to existing followers when you drop an
email to a record, go to *Settings*, activate the developer mode, and then go to
*Settings / General Settings* and set the flag 'Disable Mail Drag&Drop Notification'.

View File

@ -1,3 +1,7 @@
This module was written to allow users to drag&drop emails from their desktop to Odoo.
It supports as well RFC822 .eml files as Outlook .msg (those only if `an extra library <https://github.com/mattgwwalker/msg-extractor>`_ is installed) files.
When the mail is dropped to an odoo record, it will automatically send a notification
of that new message that has been added to all the existing followers. It is possible
to disable this notification.

View File

@ -10,6 +10,7 @@ class TestMailDropTarget(TransactionCase):
self.partner = self.env['res.partner'].create({
'name': 'TEST PARTNER'
})
self.partner.message_subscribe(partner_ids=self.partner.ids)
def test_eml(self):
message = tools.file_open(
@ -36,6 +37,9 @@ class TestMailDropTarget(TransactionCase):
self.partner._name, message, thread_id=self.partner.id)
self.partner.refresh()
self.assertEqual(comments+1, len(self.partner.message_ids))
msg = self.partner.message_ids.filtered(
lambda m: m.subject == 'Test')
self.assertIsNotNone(msg.needaction_partner_ids)
with self.assertRaises(exceptions.Warning):
self.partner.message_process_msg(
self.partner._name, message, thread_id=self.partner.id)
@ -46,3 +50,24 @@ class TestMailDropTarget(TransactionCase):
new=False,
):
self.test_msg()
def test_msg_no_notification(self):
message = base64.b64encode(tools.file_open(
'sample.msg',
mode='rb',
subdir="addons/mail_drop_target/tests"
).read())
settings = self.env['res.config.settings'].create({})
settings.disable_notify_mail_drop_target = True
settings.execute()
comments = len(self.partner.message_ids)
self.partner.message_process_msg(
self.partner._name, message, thread_id=self.partner.id)
self.partner.refresh()
self.assertEqual(comments+1, len(self.partner.message_ids))
msg = self.partner.message_ids.filtered(
lambda m: m.subject == 'Test')
self.assertEqual(len(msg.needaction_partner_ids), 0)
with self.assertRaises(exceptions.Warning):
self.partner.message_process_msg(
self.partner._name, message, thread_id=self.partner.id)

View File

@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data>
<record id="res_config_settings_view_form" model="ir.ui.view">
<field name="name">res.config.settings.view.form.inherit.mail</field>
<field name="model">res.config.settings</field>
<field name="inherit_id" ref="mail.res_config_settings_view_form"/>
<field name="arch" type="xml">
<div id="emails" position="inside">
<div class="col-xs-12 col-md-6 o_setting_box">
<div class="o_setting_left_pane">
<field name="disable_notify_mail_drop_target"/>
</div>
<div class="o_setting_right_pane">
<label string="Disable Mail Drag&amp;Drop Notification" for="disable_notify_mail_drop_target"/>
<div class="text-muted">
When a user drops an email into an existing thread
the followers of the thread will not be notified.
</div>
</div>
</div>
</div>
</field>
</record>
</data>
</odoo>