2022-01-19 17:10:24 +01:00
|
|
|
# Copyright 2018-22 ForgeFlow <http://www.forgeflow.com>
|
2018-08-23 01:26:55 +02:00
|
|
|
# Copyright 2018 Odoo, S.A.
|
|
|
|
# License AGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
|
2022-01-19 17:10:24 +01:00
|
|
|
from odoo import Command, fields
|
2018-08-23 01:26:55 +02:00
|
|
|
|
2021-08-13 12:50:46 +02:00
|
|
|
from odoo.addons.mail.models.mail_activity import MailActivity
|
|
|
|
|
2018-08-23 01:26:55 +02:00
|
|
|
|
|
|
|
def pre_init_hook(cr):
|
2021-08-13 12:50:46 +02:00
|
|
|
"""The objective of this hook is to default to false all values of field
|
2018-08-23 01:26:55 +02:00
|
|
|
'done' of mail.activity
|
|
|
|
"""
|
2021-08-13 12:50:46 +02:00
|
|
|
cr.execute(
|
|
|
|
"""SELECT column_name
|
2018-08-23 01:26:55 +02:00
|
|
|
FROM information_schema.columns
|
|
|
|
WHERE table_name='mail_activity' AND
|
2021-08-13 12:50:46 +02:00
|
|
|
column_name='done'"""
|
|
|
|
)
|
2018-08-23 01:26:55 +02:00
|
|
|
if not cr.fetchone():
|
|
|
|
cr.execute(
|
|
|
|
"""
|
|
|
|
ALTER TABLE mail_activity ADD COLUMN done boolean;
|
2021-08-13 12:50:46 +02:00
|
|
|
"""
|
|
|
|
)
|
2018-08-23 01:26:55 +02:00
|
|
|
|
|
|
|
cr.execute(
|
|
|
|
"""
|
|
|
|
UPDATE mail_activity
|
|
|
|
SET done = False
|
|
|
|
"""
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
def post_load_hook():
|
2021-08-13 12:53:43 +02:00
|
|
|
def _new_action_done(self, feedback=False, attachment_ids=None):
|
|
|
|
"""Overwritten method"""
|
2021-08-13 12:50:46 +02:00
|
|
|
if "done" not in self._fields:
|
2021-08-13 12:53:43 +02:00
|
|
|
return self._action_done_original(
|
|
|
|
feedback=feedback, attachment_ids=attachment_ids
|
|
|
|
)
|
|
|
|
# marking as 'done'
|
|
|
|
messages = self.env["mail.message"]
|
|
|
|
next_activities_values = []
|
2018-08-23 01:26:55 +02:00
|
|
|
for activity in self:
|
2021-08-13 12:53:43 +02:00
|
|
|
# extract value to generate next activities
|
2022-01-19 17:10:24 +01:00
|
|
|
if activity.chaining_type == "trigger":
|
|
|
|
vals = activity.with_context(
|
2021-08-13 12:53:43 +02:00
|
|
|
activity_previous_deadline=activity.date_deadline
|
2022-01-19 17:10:24 +01:00
|
|
|
)._prepare_next_activity_values()
|
|
|
|
next_activities_values.append(vals)
|
2021-08-13 12:53:43 +02:00
|
|
|
|
|
|
|
# post message on activity, before deleting it
|
2018-08-23 01:26:55 +02:00
|
|
|
record = self.env[activity.res_model].browse(activity.res_id)
|
|
|
|
activity.done = True
|
2019-06-11 16:42:58 +02:00
|
|
|
activity.active = False
|
2018-08-23 01:26:55 +02:00
|
|
|
activity.date_done = fields.Date.today()
|
|
|
|
record.message_post_with_view(
|
2021-08-13 12:50:46 +02:00
|
|
|
"mail.message_activity_done",
|
2021-08-13 12:53:43 +02:00
|
|
|
values={
|
|
|
|
"activity": activity,
|
|
|
|
"feedback": feedback,
|
|
|
|
"display_assignee": activity.user_id != self.env.user,
|
|
|
|
},
|
2022-01-19 17:10:24 +01:00
|
|
|
subtype_id=self.env["ir.model.data"]._xmlid_to_res_id(
|
2021-08-13 12:53:43 +02:00
|
|
|
"mail.mt_activities"
|
|
|
|
),
|
2018-08-23 01:26:55 +02:00
|
|
|
mail_activity_type_id=activity.activity_type_id.id,
|
2022-01-19 17:10:24 +01:00
|
|
|
attachment_ids=[
|
|
|
|
Command.link(attachment_id) for attachment_id in attachment_ids
|
|
|
|
]
|
2021-08-13 12:53:43 +02:00
|
|
|
if attachment_ids
|
|
|
|
else [],
|
2018-08-23 01:26:55 +02:00
|
|
|
)
|
2021-08-13 12:53:43 +02:00
|
|
|
messages |= record.message_ids[0]
|
|
|
|
|
|
|
|
next_activities = self.env["mail.activity"].create(next_activities_values)
|
|
|
|
|
|
|
|
return messages, next_activities
|
2018-08-23 01:26:55 +02:00
|
|
|
|
2021-08-13 12:53:43 +02:00
|
|
|
if not hasattr(MailActivity, "_action_done_original"):
|
|
|
|
MailActivity._action_done_original = MailActivity._action_done
|
|
|
|
MailActivity._action_done = _new_action_done
|
2019-05-07 17:25:20 +02:00
|
|
|
|
|
|
|
|
|
|
|
def uninstall_hook(cr, registry):
|
2021-08-13 12:50:46 +02:00
|
|
|
"""The objective of this hook is to remove all activities that are done
|
|
|
|
upon module uninstall
|
|
|
|
"""
|
2019-05-07 17:25:20 +02:00
|
|
|
cr.execute(
|
|
|
|
"""
|
|
|
|
DELETE FROM mail_activity
|
|
|
|
WHERE done=True
|
|
|
|
"""
|
|
|
|
)
|