Skip to content

Commit

Permalink
[MIG] mail_activity_team: Migration to 15.0
Browse files Browse the repository at this point in the history
  • Loading branch information
BernatPForgeFlow committed Jan 20, 2022
1 parent c1c26b7 commit 250eaef
Show file tree
Hide file tree
Showing 10 changed files with 182 additions and 141 deletions.
18 changes: 11 additions & 7 deletions mail_activity_team/__manifest__.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,30 @@
# Copyright 2018 Eficent Business and IT Consulting Services, S.L.
# Copyright 2018-22 ForgeFlow Business and IT Consulting Services, S.L.
# Copyright 2021 Sodexis
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
{
"name": "Mail Activity Team",
"summary": "Add Teams to Activities",
"version": "14.0.1.0.0",
"version": "15.0.1.0.0",
"development_status": "Alpha",
"category": "Social Network",
"website": "https://github.com/OCA/social",
"author": "Eficent, Sodexis, Odoo Community Association (OCA)",
"author": "ForgeFlow, Sodexis, Odoo Community Association (OCA)",
"license": "AGPL-3",
"installable": True,
"depends": ["mail_activity_board"],
"data": [
"views/assets_backend.xml",
"security/ir.model.access.csv",
"security/mail_activity_team_security.xml",
"views/mail_activity_team_views.xml",
"views/mail_activity_views.xml",
"views/res_users_views.xml",
],
"qweb": [
"static/src/xml/systray.xml",
],
"assets": {
"web.assets_backend": [
"mail_activity_team/static/src/js/systray.esm.js",
],
"web.assets_qweb": [
"mail_activity_team/static/src/xml/systray.xml",
],
},
}
12 changes: 8 additions & 4 deletions mail_activity_team/models/mail_activity.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2018 Eficent Business and IT Consulting Services, S.L.
# Copyright 2018-22 ForgeFlow Business and IT Consulting Services, S.L.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo import SUPERUSER_ID, _, api, fields, models
from odoo.exceptions import ValidationError
Expand All @@ -11,7 +11,7 @@ def _get_default_team_id(self, user_id=None):
if not user_id:
user_id = self.env.uid
res_model = self.env.context.get("default_res_model")
model = self.env["ir.model"].search([("model", "=", res_model)], limit=1)
model = self.sudo().env["ir.model"].search([("model", "=", res_model)], limit=1)
domain = [("member_ids", "in", [user_id])]
if res_model:
domain.extend(
Expand Down Expand Up @@ -74,6 +74,10 @@ def _check_team_and_user(self):
not in activity.team_id.with_context(active_test=False).member_ids
):
raise ValidationError(
_("The assigned user %s is not member of the team %s.")
% (activity.user_id.name, activity.team_id.name)
_(
"The assigned user %(user_name)s is "
"not member of the team %(team_name)s.",
user_name=activity.user_id.name,
team_name=activity.team_id.name,
)
)
6 changes: 3 additions & 3 deletions mail_activity_team/models/mail_activity_team.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2018 Eficent Business and IT Consulting Services, S.L.
# Copyright 2018-22 ForgeFlow Business and IT Consulting Services, S.L.
# Copyright 2021 Sodexis
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo import api, fields, models
Expand All @@ -19,8 +19,8 @@ def _compute_missing_activities(self):
domain.append(("res_model_id", "in", team.res_model_ids.ids))
team.count_missing_activities = activity_model.search(domain, count=True)

name = fields.Char(string="Name", required=True, translate=True)
active = fields.Boolean(string="Active", default=True)
name = fields.Char(required=True, translate=True)
active = fields.Boolean(default=True)
res_model_ids = fields.Many2many(
comodel_name="ir.model",
string="Used models",
Expand Down
9 changes: 2 additions & 7 deletions mail_activity_team/models/res_users.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2018 Eficent Business and IT Consulting Services, S.L.
# Copyright 2018-22 ForgeFlow Business and IT Consulting Services, S.L.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo import api, fields, models, modules

Expand Down Expand Up @@ -44,7 +44,7 @@ def systray_get_activities(self):
activity_data = self.env.cr.dictfetchall()
model_ids = [a["id"] for a in activity_data]
model_names = {
n[0]: n[1] for n in self.env["ir.model"].browse(model_ids).name_get()
n[0]: n[1] for n in self.env["ir.model"].sudo().browse(model_ids).name_get()
}
user_activities = {}
for activity in activity_data:
Expand All @@ -66,9 +66,4 @@ def systray_get_activities(self):
] += activity["count"]
if activity["states"] in ("today", "overdue"):
user_activities[activity["model"]]["total_count"] += activity["count"]
if activity["user_id"] == user and activity["states"] in (
"today",
"overdue",
):
user_activities[activity["model"]]["total_count"] -= activity["count"]
return list(user_activities.values())
5 changes: 3 additions & 2 deletions mail_activity_team/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
* `Eficent <https://www.eficent.com>`_:
* `ForgeFlow <https://www.forgeflow.com>`_:

* Jordi Ballester Alomar (jordi.ballester@eficent.com)
* Miquel Raïch (miquel.raich@eficent.com)
* Pedro Gonzalez (pedro.gonzalez@pesol.es)
* Bernat Puig Font (bernat.puig@forgeflow.com)
* Pedro Gonzalez (pedro.gonzalez@pesol.es)
* `Tecnativa <https://www.tecnativa.com>`_:

* David Vidal
1 change: 1 addition & 0 deletions mail_activity_team/readme/ROADMAP.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* In next version systray.esm.js file should be changed as added in comments.
150 changes: 150 additions & 0 deletions mail_activity_team/static/src/js/systray.esm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
/** @odoo-module **/
import ActivityMenu from "@mail/js/systray/systray_activity_menu";
import {qweb as QWeb} from "web.core";
import {session} from "@web/session";
import Time from "web.time";

ActivityMenu.include({
events: _.extend({}, ActivityMenu.prototype.events, {
"click .o_filter_button": "_onClickFilterButton",
}),
start: function () {
this._super.apply(this, arguments);
this.$filter_buttons = this.$(".o_filter_button");
this.$my_activities = this.$filter_buttons.first();
this.filter = "my";
session.user_context = _.extend({}, session.user_context, {
team_activities: false,
});
},

_updateCounter: function () {
this._super.apply(this, arguments);
this.$(".o_notification_counter").text(this.activityCounter);
},

_onClickFilterButton: function (event) {
var self = this;
event.stopPropagation();
self.$filter_buttons.removeClass("active");
var $target = $(event.currentTarget);
$target.addClass("active");
self.filter = $target.data("filter");

session.user_context = _.extend({}, session.user_context, {
team_activities: self.filter === "team",
});

/*
If systray_activity_menu.js session import is like -> import { session } from "@web/session";
_rpc function below can be replaced with:
self._updateActivityPreview();
*/
self._rpc({
model: "res.users",
method: "systray_get_activities",
args: [],
kwargs: {context: session.user_context},
})
.then(function (data) {
self._activities = data;
self.activityCounter = _.reduce(
data,
function (total_count, p_data) {
return total_count + p_data.total_count || 0;
},
0
);
self.$(".o_notification_counter").text(self.activityCounter);
self.$el.toggleClass("o_no_notification", !self.activityCounter);
})
.then(function () {
self._$activitiesPreview.html(
QWeb.render("mail.systray.ActivityMenu.Previews", {
widget: self,
Time: Time,
})
);
});
},
_onActivityFilterClick: function (event) {
if (this.filter === "my") {
this._super.apply(this, arguments);
}
if (this.filter === "team") {
var data = _.extend(
{},
$(event.currentTarget).data(),
$(event.target).data()
);
var context = {};
if (data.filter === "my") {
context.search_default_activities_overdue = 1;
context.search_default_activities_today = 1;
} else {
context["search_default_activities_" + data.filter] = 1;
}
this.do_action({
type: "ir.actions.act_window",
name: data.model_name,
res_model: data.res_model,
views: [
[false, "kanban"],
[false, "form"],
],
search_view_id: [false],
domain: [["activity_team_user_ids", "in", session.uid]],
context: context,
});
}
},
/*
If systray_activity_menu.js session import is like -> import { session } from "@web/session";
_rpc function below can be replaced with:
self._super.apply(self, arguments)
*/
_getActivityData: function () {
var self = this;
return self
._rpc({
model: "res.users",
method: "systray_get_activities",
args: [],
kwargs: {context: session.user_context},
})
.then(function (data) {
self._activities = data;
self.activityCounter = _.reduce(
data,
function (total_count, p_data) {
return total_count + p_data.total_count || 0;
},
0
);
self.$(".o_notification_counter").text(self.activityCounter);
self.$el.toggleClass("o_no_notification", !self.activityCounter);
})
.then(function () {
self._rpc({
model: "res.users",
method: "systray_get_activities",
args: [],
kwargs: {
context: session.user_context,
},
}).then(function (data) {
if (!session.user_context) {
self.activityCounter += _.reduce(
data,
function (total_count, p_data) {
return total_count + p_data.total_count || 0;
},
0
);
}
self.$(".o_notification_counter").text(self.activityCounter);
self.$el.toggleClass("o_no_notification", !self.activityCounter);
});
});
},
});
102 changes: 0 additions & 102 deletions mail_activity_team/static/src/js/systray.js

This file was deleted.

Loading

0 comments on commit 250eaef

Please sign in to comment.