Browse Source

Merge f846554a4a into dabb3bb7ff

pull/297/merge
Holger Brunn 5 years ago
committed by GitHub
parent
commit
6b3e55cce3
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 9
      mail_follower_custom_notification/README.rst
  2. 2
      mail_follower_custom_notification/__openerp__.py
  3. 11
      mail_follower_custom_notification/migrations/8.0.1.1.0/post-migration.py
  4. 48
      mail_follower_custom_notification/models/mail_followers.py
  5. 9
      mail_follower_custom_notification/models/mail_message_subtype.py
  6. 44
      mail_follower_custom_notification/static/src/js/mail_follower_custom_notification.js
  7. 1
      mail_follower_custom_notification/tests/test_mail_follower_custom_notification.py
  8. 1
      mail_follower_custom_notification/views/mail_message_subtype.xml

9
mail_follower_custom_notification/README.rst

@ -6,11 +6,12 @@ Custom notification settings for followers
==========================================
In standard Odoo, receiving mail notifications is an all or nothing affair.
This module allows you users to decide per followed record if they want to
receive emails or not. Further, they can choose to receive notification about
This module allows your users to decide per followed record if they want to
receive emails or not. Further, they can choose to receive notifications about
their own messages.
You can also set defaults for this settings on the subtype in question.
You can also set defaults for this settings on the subtype in question for all
partners or only for employees.
Configuration
=============
@ -41,6 +42,7 @@ For further information, please visit:
* https://www.odoo.com/forum/help-1
Bug Tracker
===========
@ -49,6 +51,7 @@ In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed and welcomed feedback
`here <https://github.com/OCA/social/issues/new?body=module:%20mail_follower_custom_notification%0Aversion:%208.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
Credits
=======

2
mail_follower_custom_notification/__openerp__.py

@ -3,7 +3,7 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
{
"name": "Custom notification settings for followers",
"version": "8.0.1.0.0",
"version": "8.0.1.1.0",
"author": "Therp BV,Odoo Community Association (OCA)",
"license": "AGPL-3",
"category": "Social Network",

11
mail_follower_custom_notification/migrations/8.0.1.1.0/post-migration.py

@ -0,0 +1,11 @@
# -*- coding: utf-8 -*-
# Copyright 2018 Therp BV <https://therp.nl>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
def migrate(cr, version=None):
# initialize value for employees with values for everyone
cr.execute(
'update mail_message_subtype set '
'custom_notification_mail_employees=custom_notification_mail',
)

48
mail_follower_custom_notification/models/mail_followers.py

@ -23,20 +23,54 @@ class MailFollowers(models.Model):
string='Force own mails from subtype')
@api.model
@api.returns('self', lambda x: x.id)
def create(self, values):
this = super(MailFollowers, self).create(values)
for subtype in this.subtype_ids:
this._mail_follower_custom_notification_update()
return this
@api.multi
def _mail_follower_custom_notification_update(self, subtypes=None):
self.ensure_one()
for subtype in subtypes or self.subtype_ids:
if not subtype.res_model and\
subtype.custom_notification_model_ids and\
this.res_model not in\
self.res_model not in\
subtype.custom_notification_model_ids\
.mapped('model'):
continue
user = self.env['res.users'].search([
('partner_id', '=', self.partner_id.id),
], limit=1)
is_employee = user and user.has_group('base.group_user')
if subtype.custom_notification_mail == 'force_yes':
this.force_mail_subtype_ids += subtype
self.force_mail_subtype_ids |= subtype
if subtype.custom_notification_mail == 'force_no':
this.force_nomail_subtype_ids += subtype
self.force_nomail_subtype_ids |= subtype
if is_employee:
if subtype.custom_notification_mail_employees == 'force_yes':
self.force_mail_subtype_ids |= subtype
self.force_nomail_subtype_ids -= subtype
if subtype.custom_notification_mail_employees == 'force_no':
self.force_mail_subtype_ids -= subtype
self.force_nomail_subtype_ids |= subtype
if subtype.custom_notification_own:
this.force_own_subtype_ids += subtype
return this
self.force_own_subtype_ids |= subtype
@api.multi
def write(self, values):
result = super(MailFollowers, self).write(values)
if 'subtype_ids' in values:
for this in self:
subtypes = self.env['mail.message.subtype'].browse(
filter(
None,
map(
lambda x: x.get('id'),
this.resolve_2many_commands(
'subtype_ids', values['subtype_ids'],
),
)
)
)
this._mail_follower_custom_notification_update(subtypes)
return result

9
mail_follower_custom_notification/models/mail_message_subtype.py

@ -9,10 +9,17 @@ class MailMessageSubtype(models.Model):
custom_notification_mail = fields.Selection(
[('force_yes', 'Force yes'), ('force_no', 'Force no')],
string='Send mail notification', help='Leave empty to use the '
string='Send mail notification', help='Leave empty to use the setting '
'on the partner\'s form, set to "Force yes" to always send messages '
'of this type via email, and "Force no" to never send messages of '
'type via email')
custom_notification_mail_employees = fields.Selection(
[('force_yes', 'Force yes'), ('force_no', 'Force no')],
string='Send mail notification (employees)', help='Leave empty to use '
'the setting on the employee\'s partner form, set '
'to "Force yes" to always send messages of this type via email to '
'employees, and "Force no" to never send messages of type via email '
'to employees. Employees are users in group \'Employees\'')
custom_notification_own = fields.Boolean(
'Notify about own messages', help='Check this to have notifications '
'generated and sent via email about own messages')

44
mail_follower_custom_notification/static/src/js/mail_follower_custom_notification.js

@ -2,20 +2,16 @@
//© 2015 Therp BV <http://therp.nl>
//License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
openerp.mail_follower_custom_notification = function(instance)
{
openerp.mail_follower_custom_notification = function(instance) {
instance.mail_followers.Followers.include({
display_subtypes: function(data, id, dialog)
{
display_subtypes: function(data, id, dialog) {
var $list = this.$('.oe_subtype_list ul');
if (dialog)
{
if (dialog) {
$list = this.$dialog.$el;
}
$list.empty();
this._super(data, id, dialog);
$list.find('input[type=checkbox]').change(function()
{
$list.find('input[type=checkbox]').change(function() {
$list.find(_.str.sprintf(
'#custom_notification_%s%s',
jQuery(this).data('id'),
@ -23,14 +19,12 @@ openerp.mail_follower_custom_notification = function(instance)
))
.toggle(jQuery(this).prop('checked'));
});
if(!dialog)
{
if(!dialog) {
$list.find('.oe_custom_notification input[type=radio]')
.change(this.proxy('do_update_subscription'));
};
}
},
do_update_subscription: function(event, user_pid)
{
do_update_subscription: function(event, user_pid) {
/*
if(jQuery(event.currentTarget).parents('.oe_custom_notification')
.length)
@ -44,36 +38,32 @@ openerp.mail_follower_custom_notification = function(instance)
follower_ids = [this.session.uid],
custom_notifications = {},
oe_action = this.$('.oe_actions');
if(user_pid)
{
if(user_pid) {
update_func = 'message_custom_notification_update';
follower_ids = [user_pid];
oe_action = jQuery('.oe_edit_actions');
}
_(follower_ids).each(function(follower)
{
_(follower_ids).each(function(follower) {
var follower_settings = custom_notifications[follower] = {};
oe_action.find('.oe_custom_notification')
.each(function()
{
var id = parseInt(jQuery(this).data('id')),
.each(function() {
var id = parseInt(jQuery(this).data('id'), 10),
settings = follower_settings[id] = {};
settings['force_mail'] = jQuery(this)
settings.force_mail = jQuery(this)
.find('.oe_custom_notification_mail input:checked')
.val();
settings['force_own'] = jQuery(this)
settings.force_own = jQuery(this)
.find('.oe_custom_notification_own input:checked')
.val();
});
});
return jQuery.when(this._super.apply(this, arguments))
.then(function()
{
.then(function() {
return self.ds_model.call(
update_func,
[[self.view.datarecord.id], custom_notifications])
})
[[self.view.datarecord.id], custom_notifications]);
});
},
});
}
};

1
mail_follower_custom_notification/tests/test_mail_follower_custom_notification.py

@ -50,6 +50,7 @@ class TestMailFollowerCustomNotification(TransactionCase):
# post a message and see if we successfully forced a notification to
# ourselves
# pylint: disable=translation-required
followed_partner_demo.message_post('hello world', subtype='mt_comment')
self.assertEqual(
followed_partner_demo.message_ids[:-1].notification_ids.partner_id,

1
mail_follower_custom_notification/views/mail_message_subtype.xml

@ -8,6 +8,7 @@
<group position="inside">
<group string="Custom notifications">
<field name="custom_notification_mail" />
<field name="custom_notification_mail_employees" />
<field name="custom_notification_own" />
<field name="custom_notification_model_ids" attrs="{'invisible': [('res_model', '!=', False)]}" widget="many2many_tags" />
</group>

Loading…
Cancel
Save