-
-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[MIG] mail_activity_team: Migration to 18.0
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
1 parent
cd510f3
commit 72314e7
Showing
20 changed files
with
242 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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| | ||
|
@@ -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. | ||
|
||
|
@@ -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 | ||
------------- | ||
|
@@ -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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,3 +14,4 @@ | |
- Italo Lopes <[email protected]> | ||
- [CorporateHub](https://corporatehub.eu/) | ||
- Alexey Pelykh <[email protected]> | ||
- Stefan Rijnhart (<[email protected]>) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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), "&", ('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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
}, | ||
}); |
Oops, something went wrong.