Skip to content

Commit

Permalink
[MIG] mail_activity_team: Migration to 18.0
Browse files Browse the repository at this point in the history
A monkey patch is required on mail.activity's create method to prevent an
unboundError (see odoo/odoo#197864).

In order to open the team activities (Late/Today/Future) from the systray widget,
domain clause mangling is applied in mail.activity.mixin's web_search_read.

Includes OCA/social#1469 that was not ported to 17.0 yet.

Co-authored-by: Wodran Van de Sande <[email protected]>
  • Loading branch information
StefanRijnhart and Wodran14 committed Feb 25, 2025
1 parent cd510f3 commit 72314e7
Show file tree
Hide file tree
Showing 20 changed files with 242 additions and 100 deletions.
4 changes: 3 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ exclude: |
# Ignore test files in addons
/tests/samples/.*|
# You don't usually want a bot to modify your legal texts
(LICENSE.*|COPYING.*)
(LICENSE.*|COPYING.*)|
# Exclude monkeypatches
mail_activity_team/patch.py
default_language_version:
python: python3
node: "22.9.0"
Expand Down
50 changes: 26 additions & 24 deletions mail_activity_team/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ Mail Activity Team
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fsocial-lightgray.png?logo=github
:target: https://github.com/OCA/social/tree/17.0/mail_activity_team
:alt: OCA/social
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fmail-lightgray.png?logo=github
:target: https://github.com/OCA/mail/tree/18.0/mail_activity_team
:alt: OCA/mail
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/social-17-0/social-17-0-mail_activity_team
:target: https://translation.odoo-community.org/projects/mail-18-0/mail-18-0-mail_activity_team
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/social&target_branch=17.0
:target: https://runboat.odoo-community.org/builds?repo=OCA/mail&target_branch=18.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|
Expand Down Expand Up @@ -63,10 +63,10 @@ You can report on the activities assigned to a team going to *Dashboards
Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/social/issues>`_.
Bugs are tracked on `GitHub Issues <https://github.com/OCA/mail/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/social/issues/new?body=module:%20mail_activity_team%0Aversion:%2017.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
`feedback <https://github.com/OCA/mail/issues/new?body=module:%20mail_activity_team%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Expand All @@ -82,33 +82,35 @@ Authors
Contributors
------------

- `ForgeFlow <https://www.forgeflow.com>`__:
- `ForgeFlow <https://www.forgeflow.com>`__:

- Jordi Ballester Alomar ([email protected])
- Miquel Raïch ([email protected])
- Bernat Puig Font ([email protected])
- Jordi Ballester Alomar ([email protected])
- Miquel Raïch ([email protected])
- Bernat Puig Font ([email protected])

- Pedro Gonzalez ([email protected])
- `Tecnativa <https://www.tecnativa.com>`__:
- Pedro Gonzalez ([email protected])
- `Tecnativa <https://www.tecnativa.com>`__:

- David Vidal
- David Vidal

- `Dynapps <https://www.dynapps.eu>`__:
- `Dynapps <https://www.dynapps.eu>`__:

- Raf Ven
- Raf Ven

- [Trobz] (https://trobz.com):
- [Trobz] (https://trobz.com):

- Son Ho [email protected]
- Son Ho [email protected]

- [Camptocamp] (https://camptocamp.com):
- [Camptocamp] (https://camptocamp.com):

- Vincent Van Rossem [email protected]
- Italo Lopes [email protected]
- Vincent Van Rossem [email protected]
- Italo Lopes [email protected]

- `CorporateHub <https://corporatehub.eu/>`__
- `CorporateHub <https://corporatehub.eu/>`__

- Alexey Pelykh [email protected]
- Alexey Pelykh [email protected]

- Stefan Rijnhart ([email protected])

Other credits
-------------
Expand All @@ -129,6 +131,6 @@ OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

This module is part of the `OCA/social <https://github.com/OCA/social/tree/17.0/mail_activity_team>`_ project on GitHub.
This module is part of the `OCA/mail <https://github.com/OCA/mail/tree/18.0/mail_activity_team>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
1 change: 1 addition & 0 deletions mail_activity_team/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
from .hooks import post_load_hook
from . import models
from . import wizard
7 changes: 4 additions & 3 deletions mail_activity_team/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
{
"name": "Mail Activity Team",
"summary": "Add Teams to Activities",
"version": "17.0.2.0.1",
"version": "18.0.1.0.0",
"development_status": "Alpha",
"category": "Social Network",
"website": "https://github.com/OCA/social",
"website": "https://github.com/OCA/mail",
"author": "ForgeFlow, Sodexis, Odoo Community Association (OCA)",
"license": "AGPL-3",
"installable": True,
"depends": ["mail_activity_board"],
"depends": ["mail_activity_board", "web"],
"data": [
"security/ir.model.access.csv",
"security/mail_activity_team_security.xml",
Expand All @@ -30,4 +30,5 @@
"mail_activity_team/static/src/models/*",
],
},
"post_load": "post_load_hook",
}
13 changes: 13 additions & 0 deletions mail_activity_team/hooks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import logging

from odoo.addons.mail.models.mail_activity import MailActivity

from .patch import mail_activity__create

_logger = logging.getLogger(__name__)


def post_load_hook():
"""See patch.py for more info"""
MailActivity.create = mail_activity__create
_logger.info("PATCHED mail's mail.activity create")
26 changes: 26 additions & 0 deletions mail_activity_team/models/mail_activity_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,29 @@ def _compute_my_activity_date_deadline(self):
),
False,
)

@api.model
def web_search_read(
self, domain, specification, offset=0, limit=None, order=None, count_limit=None
):
"""Intercept the queries from the systray widget and apply team search.
This allows the frontend widget to direct the user to their team activities
Late/Today/Future.
"""
if self.env.context.get("team_activities"):
orig_domain = domain
domain = []
for clause in orig_domain:
if isinstance(clause, list | tuple) and clause[0] == "activity_user_id":
domain.append(("activity_team_user_ids", clause[1], clause[2]))
else:
domain.append(clause)
return super().web_search_read(
domain,
specification,
offset=offset,
limit=limit,
order=order,
count_limit=count_limit,
)
10 changes: 5 additions & 5 deletions mail_activity_team/models/res_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ class ResUsers(models.Model):
)

@api.model
def systray_get_activities(self):
def _get_activity_groups(self):
if not self.env.context.get("team_activities"):
return super().systray_get_activities()
return super()._get_activity_groups()
query = """SELECT m.id, count(*), act.res_model as model,
CASE
WHEN %(today)s::date -
Expand Down Expand Up @@ -66,9 +66,9 @@ def systray_get_activities(self):
"overdue_count": 0,
"planned_count": 0,
}
user_activities[activity["model"]][
"%s_count" % activity["states"]
] += activity["count"]
user_activities[activity["model"]][f"{activity['states']}_count"] += (
activity["count"]
)
if (
activity["states"] in ("today", "overdue")
and activity["user_id"] != user
Expand Down
51 changes: 51 additions & 0 deletions mail_activity_team/patch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
from odoo import api, fields

from odoo.addons.mail.models.mail_activity import MailActivity


@api.model_create_multi
def mail_activity__create(self, vals_list):
# Monkeypatch for mail's mail.activity's create method to prevent
# UnboundLocalError: cannot access local variable 'activity' where it is not associated with a value
# which occurs when this module creates activities without a user_id.
# Patch below is according to https://github.com/odoo/odoo/pull/197864
activities = super(MailActivity, self).create(vals_list)

# find partners related to responsible users, separate readable from unreadable
if any(user != self.env.user for user in activities.user_id):
user_partners = activities.user_id.partner_id
readable_user_partners = user_partners._filtered_access('read')
else:
readable_user_partners = self.env.user.partner_id

# when creating activities for other: send a notification to assigned user;
if self.env.context.get('mail_activity_quick_update'):
activities_to_notify = self.env['mail.activity']
else:
activities_to_notify = activities.filtered(lambda act: act.user_id != self.env.user)
if activities_to_notify:
to_sudo = activities_to_notify.filtered(lambda act: act.user_id.partner_id not in readable_user_partners)
other = activities_to_notify - to_sudo
to_sudo.sudo().action_notify()
other.action_notify()

# subscribe (batch by model and user to speedup)
for model, activity_data in activities._classify_by_model().items():
per_user = dict()
for activity in activity_data['activities'].filtered(lambda act: act.user_id):
if activity.user_id not in per_user:
per_user[activity.user_id] = [activity.res_id]
else:
per_user[activity.user_id].append(activity.res_id)
for user, res_ids in per_user.items():
pids = user.partner_id.ids if user.partner_id in readable_user_partners else user.sudo().partner_id.ids
self.env[model].browse(res_ids).message_subscribe(partner_ids=pids)

# send notifications about activity creation
todo_activities = activities.filtered(lambda act: act.date_deadline <= fields.Date.today())
if todo_activities:
# Monkeypatch start
# activity.user_id._bus_send("mail.activity/updated", {"activity_created": True})
todo_activities.user_id._bus_send("mail.activity/updated", {"activity_created": True})
# Monkeypatch end
return activities
1 change: 1 addition & 0 deletions mail_activity_team/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@
- Italo Lopes <[email protected]>
- [CorporateHub](https://corporatehub.eu/)
- Alexey Pelykh <[email protected]>
- Stefan Rijnhart (<[email protected]>)
4 changes: 1 addition & 3 deletions mail_activity_team/security/mail_activity_team_security.xml
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo noupdate="1">

<record id="mail_activity_rule_my_team" model="ir.rule">
<field name="name">mail.activity: user: my team</field>
<field name="model_id" ref="mail.model_mail_activity" />
<field
name="domain_force"
>["|", ('team_id', 'in', user.activity_team_ids.ids), "&amp;", ('team_id', '=', False), ('user_id', '=', user.id)]</field>
<field name="groups" eval="[(4, ref('base.group_user'))]" />
<field name="perm_create" eval="True" />
<field name="perm_create" eval="False" />
<field name="perm_read" eval="False" />
<field name="perm_write" eval="True" />
<field name="perm_unlink" eval="True" />
</record>

</odoo>
9 changes: 5 additions & 4 deletions mail_activity_team/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ <h1 class="title">Mail Activity Team</h1>
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:f57479d7f6e748ab80d1f5de32d806761fe970d6e84f0b056b7e1206b3afd9b5
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Alpha" src="https://img.shields.io/badge/maturity-Alpha-red.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/social/tree/17.0/mail_activity_team"><img alt="OCA/social" src="https://img.shields.io/badge/github-OCA%2Fsocial-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/social-17-0/social-17-0-mail_activity_team"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/social&amp;target_branch=17.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Alpha" src="https://img.shields.io/badge/maturity-Alpha-red.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/mail/tree/18.0/mail_activity_team"><img alt="OCA/mail" src="https://img.shields.io/badge/github-OCA%2Fmail-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/mail-18-0/mail-18-0-mail_activity_team"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/mail&amp;target_branch=18.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>This module adds the possibility to assign teams to activities.</p>
<div class="admonition important">
<p class="first admonition-title">Important</p>
Expand Down Expand Up @@ -410,10 +410,10 @@ <h1><a class="toc-backref" href="#toc-entry-1">Usage</a></h1>
</div>
<div class="section" id="bug-tracker">
<h1><a class="toc-backref" href="#toc-entry-2">Bug Tracker</a></h1>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/social/issues">GitHub Issues</a>.
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/mail/issues">GitHub Issues</a>.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
<a class="reference external" href="https://github.com/OCA/social/issues/new?body=module:%20mail_activity_team%0Aversion:%2017.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<a class="reference external" href="https://github.com/OCA/mail/issues/new?body=module:%20mail_activity_team%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<p>Do not contact contributors directly about support or help with technical issues.</p>
</div>
<div class="section" id="credits">
Expand Down Expand Up @@ -456,6 +456,7 @@ <h2><a class="toc-backref" href="#toc-entry-5">Contributors</a></h2>
<li>Alexey Pelykh <a class="reference external" href="mailto:alexey.pelykh&#64;corphub.eu">alexey.pelykh&#64;corphub.eu</a></li>
</ul>
</li>
<li>Stefan Rijnhart (<a class="reference external" href="mailto:stefan&#64;opener.amsterdam">stefan&#64;opener.amsterdam</a>)</li>
</ul>
</div>
<div class="section" id="other-credits">
Expand All @@ -472,7 +473,7 @@ <h2><a class="toc-backref" href="#toc-entry-7">Maintainers</a></h2>
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/social/tree/17.0/mail_activity_team">OCA/social</a> project on GitHub.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/mail/tree/18.0/mail_activity_team">OCA/mail</a> project on GitHub.</p>
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
t-inherit-mode="extension"
>
<xpath expr="//div[1]" position="before">
<div class="o_mail_systray_dropdown_top">
<div
t-ref="mail_activity_team_dropdown"
class="o_mail_systray_dropdown_top"
>
<ul class="nav nav-pills">
<li class="nav-item cursor-pointer">
<a
Expand Down
7 changes: 3 additions & 4 deletions mail_activity_team/static/src/core/web/activity.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,17 @@
t-inherit-mode="extension"
>
<xpath
expr="//div/div[hasclass('o-mail-Activity-sidebar')]/img"
expr="//div/div[hasclass('o-mail-Activity-sidebar')]/a/img"
position="attributes"
>
<attribute name="t-if">activity.user_id</attribute>
<attribute name="t-if">props.activity.user_id</attribute>
</xpath>
<xpath
expr="//div/div/div[hasclass('o-mail-Activity-info')]/span[hasclass('o-mail-Activity-user')]"
position="attributes"
>
<attribute name="t-if">activity.user_id</attribute>
<attribute name="t-if">props.activity.user_id</attribute>
</xpath>

</t>

</templates>
19 changes: 10 additions & 9 deletions mail_activity_team/static/src/models/activity_menu.esm.js
Original file line number Diff line number Diff line change
@@ -1,37 +1,38 @@
/** @odoo-module */

import {ActivityMenu} from "@mail/core/web/activity_menu";
import {patch} from "@web/core/utils/patch";
import {useRef} from "@odoo/owl";
import {user} from "@web/core/user";

patch(ActivityMenu.prototype, {
setup() {
super.setup();
this.currentFilter = "my";
this.rootRef = useRef("mail_activity_team_dropdown");
},
activateFilter(filter_el) {
this.deactivateButtons();

filter_el.addClass("active");
this.currentFilter = filter_el.data("filter");
filter_el.classList.add("active");
this.currentFilter = filter_el.dataset.filter;
this.updateTeamActivitiesContext();
this.fetchSystrayActivities();
this.store.fetchData({systray_get_activities: true});
},
updateTeamActivitiesContext() {
var active = false;
if (this.currentFilter === "team") {
active = true;
}
this.env.services.orm.user.updateContext({team_activities: active});
user.updateContext({team_activities: active});
},
onBeforeOpen() {
this.env.services.orm.user.updateContext({team_activities: false});
user.updateContext({team_activities: false});
super.onBeforeOpen();
},

deactivateButtons() {
$(".o_filter_nav_item").removeClass("active");
this.rootRef.el.querySelector(".o_filter_nav_item").classList.remove("active");
},
onClickActivityFilter(filter) {
this.activateFilter($("." + filter));
this.activateFilter(this.rootRef.el.querySelector("." + filter));
},
});
Loading

0 comments on commit 72314e7

Please sign in to comment.