From eabfd1be19b663e8adddc33f76dda79c6f3d8993 Mon Sep 17 00:00:00 2001 From: Holger Brunn Date: Tue, 28 Aug 2018 14:28:40 +0200 Subject: [PATCH] [ADD] mail_follower_custom_notification: Treat employees differently from other partners for overriding mailing value --- mail_follower_custom_notification/README.rst | 9 ++++++--- .../__openerp__.py | 2 +- .../migrations/8.0.1.1.0/post-migration.py | 11 +++++++++++ .../models/mail_followers.py | 18 ++++++++++++++---- .../models/mail_message_subtype.py | 9 ++++++++- .../test_mail_follower_custom_notification.py | 1 + .../views/mail_message_subtype.xml | 1 + 7 files changed, 42 insertions(+), 9 deletions(-) create mode 100644 mail_follower_custom_notification/migrations/8.0.1.1.0/post-migration.py diff --git a/mail_follower_custom_notification/README.rst b/mail_follower_custom_notification/README.rst index 7f14c572..0e7f18aa 100644 --- a/mail_follower_custom_notification/README.rst +++ b/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 `_. + Credits ======= diff --git a/mail_follower_custom_notification/__openerp__.py b/mail_follower_custom_notification/__openerp__.py index e15b28ba..110f7882 100644 --- a/mail_follower_custom_notification/__openerp__.py +++ b/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", diff --git a/mail_follower_custom_notification/migrations/8.0.1.1.0/post-migration.py b/mail_follower_custom_notification/migrations/8.0.1.1.0/post-migration.py new file mode 100644 index 00000000..ec35e7f4 --- /dev/null +++ b/mail_follower_custom_notification/migrations/8.0.1.1.0/post-migration.py @@ -0,0 +1,11 @@ +# -*- coding: utf-8 -*- +# Copyright 2018 Therp BV +# 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', + ) diff --git a/mail_follower_custom_notification/models/mail_followers.py b/mail_follower_custom_notification/models/mail_followers.py index 82719402..e44b2018 100644 --- a/mail_follower_custom_notification/models/mail_followers.py +++ b/mail_follower_custom_notification/models/mail_followers.py @@ -23,7 +23,6 @@ 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: @@ -33,10 +32,21 @@ class MailFollowers(models.Model): subtype.custom_notification_model_ids\ .mapped('model'): continue + user = self.env['res.users'].search([ + ('partner_id', '=', this.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 + this.force_mail_subtype_ids |= subtype if subtype.custom_notification_mail == 'force_no': - this.force_nomail_subtype_ids += subtype + this.force_nomail_subtype_ids |= subtype + if is_employee: + if subtype.custom_notification_mail_employees == 'force_yes': + this.force_mail_subtype_ids |= subtype + this.force_nomail_subtype_ids -= subtype + if subtype.custom_notification_mail_employees == 'force_no': + this.force_mail_subtype_ids -= subtype + this.force_nomail_subtype_ids |= subtype if subtype.custom_notification_own: - this.force_own_subtype_ids += subtype + this.force_own_subtype_ids |= subtype return this diff --git a/mail_follower_custom_notification/models/mail_message_subtype.py b/mail_follower_custom_notification/models/mail_message_subtype.py index f58e199d..ad1b0cb9 100644 --- a/mail_follower_custom_notification/models/mail_message_subtype.py +++ b/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') diff --git a/mail_follower_custom_notification/tests/test_mail_follower_custom_notification.py b/mail_follower_custom_notification/tests/test_mail_follower_custom_notification.py index 11bed947..613028c6 100644 --- a/mail_follower_custom_notification/tests/test_mail_follower_custom_notification.py +++ b/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, diff --git a/mail_follower_custom_notification/views/mail_message_subtype.xml b/mail_follower_custom_notification/views/mail_message_subtype.xml index 0d60986c..4f5b8c15 100644 --- a/mail_follower_custom_notification/views/mail_message_subtype.xml +++ b/mail_follower_custom_notification/views/mail_message_subtype.xml @@ -8,6 +8,7 @@ +