[ADD] mail_activity_unlink_log

pull/1597/head
Enric Tobella 2023-02-23 14:38:10 +01:00 committed by Enric Tobella
parent 518765e26e
commit 87e446bc29
11 changed files with 152 additions and 0 deletions

View File

@ -0,0 +1,9 @@
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
:target: https://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
====================
Mail Activity Unlink
====================
Leave a message on deleted activities

View File

@ -0,0 +1 @@
from . import models

View File

@ -0,0 +1,14 @@
# Copyright 2023 CreuBlanca
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
{
"name": "Mail Activities: log on unlink",
"summary": """
Leave a message when an activity is unlinked""",
"version": "14.0.1.0.0",
"license": "AGPL-3",
"author": "CreuBlanca,Odoo Community Association (OCA)",
"website": "https://github.com/OCA/social",
"depends": ["mail"],
"data": ["data/unlink_message.xml"],
}

View File

@ -0,0 +1,35 @@
<?xml version="1.0" encoding="UTF-8" ?>
<odoo>
<data noupdate="1">
<record id="mt_activities_unlink" model="mail.message.subtype">
<field name="name">Activities unlink</field>
<field name="default" eval="True" />
<field name="internal" eval="True" />
<field name="sequence" eval="90" />
</record>
</data>
<data>
<template id="message_activity_unlink">
<div>
<p>
<span
t-attf-class="fa #{activity.activity_type_id.icon} fa-fw"
/><span t-field="activity.activity_type_id.name" /> deleted
<t t-if="display_assignee"> (originally assigned to <span
t-field="activity.user_id.name"
/>)</t>
<span t-if="activity.summary">: </span><span
t-if="activity.summary"
t-field="activity.summary"
/>
</p>
<t
t-if="activity.note and activity.note != '&lt;p&gt;&lt;br&gt;&lt;/p&gt;'"
><!-- <p></br></p> -->
<div class="o_mail_note_title"><strong>Original note:</strong></div>
<div t-field="activity.note" />
</t>
</div>
</template>
</data>
</odoo>

View File

@ -0,0 +1 @@
from . import mail_activity

View File

@ -0,0 +1,39 @@
# Copyright 2023 CreuBlanca
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import models
class MailActivity(models.Model):
_inherit = "mail.activity"
def _action_done(self, *args, **kwargs):
return super(
MailActivity, self.with_context(activity_unlink_no_message=True)
)._action_done(*args, **kwargs)
def unlink(self):
if not self.env.context.get("activity_unlink_no_message"):
for activity in self:
record = self.env[activity.res_model].browse(activity.res_id)
record.message_post_with_view(
"mail_activity_unlink_log.message_activity_unlink",
values={
"activity": activity,
"display_assignee": activity.user_id != self.env.user,
},
subtype_id=self.env["ir.model.data"].xmlid_to_res_id(
"mail_activity_unlink_log.mt_activities_unlink"
),
mail_activity_type_id=activity.activity_type_id.id,
)
return super().unlink()
class MailActivityMixin(models.AbstractModel):
_inherit = "mail.activity.mixin"
def unlink(self):
return super(
MailActivityMixin, self.with_context(activity_unlink_no_message=True)
).unlink()

View File

@ -0,0 +1 @@
* Enric Tobella

View File

@ -0,0 +1,2 @@
This addon enforces the creation of a message when an activity is unlinked.
This change tries to avoid a possible bad practice of deletion of an activity without notifying the deletion.

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.2 KiB

View File

@ -0,0 +1 @@
from . import test_activity_unlink

View File

@ -0,0 +1,49 @@
# Copyright 2023 CreuBlanca
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo.tests.common import TransactionCase
class TestActivityUnlink(TransactionCase):
def setUp(self):
super().setUp()
self.partner = self.env["res.partner"].create({"name": "Partner"})
self.unlink_subtype = self.env.ref(
"mail_activity_unlink_log.mt_activities_unlink"
)
def test_done(self):
self.assertFalse(
self.partner.message_ids.filtered(
lambda r: r.subtype_id == self.unlink_subtype
)
)
self.activity = self.partner.activity_schedule(
act_type_xmlid="mail.mail_activity_data_todo"
)
self.assertTrue(self.partner.activity_ids)
self.activity.action_done()
self.assertFalse(self.partner.activity_ids)
self.assertFalse(
self.partner.message_ids.filtered(
lambda r: r.subtype_id == self.unlink_subtype
)
)
def test_unlink(self):
self.assertFalse(
self.partner.message_ids.filtered(
lambda r: r.subtype_id == self.unlink_subtype
)
)
self.activity = self.partner.activity_schedule(
act_type_xmlid="mail.mail_activity_data_todo"
)
self.assertTrue(self.partner.activity_ids)
self.activity.unlink()
self.assertFalse(self.partner.activity_ids)
self.assertTrue(
self.partner.message_ids.filtered(
lambda r: r.subtype_id == self.unlink_subtype
)
)