From f7307d64b88f641bd12124f9b08c16835c53cad7 Mon Sep 17 00:00:00 2001 From: Nicolas Martinelli Date: Tue, 27 Feb 2018 14:26:56 +0100 Subject: [PATCH] [FIX] mail: activities of archived records - Create an activity for a crm lead - Set the lead as lost The activity still appears in the list. A proper fix would be to have an `active` field on `mail.activity`. In the meantime, simply delete activites when archiving. opw-1817703 --- addons/mail/models/mail_activity.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/addons/mail/models/mail_activity.py b/addons/mail/models/mail_activity.py index cc53bab9fa7..4dc34056d90 100644 --- a/addons/mail/models/mail_activity.py +++ b/addons/mail/models/mail_activity.py @@ -317,6 +317,15 @@ class MailActivityMixin(models.AbstractModel): def _search_activity_summary(self, operator, operand): return [('activity_ids.summary', operator, operand)] + @api.multi + def write(self, vals): + # Delete activities of archived record. + if 'active' in vals and vals['active'] is False: + self.env['mail.activity'].sudo().search( + [('res_model', '=', self._name), ('res_id', 'in', self.ids)] + ).unlink() + return super(MailActivityMixin, self).write(vals) + @api.multi def unlink(self): """ Override unlink to delete records activities through (res_model, res_id). """