mirror of https://github.com/OCA/social.git
[MIG] mail_activity_reminder: Migration to 16.0
parent
0f29b9ab32
commit
66577ad16b
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
{
|
{
|
||||||
"name": "Mail Activity Reminder",
|
"name": "Mail Activity Reminder",
|
||||||
"version": "13.0.1.0.0",
|
"version": "16.0.1.0.0",
|
||||||
"category": "Discuss",
|
"category": "Discuss",
|
||||||
"website": "https://github.com/OCA/social",
|
"website": "https://github.com/OCA/social",
|
||||||
"author": "CorporateHub, Odoo Community Association (OCA)",
|
"author": "CorporateHub, Odoo Community Association (OCA)",
|
||||||
|
|
|
@ -22,7 +22,6 @@ class MailActivity(models.Model):
|
||||||
string="Last reminder (local)",
|
string="Last reminder (local)",
|
||||||
)
|
)
|
||||||
deadline = fields.Datetime(
|
deadline = fields.Datetime(
|
||||||
string="Deadline",
|
|
||||||
compute="_compute_deadline",
|
compute="_compute_deadline",
|
||||||
compute_sudo=True,
|
compute_sudo=True,
|
||||||
store=True,
|
store=True,
|
||||||
|
@ -99,22 +98,20 @@ class MailActivity(models.Model):
|
||||||
)
|
)
|
||||||
|
|
||||||
def action_notify(self):
|
def action_notify(self):
|
||||||
super().action_notify()
|
res = super().action_notify()
|
||||||
utc_now = fields.Datetime.now().replace(tzinfo=UTC)
|
utc_now = fields.Datetime.now().replace(tzinfo=UTC)
|
||||||
for activity in self:
|
for activity in self:
|
||||||
if activity.last_reminder_local:
|
if activity.last_reminder_local:
|
||||||
continue
|
continue
|
||||||
tz = timezone(activity.user_id.sudo().tz or "UTC")
|
tz = timezone(activity.user_id.sudo().tz or "UTC")
|
||||||
activity.last_reminder_local = utc_now.astimezone(tz).replace(tzinfo=None)
|
activity.last_reminder_local = utc_now.astimezone(tz).replace(tzinfo=None)
|
||||||
|
return res
|
||||||
|
|
||||||
def action_remind(self):
|
def action_remind(self):
|
||||||
"""
|
"""
|
||||||
Group reminders by user and type and send them together
|
Group reminders by user and type and send them together
|
||||||
"""
|
"""
|
||||||
MailThread = self.env["mail.thread"]
|
MailThread = self.env["mail.thread"]
|
||||||
message_activity_assigned = self.env.ref(
|
|
||||||
"mail_activity_reminder.message_activity_assigned"
|
|
||||||
)
|
|
||||||
utc_now = fields.Datetime.now().replace(tzinfo=UTC)
|
utc_now = fields.Datetime.now().replace(tzinfo=UTC)
|
||||||
for user in self.mapped("user_id"):
|
for user in self.mapped("user_id"):
|
||||||
activities = self.filtered(lambda activity: activity.user_id == user)
|
activities = self.filtered(lambda activity: activity.user_id == user)
|
||||||
|
@ -123,9 +120,9 @@ class MailActivity(models.Model):
|
||||||
|
|
||||||
subject = _("Some activities you are assigned too expire soon.")
|
subject = _("Some activities you are assigned too expire soon.")
|
||||||
|
|
||||||
body = message_activity_assigned.render(
|
body = self.env["ir.qweb"]._render(
|
||||||
|
"mail_activity_reminder.message_activity_assigned",
|
||||||
dict(activities=activities, model_description="Activities"),
|
dict(activities=activities, model_description="Activities"),
|
||||||
engine="ir.qweb",
|
|
||||||
minimal_qcontext=True,
|
minimal_qcontext=True,
|
||||||
)
|
)
|
||||||
MailThread.message_notify(
|
MailThread.message_notify(
|
||||||
|
|
|
@ -10,7 +10,6 @@ class MailActivityType(models.Model):
|
||||||
_inherit = "mail.activity.type"
|
_inherit = "mail.activity.type"
|
||||||
|
|
||||||
reminders = fields.Char(
|
reminders = fields.Char(
|
||||||
string="Reminders",
|
|
||||||
help=(
|
help=(
|
||||||
"A non-digit-separated list of offsets (in days) when reminders"
|
"A non-digit-separated list of offsets (in days) when reminders"
|
||||||
' should be fired: e.g. 0 means "on the deadline day" while'
|
' should be fired: e.g. 0 means "on the deadline day" while'
|
||||||
|
|
|
@ -9,7 +9,7 @@ from freezegun import freeze_time
|
||||||
from odoo.tests import common
|
from odoo.tests import common
|
||||||
|
|
||||||
|
|
||||||
class TestMailActivityReminder(common.SavepointCase):
|
class TestMailActivityReminder(common.TransactionCase):
|
||||||
@classmethod
|
@classmethod
|
||||||
def setUpClass(cls):
|
def setUpClass(cls):
|
||||||
super().setUpClass()
|
super().setUpClass()
|
||||||
|
@ -114,7 +114,7 @@ class TestMailActivityReminder(common.SavepointCase):
|
||||||
self.assertEqual(activities, activity)
|
self.assertEqual(activities, activity)
|
||||||
activities.action_remind()
|
activities.action_remind()
|
||||||
|
|
||||||
activity.active = False
|
activity.unlink()
|
||||||
with freeze_time(self.now + relativedelta(days=5)):
|
with freeze_time(self.now + relativedelta(days=5)):
|
||||||
activities = self.MailActivity._get_activities_to_remind()
|
activities = self.MailActivity._get_activities_to_remind()
|
||||||
self.assertFalse(activities)
|
self.assertFalse(activities)
|
||||||
|
|
Loading…
Reference in New Issue