From 5d795d16f98714cc8ca08ec9542d95d30e5d6684 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Fri, 15 Jun 2018 11:57:32 +0200 Subject: [PATCH 1/4] [IMP] mail: remove unused imports --- addons/mail/models/mail_activity.py | 2 -- addons/test_mail/tests/common.py | 1 - 2 files changed, 3 deletions(-) diff --git a/addons/mail/models/mail_activity.py b/addons/mail/models/mail_activity.py index 83feb875a66..57b60ab95d9 100644 --- a/addons/mail/models/mail_activity.py +++ b/addons/mail/models/mail_activity.py @@ -5,8 +5,6 @@ from datetime import date, datetime, timedelta import pytz from odoo import api, exceptions, fields, models, _ -from odoo.osv import expression -from odoo.tools import pycompat class MailActivityType(models.Model): diff --git a/addons/test_mail/tests/common.py b/addons/test_mail/tests/common.py index b526dce2906..641863a3bcb 100644 --- a/addons/test_mail/tests/common.py +++ b/addons/test_mail/tests/common.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- -from json import dumps, loads import json From af3bd8193a55756528716f114ebf284cb55dcb6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Fri, 15 Jun 2018 12:11:52 +0200 Subject: [PATCH 2/4] [MOV] mail: move template used for notification to data As those are technical views used as data when sending some notifications they should not be in the templates. --- addons/mail/data/mail_data.xml | 41 ++++++++++++++++++++++++++++ addons/mail/views/mail_templates.xml | 39 -------------------------- 2 files changed, 41 insertions(+), 39 deletions(-) diff --git a/addons/mail/data/mail_data.xml b/addons/mail/data/mail_data.xml index 4c3848f1199..78c74494941 100644 --- a/addons/mail/data/mail_data.xml +++ b/addons/mail/data/mail_data.xml @@ -320,6 +320,47 @@ + + + + + + + + - - - - - - From 4b348c6ed971aa99878cde6e4ecb8cab5346161e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Fri, 27 Jul 2018 16:26:26 +0200 Subject: [PATCH 3/4] [IMP] test_mail: improve assertNotification method Purpose is to be able to test generic notifications, not only those attached to some messages. --- addons/test_mail/tests/common.py | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/addons/test_mail/tests/common.py b/addons/test_mail/tests/common.py index 641863a3bcb..c7b2e4af8e3 100644 --- a/addons/test_mail/tests/common.py +++ b/addons/test_mail/tests/common.py @@ -42,23 +42,23 @@ class BaseFunctionalTest(common.SavepointCase): def assertNotifications(self, **counters): """ Counters: 'partner_attribute': 'inbox' or 'email' """ try: - init_messages = self.test_record.message_ids init = {} partners = self.env['res.partner'] for partner_attribute in counters.keys(): - partner = getattr(self, partner_attribute) - partners |= partner + partners |= getattr(self, partner_attribute) + init_notifs = self.env['mail.notification'].sudo().search([('res_partner_id', 'in', partners.ids)]) + for partner in partners: if partner.user_ids: init[partner] = { - 'na_counter': self.test_record.sudo(partner.user_ids[0]).message_needaction_counter, + 'na_counter': len([n for n in init_notifs if n.res_partner_id == partner]), } yield finally: - new_messages = self.test_record.sudo().message_ids - init_messages - new_notifications = self.env['mail.notification'].search([ + new_notifications = self.env['mail.notification'].sudo().search([ ('res_partner_id', 'in', partners.ids), - ('mail_message_id', 'in', new_messages.ids) + ('id', 'not in', init_notifs.ids) ]) + new_messages = new_notifications.mapped('mail_message_id') for partner_attribute in counters.keys(): counter, notif_type, notif_read = counters[partner_attribute] @@ -69,9 +69,12 @@ class BaseFunctionalTest(common.SavepointCase): if partner.user_ids: expected = init[partner]['na_counter'] + counter if notif_read == 'unread' else init[partner]['na_counter'] - self.assertEqual(expected, self.test_record.sudo(partner.user_ids[0]).message_needaction_counter, - 'Invalid number of notification for %s: %s instead of %s' % - (partner.name, expected, self.test_record.sudo(partner.user_ids[0]).message_needaction_counter)) + real = self.env['mail.notification'].sudo().search_count([ + ('res_partner_id', '=', partner.id), + ('is_read', '=', False) + ]) + self.assertEqual(expected, real, 'Invalid number of notification for %s: %s instead of %s' % + (partner.name, real, expected)) if partner_notif: self.assertTrue(all(n.is_email == (notif_type == 'email') for n in partner_notif)) self.assertTrue(all(n.is_read == (notif_read == 'read') for n in partner_notif), From 792efc861503d6060a3d1edba0ff9a9c75999c4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Fri, 15 Jun 2018 13:03:21 +0200 Subject: [PATCH 4/4] [IMP] mail: notify people when another user assigns them on an activity When someone assigns an activity to another user it is a good idea to notify this user a new activity has been assigned to him. This is done using the message_notify method that sends a notification either in the Inbox either by email depending on the user preferences. This commits is linked to task ID 1854820. Closes PR #25265. --- addons/mail/data/mail_data.xml | 16 ++++++++++++++ addons/mail/models/mail_activity.py | 23 ++++++++++++++++++++ addons/mail/views/mail_activity_views.xml | 7 ++++-- addons/test_mail/tests/test_mail_activity.py | 20 +++++++++++++++++ 4 files changed, 64 insertions(+), 2 deletions(-) diff --git a/addons/mail/data/mail_data.xml b/addons/mail/data/mail_data.xml index 78c74494941..83b78c2989a 100644 --- a/addons/mail/data/mail_data.xml +++ b/addons/mail/data/mail_data.xml @@ -348,6 +348,22 @@ + +