Browse Source

Merge pull request #253 from simahawk/11.0

mail_digest: fix notification domain for partners w/ no user
pull/254/head
Pedro M. Baeza 7 years ago
committed by GitHub
parent
commit
48978fbb66
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      mail_digest/__manifest__.py
  2. 26
      mail_digest/models/res_partner.py
  3. 15
      mail_digest/tests/test_partner_domains.py

2
mail_digest/__manifest__.py

@ -4,7 +4,7 @@
{ {
'name': 'Mail digest', 'name': 'Mail digest',
'summary': """Basic digest mail handling.""", 'summary': """Basic digest mail handling.""",
'version': '11.0.1.0.1',
'version': '11.0.1.0.2',
'license': 'AGPL-3', 'license': 'AGPL-3',
'author': 'Camptocamp, Odoo Community Association (OCA)', 'author': 'Camptocamp, Odoo Community Association (OCA)',
'website': 'https://github.com/OCA/social', 'website': 'https://github.com/OCA/social',

26
mail_digest/models/res_partner.py

@ -77,17 +77,37 @@ class ResPartner(models.Model):
ids = self.ids ids = self.ids
if self.env.context.get('notify_only_recipients'): if self.env.context.get('notify_only_recipients'):
ids = [x for x in ids if x in message.partner_ids.ids] ids = [x for x in ids if x in message.partner_ids.ids]
domain = [
common_domain = [
'|', '|',
('id', 'in', ids), ('id', 'in', ids),
('channel_ids', 'in', channels.ids), ('channel_ids', 'in', channels.ids),
('email', '!=', email), ('email', '!=', email),
]
# A bit hacky but we need to exclude / include partners
# that do not have any user and as such, they have no email settings.
# NOTE: using the following domain does not work,
# so we do 2 searches in the middle and return a domain
# containing only the desired ids.
#
# '|', ('user_ids', '=', False),
# '&', ('user_ids.digest_mode', '=', False),
# ('user_ids.notification_type', '=', 'email')
without_users_ids = []
if not digest:
# get partners w/ no users
without_users_ids = self.search(
common_domain + [('user_ids', '=', False)]
).ids
digest_domain = [
('user_ids.digest_mode', '=', digest), ('user_ids.digest_mode', '=', digest),
('user_ids.notification_type', '=', 'email'), ('user_ids.notification_type', '=', 'email'),
] ]
if message.subtype_id: if message.subtype_id:
domain.extend(self._get_domain_subtype_leaf(message.subtype_id))
return domain
digest_domain.extend(
self._get_domain_subtype_leaf(message.subtype_id))
# get partners w/ users
with_users_ids = self.search(common_domain + digest_domain).ids
return [('id', 'in', without_users_ids + with_users_ids)]
@api.model @api.model
def _get_domain_subtype_leaf(self, subtype): def _get_domain_subtype_leaf(self, subtype):

15
mail_digest/tests/test_partner_domains.py

@ -34,6 +34,13 @@ class PartnerDomainCase(SavepointCase):
cls.partner1 = cls.user1.partner_id cls.partner1 = cls.user1.partner_id
cls.partner2 = cls.user2.partner_id cls.partner2 = cls.user2.partner_id
cls.partner3 = cls.user3.partner_id cls.partner3 = cls.user3.partner_id
# a partner w/ no user that should not be excluded
# in non-digest notifications
cls.partner_nouser = cls.partner_model.with_context(
tracking_disable=True).create({
'name': 'No User Partner',
'email': 'nouser@test.com',
})
cls.subtype1 = cls.subtype_model.create({'name': 'Type 1'}) cls.subtype1 = cls.subtype_model.create({'name': 'Type 1'})
cls.subtype2 = cls.subtype_model.create({'name': 'Type 2'}) cls.subtype2 = cls.subtype_model.create({'name': 'Type 2'})
@ -60,7 +67,7 @@ class PartnerDomainCase(SavepointCase):
# because we call `_get_notify_by_email_domain` directly # because we call `_get_notify_by_email_domain` directly
self.partner1.real_user_id.notification_type = 'email' self.partner1.real_user_id.notification_type = 'email'
self.partner2.real_user_id.notification_type = 'email' self.partner2.real_user_id.notification_type = 'email'
partners = self.partner1 + self.partner2
partners = self.partner1 + self.partner2 + self.partner_nouser
# followers # followers
self.partner3.message_subscribe(self.partner2.ids) self.partner3.message_subscribe(self.partner2.ids)
# partner1 is the only recipient # partner1 is the only recipient
@ -68,16 +75,20 @@ class PartnerDomainCase(SavepointCase):
'body': 'My Body', 'body': 'My Body',
'res_id': self.partner3.id, 'res_id': self.partner3.id,
'model': 'res.partner', 'model': 'res.partner',
'partner_ids': [(4, self.partner1.id)]
'partner_ids': [(4, self.partner1.id), (4, self.partner_nouser.id)]
}) })
domain = partners._get_notify_by_email_domain(message) domain = partners._get_notify_by_email_domain(message)
# we find both of them since partner2 is a follower # we find both of them since partner2 is a follower
self._assert_found(self.partner1, domain) self._assert_found(self.partner1, domain)
self._assert_found(self.partner2, domain) self._assert_found(self.partner2, domain)
# and we find also the partner w/ no user
self._assert_found(self.partner_nouser, domain)
# no one here in digest mode # no one here in digest mode
domain = partners._get_notify_by_email_domain(message, digest=True) domain = partners._get_notify_by_email_domain(message, digest=True)
self._assert_found(self.partner1, domain, not_found=True) self._assert_found(self.partner1, domain, not_found=True)
self._assert_found(self.partner2, domain, not_found=True) self._assert_found(self.partner2, domain, not_found=True)
self._assert_found(self.partner_nouser, domain, not_found=True)
# include only recipients # include only recipients
domain = partners.with_context( domain = partners.with_context(

Loading…
Cancel
Save