[MIG] mail_activity_team: Migration to 15.0

This commit is contained in:
Bernat Puig Font 2022-01-17 12:45:08 +01:00
parent c1c26b72aa
commit d916ef3f49
11 changed files with 142 additions and 141 deletions

View File

@ -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",
],
},
}

View File

@ -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
@ -11,7 +11,7 @@ class MailActivity(models.Model):
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(
@ -74,6 +74,10 @@ class MailActivity(models.Model):
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,
)
)

View File

@ -18,6 +18,22 @@ class MailActivityMixin(models.AbstractModel):
for rec in self:
rec.activity_team_user_ids = rec.activity_ids.mapped("team_id.member_ids")
def _search_my_activity_date_deadline(self, operator, operand):
if not self._context.get("team_activities", False):
return super(MailActivityMixin, self)._search_my_activity_date_deadline(
operator, operand
)
activity_ids = self.env["mail.activity"]._search(
[
"|",
("user_id", "=", self.env.user.id),
"&",
("date_deadline", operator, operand),
("res_model", "=", self._name),
]
)
return [("activity_ids", "in", activity_ids)]
@api.model
def _search_activity_team_user_ids(self, operator, operand):
return [("activity_ids.team_id.member_ids", operator, operand)]

View File

@ -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
@ -19,8 +19,8 @@ class MailActivityTeam(models.Model):
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",

View File

@ -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
@ -44,7 +44,7 @@ class ResUsers(models.Model):
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:
@ -66,9 +66,4 @@ class ResUsers(models.Model):
] += 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())

View File

@ -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

View File

@ -0,0 +1 @@
* In next version systray.esm.js file should be changed as added in comments.

View File

@ -0,0 +1,94 @@
/** @odoo-module **/
import ActivityMenu from "@mail/js/systray/systray_activity_menu";
import {session} from "@web/session";
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";
this.user_context = session.user_context;
this.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");
self.user_context = _.extend({}, session.user_context, {
team_activities: self.filter === "team",
});
self._updateActivityPreview();
},
_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 = {};
context.team_activities = 1;
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,
});
}
},
_getActivityData: function () {
var self = this;
return self
._rpc({
model: "res.users",
method: "systray_get_activities",
args: [],
kwargs: {context: self.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);
});
},
});

View File

@ -1,102 +0,0 @@
odoo.define("mail_activity_team.systray.ActivityMenu", function (require) {
"use strict";
var ActivityMenu = require("mail.systray.ActivityMenu");
var session = require("web.session");
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",
});
self._updateActivityPreview();
},
_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,
});
}
},
_getActivityData: function () {
var self = this;
return self._super.apply(self, arguments).then(function () {
session.user_context = _.extend({}, session.user_context, {
team_activities: !session.user_context.team_activities,
});
self._rpc({
model: "res.users",
method: "systray_get_activities",
args: [],
kwargs: {
context: session.user_context,
},
}).then(function (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);
session.user_context = _.extend({}, session.user_context, {
team_activities: !session.user_context.team_activities,
});
});
});
},
});
});

View File

@ -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.exceptions import ValidationError
from odoo.tests.common import TransactionCase
@ -48,7 +48,7 @@ class TestMailActivityTeam(TransactionCase):
"delay_count": 5,
"delay_unit": "days",
"summary": "ACT 1 : Presentation, barbecue, ... ",
"res_model_id": self.partner_ir_model.id,
"res_model": self.partner_ir_model.model,
}
)
self.activity2 = activity_type_model.create(
@ -57,7 +57,7 @@ class TestMailActivityTeam(TransactionCase):
"delay_count": 6,
"delay_unit": "days",
"summary": "ACT 2 : I want to show you my ERP !",
"res_model_id": self.partner_ir_model.id,
"res_model": self.partner_ir_model.model,
}
)
@ -148,7 +148,6 @@ class TestMailActivityTeam(TransactionCase):
self.assertEqual(
self.act2.team_id, self.team1, "Error: Activity 2 should have Team 1."
)
self.act2.team_id = False
self.act2._onchange_team_id()
self.assertEqual(self.act2.user_id, self.employee)
self.act2.team_id = self.team2
@ -174,7 +173,7 @@ class TestMailActivityTeam(TransactionCase):
def test_schedule_activity(self):
"""Correctly assign teams to auto scheduled activities. Those won't
trigger onchanges and could raise constraints and team missmatches"""
partner_record = self.employee.partner_id.sudo(self.employee.id)
partner_record = self.employee.partner_id.with_user(self.employee.id)
activity = partner_record.activity_schedule(
user_id=self.employee2.id,
activity_type_id=self.env.ref("mail.mail_activity_data_call").id,

View File

@ -1,11 +0,0 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<template id="assets_backend" name="mail assets" inherit_id="web.assets_backend">
<xpath expr="." position="inside">
<script
type="text/javascript"
src="/mail_activity_team/static/src/js/systray.js"
/>
</xpath>
</template>
</odoo>