Skip to content

Commit 2534fbe

Browse files
[MIG] mail_activity_done: Migration to 18.0
The functionality is now supported by Odoo, using a similar datamodel: to mark activities done, they are archived instead of unlinked. This is reflected in the way that the state field is computed.
1 parent f38024b commit 2534fbe

File tree

15 files changed

+148
-380
lines changed

15 files changed

+148
-380
lines changed

mail_activity_done/README.rst

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ This module implements the capability to keep activities that have been
3232
completed, for future reporting, by setting them with the boolean
3333
'Done'.
3434

35+
Since Odoo 18.0, this is supported natively by Odoo, depending on the
36+
configuration of the activity types. This module ensures that the option
37+
is active on all existing and new activity types in your setup.
38+
3539
**Table of contents**
3640

3741
.. contents::
@@ -40,15 +44,7 @@ completed, for future reporting, by setting them with the boolean
4044
Usage
4145
=====
4246

43-
To use this module, you need to:
44-
45-
1. Access to an activity from the systray activities menu.
46-
2. Once finished, open the activity and mark it as Done.
47-
48-
To check activities:
49-
50-
1. Go to Settings -> Technical -> Activities
51-
2. To see finished activities filter by Completed Activities
47+
To use this module, you do not need to do anything.
5248

5349
Bug Tracker
5450
===========
@@ -79,6 +75,7 @@ Contributors
7975
- Manuel Regidor <manuel.regidor@sygel.es> (https://www.sygel.es)
8076
- Bernat Puig <bernat.puig@forgeflow.com>
8177
(`www.forgeflow.com <http://www.forgeflow.com>`__)
78+
- Stefan Rijnhart <stefan@opener.amsterdam>
8279

8380
Maintainers
8481
-----------

mail_activity_done/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
from . import models
2-
from .hooks import pre_init_hook, uninstall_hook
2+
from .hooks import post_init_hook

mail_activity_done/__manifest__.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,11 @@
22
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html).
33
{
44
"name": "Mail Activity Done",
5-
"version": "17.0.1.0.0",
5+
"version": "18.0.1.0.0",
66
"author": "ForgeFlow, Odoo Community Association (OCA)",
77
"license": "LGPL-3",
88
"category": "Discuss",
99
"website": "https://github.com/OCA/mail",
1010
"depends": ["mail"],
11-
"data": ["views/mail_activity_views.xml"],
12-
"pre_init_hook": "pre_init_hook",
13-
"uninstall_hook": "uninstall_hook",
11+
"post_init_hook": "post_init_hook",
1412
}

mail_activity_done/hooks.py

Lines changed: 7 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -3,40 +3,16 @@
33
# License AGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
44

55

6-
def pre_init_hook(env):
7-
"""The objective of this hook is to default to false all values of field
8-
'done' of mail.activity
9-
"""
10-
cr = env.cr
11-
cr.execute(
12-
"""SELECT column_name
13-
FROM information_schema.columns
14-
WHERE table_name='mail_activity' AND
15-
column_name='done'"""
16-
)
17-
if not cr.fetchone():
18-
cr.execute(
19-
"""
20-
ALTER TABLE mail_activity ADD COLUMN done boolean;
21-
"""
22-
)
23-
6+
def _set_keep_done(cr):
7+
"""Set keep_done to true for all existing activity types"""
248
cr.execute(
259
"""
26-
UPDATE mail_activity
27-
SET done = False
10+
update mail_activity_type
11+
set keep_done = true
12+
where keep_done is not true
2813
"""
2914
)
3015

3116

32-
def uninstall_hook(env):
33-
"""The objective of this hook is to remove all activities that are done
34-
upon module uninstall
35-
"""
36-
cr = env.cr
37-
cr.execute(
38-
"""
39-
DELETE FROM mail_activity
40-
WHERE done=True
41-
"""
42-
)
17+
def post_init_hook(env):
18+
_set_keep_done(env.cr)
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import logging
2+
3+
from odoo.addons.mail_activity_done.hooks import _set_keep_done
4+
5+
6+
def migrate(cr, version):
7+
"""Deal with possible inconsistencies between active and done.
8+
9+
Set done activities that were not archived to archived.
10+
Warn about possible archived activities that were not done.
11+
"""
12+
logger = logging.getLogger("odoo.addons.mail_activity_done.migrations")
13+
_set_keep_done(cr)
14+
cr.execute(
15+
"update mail_activity set active = false where active and done;",
16+
)
17+
if cr.rowcount:
18+
logger.info(
19+
f"{cr.rowcount} done activities were previously unarchived. They are "
20+
"now set back to archived for Odoo to still consider them done.",
21+
)
22+
cr.execute(
23+
"select id from mail_activity where active is not true and done is not true;",
24+
)
25+
ids = [str(row[0]) for row in cr.fetchall()]
26+
if ids:
27+
logger.warning(
28+
f"{len(ids)} activities were previously archived but not "
29+
"done. Odoo will consider them done now (activities with ids "
30+
f"{','.join(ids)})"
31+
)
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
from . import mail_activity
2-
from . import res_users
1+
from . import mail_activity_type

mail_activity_done/models/mail_activity.py

Lines changed: 0 additions & 92 deletions
This file was deleted.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Copyright 2018-22 ForgeFlow <http://www.forgeflow.com>
2+
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html).
3+
from odoo import fields, models
4+
5+
6+
class MailActivityType(models.Model):
7+
_inherit = "mail.activity.type"
8+
9+
keep_done = fields.Boolean(default=True)

mail_activity_done/models/res_users.py

Lines changed: 0 additions & 59 deletions
This file was deleted.

mail_activity_done/readme/CONTRIBUTORS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@
55
- Radovan Skolnik \<<radovan@skolnik.info>\> (<https://www.kema.sk>)
66
- Manuel Regidor \<<manuel.regidor@sygel.es>\> (<https://www.sygel.es>)
77
- Bernat Puig \<<bernat.puig@forgeflow.com>\> (www.forgeflow.com)
8+
- Stefan Rijnhart \<<stefan@opener.amsterdam>\>

0 commit comments

Comments
 (0)