Browse Source

[ADD] mail_follower_custom_notification: Treat employees differently

from other partners for overriding mailing value
pull/297/head
Holger Brunn 6 years ago
parent
commit
eabfd1be19
No known key found for this signature in database GPG Key ID: 1C9760FECA3AE18
  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. 18
      mail_follower_custom_notification/models/mail_followers.py
  5. 9
      mail_follower_custom_notification/models/mail_message_subtype.py
  6. 1
      mail_follower_custom_notification/tests/test_mail_follower_custom_notification.py
  7. 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. 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. 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 Configuration
============= =============
@ -41,6 +42,7 @@ For further information, please visit:
* https://www.odoo.com/forum/help-1 * https://www.odoo.com/forum/help-1
Bug Tracker 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 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**>`_. `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 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). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
{ {
"name": "Custom notification settings for followers", "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)", "author": "Therp BV,Odoo Community Association (OCA)",
"license": "AGPL-3", "license": "AGPL-3",
"category": "Social Network", "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',
)

18
mail_follower_custom_notification/models/mail_followers.py

@ -23,7 +23,6 @@ class MailFollowers(models.Model):
string='Force own mails from subtype') string='Force own mails from subtype')
@api.model @api.model
@api.returns('self', lambda x: x.id)
def create(self, values): def create(self, values):
this = super(MailFollowers, self).create(values) this = super(MailFollowers, self).create(values)
for subtype in this.subtype_ids: for subtype in this.subtype_ids:
@ -33,10 +32,21 @@ class MailFollowers(models.Model):
subtype.custom_notification_model_ids\ subtype.custom_notification_model_ids\
.mapped('model'): .mapped('model'):
continue 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': 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': 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: if subtype.custom_notification_own:
this.force_own_subtype_ids += subtype
this.force_own_subtype_ids |= subtype
return this return this

9
mail_follower_custom_notification/models/mail_message_subtype.py

@ -9,10 +9,17 @@ class MailMessageSubtype(models.Model):
custom_notification_mail = fields.Selection( custom_notification_mail = fields.Selection(
[('force_yes', 'Force yes'), ('force_no', 'Force no')], [('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 ' '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 ' 'of this type via email, and "Force no" to never send messages of '
'type via email') '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( custom_notification_own = fields.Boolean(
'Notify about own messages', help='Check this to have notifications ' 'Notify about own messages', help='Check this to have notifications '
'generated and sent via email about own messages') 'generated and sent via email about own messages')

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 # post a message and see if we successfully forced a notification to
# ourselves # ourselves
# pylint: disable=translation-required
followed_partner_demo.message_post('hello world', subtype='mt_comment') followed_partner_demo.message_post('hello world', subtype='mt_comment')
self.assertEqual( self.assertEqual(
followed_partner_demo.message_ids[:-1].notification_ids.partner_id, 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 position="inside">
<group string="Custom notifications"> <group string="Custom notifications">
<field name="custom_notification_mail" /> <field name="custom_notification_mail" />
<field name="custom_notification_mail_employees" />
<field name="custom_notification_own" /> <field name="custom_notification_own" />
<field name="custom_notification_model_ids" attrs="{'invisible': [('res_model', '!=', False)]}" widget="many2many_tags" /> <field name="custom_notification_model_ids" attrs="{'invisible': [('res_model', '!=', False)]}" widget="many2many_tags" />
</group> </group>

Loading…
Cancel
Save