[IMP] mail: remove activities when archiving records

When archiving records through the generic toggle_active methods we now
remove ongoing activities.

Purpose of this commit is to avoid having ongoing activities in the systray
linked to archived records. As archiving records means we won't work on
them anymore it makes no sense to keep related activities.
This commit is contained in:
Thibault Delavallée
2018-08-01 10:24:36 +02:00
parent 964f2dc046
commit 618c42575e
2 changed files with 27 additions and 0 deletions
+14
View File
@@ -453,6 +453,20 @@ class MailActivityMixin(models.AbstractModel):
).unlink()
return result
@api.multi
def toggle_active(self):
""" Before archiving the record we should also remove its ongoing
activities. Otherwise they stay in the systray and concerning archived
records it makes no sense. """
record_to_deactivate = self.filtered(lambda rec: rec.active)
if record_to_deactivate:
# use a sudo to bypass every access rights; all activities should be removed
self.env['mail.activity'].sudo().search([
('res_model', '=', self._name),
('res_id', 'in', record_to_deactivate.ids)
]).unlink()
return super(MailActivityMixin, self).toggle_active()
def activity_schedule(self, act_type_xmlid='', date_deadline=None, summary='', note='', **act_values):
""" Schedule an activity on each record of the current record set.
This method allow to provide as parameter act_type_xmlid. This is an
@@ -144,6 +144,19 @@ class TestMailActivity(BaseFunctionalTest):
self.assertEqual(self.test_record.activity_ids, self.env['mail.activity'])
self.assertEqual(len(self.test_record.message_ids), 2)
def test_activity_mixin_archive(self):
rec = self.test_record.sudo(self.user_employee)
new_act = rec.activity_schedule(
'test_mail.mail_act_test_todo',
user_id=self.user_admin.id)
self.assertEqual(rec.activity_ids, new_act)
rec.toggle_active()
self.assertEqual(rec.active, False)
self.assertEqual(rec.activity_ids, self.env['mail.activity'])
rec.toggle_active()
self.assertEqual(rec.active, True)
self.assertEqual(rec.activity_ids, self.env['mail.activity'])
def test_activity_notify_other_user(self):
self.user_admin.notification_type = 'email'
rec = self.test_record.sudo(self.user_employee)