commit
40d2c6854a
@ -15,6 +15,7 @@
|
|||||||
"data": [
|
"data": [
|
||||||
"security/ir.model.access.csv",
|
"security/ir.model.access.csv",
|
||||||
"security/mail_activity_team_security.xml",
|
"security/mail_activity_team_security.xml",
|
||||||
|
"views/mail_activity_type.xml",
|
||||||
"views/mail_activity_team_views.xml",
|
"views/mail_activity_team_views.xml",
|
||||||
"views/mail_activity_views.xml",
|
"views/mail_activity_views.xml",
|
||||||
"views/res_users_views.xml",
|
"views/res_users_views.xml",
|
||||||
|
@ -2,3 +2,4 @@ from . import mail_activity_team
|
|||||||
from . import mail_activity
|
from . import mail_activity
|
||||||
from . import mail_activity_mixin
|
from . import mail_activity_mixin
|
||||||
from . import res_users
|
from . import res_users
|
||||||
|
from . import mail_activity_type
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
# Copyright 2018-22 ForgeFlow S.L.
|
# Copyright 2018-22 ForgeFlow S.L.
|
||||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||||
|
|
||||||
from odoo import SUPERUSER_ID, _, api, fields, models
|
from odoo import SUPERUSER_ID, _, api, fields, models
|
||||||
from odoo.exceptions import ValidationError
|
from odoo.exceptions import ValidationError
|
||||||
|
|
||||||
@ -19,41 +20,32 @@ class MailActivity(models.Model):
|
|||||||
)
|
)
|
||||||
return self.env["mail.activity.team"].search(domain, limit=1)
|
return self.env["mail.activity.team"].search(domain, limit=1)
|
||||||
|
|
||||||
|
user_id = fields.Many2one(required=False)
|
||||||
|
team_user_id = fields.Many2one(related="user_id", readonly=False)
|
||||||
|
|
||||||
team_id = fields.Many2one(
|
team_id = fields.Many2one(
|
||||||
comodel_name="mail.activity.team", default=lambda s: s._get_default_team_id()
|
comodel_name="mail.activity.team", default=lambda s: s._get_default_team_id()
|
||||||
)
|
)
|
||||||
|
|
||||||
@api.onchange("user_id")
|
@api.onchange("user_id")
|
||||||
def _onchange_user_id(self):
|
def _onchange_user_id(self):
|
||||||
res = {"domain": {"team_id": []}}
|
if not self.user_id or (
|
||||||
if not self.user_id:
|
self.team_id and self.user_id in self.team_id.member_ids
|
||||||
return res
|
):
|
||||||
res["domain"]["team_id"] = [
|
return
|
||||||
"|",
|
|
||||||
("res_model_ids", "=", False),
|
|
||||||
("res_model_ids", "in", self.res_model_id.ids),
|
|
||||||
]
|
|
||||||
if self.team_id and self.user_id in self.team_id.member_ids:
|
|
||||||
return res
|
|
||||||
self.team_id = self.with_context(
|
self.team_id = self.with_context(
|
||||||
default_res_model=self.res_model_id.id
|
default_res_model=self.sudo().res_model_id.model
|
||||||
)._get_default_team_id(user_id=self.user_id.id)
|
)._get_default_team_id(user_id=self.user_id.id)
|
||||||
return res
|
|
||||||
|
|
||||||
@api.onchange("team_id")
|
@api.onchange("team_id")
|
||||||
def _onchange_team_id(self):
|
def _onchange_team_id(self):
|
||||||
res = {"domain": {"user_id": []}}
|
if self.team_id and self.user_id not in self.team_id.member_ids:
|
||||||
if not self.team_id:
|
|
||||||
return res
|
|
||||||
res["domain"]["user_id"] = [("id", "in", self.team_id.member_ids.ids)]
|
|
||||||
if self.user_id not in self.team_id.member_ids:
|
|
||||||
if self.team_id.user_id:
|
if self.team_id.user_id:
|
||||||
self.user_id = self.team_id.user_id
|
self.user_id = self.team_id.user_id
|
||||||
elif len(self.team_id.member_ids) == 1:
|
elif len(self.team_id.member_ids) == 1:
|
||||||
self.user_id = self.team_id.member_ids
|
self.user_id = self.team_id.member_ids
|
||||||
else:
|
else:
|
||||||
self.user_id = self.env["res.users"]
|
self.user_id = self.env["res.users"]
|
||||||
return res
|
|
||||||
|
|
||||||
@api.constrains("team_id", "user_id")
|
@api.constrains("team_id", "user_id")
|
||||||
def _check_team_and_user(self):
|
def _check_team_and_user(self):
|
||||||
@ -81,3 +73,13 @@ class MailActivity(models.Model):
|
|||||||
team_name=activity.team_id.name,
|
team_name=activity.team_id.name,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@api.onchange("activity_type_id")
|
||||||
|
def _onchange_activity_type_id(self):
|
||||||
|
res = super(MailActivity, self)._onchange_activity_type_id()
|
||||||
|
if self.activity_type_id.default_team_id:
|
||||||
|
self.team_id = self.activity_type_id.default_team_id
|
||||||
|
members = self.activity_type_id.default_team_id.member_ids
|
||||||
|
if self.user_id not in members and members:
|
||||||
|
self.user_id = members[:1]
|
||||||
|
return res
|
||||||
|
@ -46,16 +46,35 @@ class MailActivityMixin(models.AbstractModel):
|
|||||||
user-team missmatch. We can hook onto `act_values` dict as it's passed
|
user-team missmatch. We can hook onto `act_values` dict as it's passed
|
||||||
to the create activity method.
|
to the create activity method.
|
||||||
"""
|
"""
|
||||||
user_id = act_values.get("user_id")
|
if "team_id" not in act_values:
|
||||||
if user_id:
|
if act_type_xmlid:
|
||||||
team = (
|
activity_type = self.sudo().env.ref(act_type_xmlid)
|
||||||
self.env["mail.activity"]
|
else:
|
||||||
.with_context(
|
activity_type = (
|
||||||
default_res_model=self._name,
|
self.env["mail.activity.type"]
|
||||||
|
.sudo()
|
||||||
|
.browse(act_values["activity_type_id"])
|
||||||
)
|
)
|
||||||
._get_default_team_id(user_id=user_id)
|
if activity_type.default_team_id:
|
||||||
)
|
act_values.update({"team_id": activity_type.default_team_id.id})
|
||||||
act_values.update({"team_id": team.id})
|
if (
|
||||||
|
not act_values.get("user_id")
|
||||||
|
and activity_type.default_team_id.member_ids
|
||||||
|
):
|
||||||
|
act_values.update(
|
||||||
|
{"user_id": activity_type.default_team_id.member_ids[:1].id}
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
user_id = act_values.get("user_id")
|
||||||
|
if user_id:
|
||||||
|
team = (
|
||||||
|
self.env["mail.activity"]
|
||||||
|
.with_context(
|
||||||
|
default_res_model=self._name,
|
||||||
|
)
|
||||||
|
._get_default_team_id(user_id=user_id)
|
||||||
|
)
|
||||||
|
act_values.update({"team_id": team.id})
|
||||||
return super().activity_schedule(
|
return super().activity_schedule(
|
||||||
act_type_xmlid=act_type_xmlid,
|
act_type_xmlid=act_type_xmlid,
|
||||||
date_deadline=date_deadline,
|
date_deadline=date_deadline,
|
||||||
|
11
mail_activity_team/models/mail_activity_type.py
Normal file
11
mail_activity_team/models/mail_activity_type.py
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
# Copyright 2022 CreuBlanca
|
||||||
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||||
|
|
||||||
|
from odoo import fields, models
|
||||||
|
|
||||||
|
|
||||||
|
class MailActivityType(models.Model):
|
||||||
|
|
||||||
|
_inherit = "mail.activity.type"
|
||||||
|
|
||||||
|
default_team_id = fields.Many2one(comodel_name="mail.activity.team")
|
@ -14,7 +14,7 @@ class ResUsers(models.Model):
|
|||||||
|
|
||||||
@api.model
|
@api.model
|
||||||
def systray_get_activities(self):
|
def systray_get_activities(self):
|
||||||
if not self._context.get("team_activities", False):
|
if not self.env.context.get("team_activities"):
|
||||||
return super().systray_get_activities()
|
return super().systray_get_activities()
|
||||||
query = """SELECT m.id, count(*), act.res_model as model,
|
query = """SELECT m.id, count(*), act.res_model as model,
|
||||||
CASE
|
CASE
|
||||||
@ -64,6 +64,9 @@ class ResUsers(models.Model):
|
|||||||
user_activities[activity["model"]][
|
user_activities[activity["model"]][
|
||||||
"%s_count" % activity["states"]
|
"%s_count" % activity["states"]
|
||||||
] += activity["count"]
|
] += activity["count"]
|
||||||
if activity["states"] in ("today", "overdue"):
|
if (
|
||||||
|
activity["states"] in ("today", "overdue")
|
||||||
|
and activity["user_id"] != user
|
||||||
|
):
|
||||||
user_activities[activity["model"]]["total_count"] += activity["count"]
|
user_activities[activity["model"]]["total_count"] += activity["count"]
|
||||||
return list(user_activities.values())
|
return list(user_activities.values())
|
||||||
|
@ -11,10 +11,11 @@ ActivityMenu.include({
|
|||||||
this.$filter_buttons = this.$(".o_filter_button");
|
this.$filter_buttons = this.$(".o_filter_button");
|
||||||
this.$my_activities = this.$filter_buttons.first();
|
this.$my_activities = this.$filter_buttons.first();
|
||||||
this.filter = "my";
|
this.filter = "my";
|
||||||
this.user_context = session.user_context;
|
this._update_team_activities_context();
|
||||||
this.user_context = _.extend({}, session.user_context, {
|
},
|
||||||
team_activities: false,
|
|
||||||
});
|
_update_team_activities_context: function () {
|
||||||
|
session.user_context.team_activities = this.filter === "team";
|
||||||
},
|
},
|
||||||
|
|
||||||
_updateCounter: function () {
|
_updateCounter: function () {
|
||||||
@ -23,18 +24,13 @@ ActivityMenu.include({
|
|||||||
},
|
},
|
||||||
|
|
||||||
_onClickFilterButton: function (event) {
|
_onClickFilterButton: function (event) {
|
||||||
var self = this;
|
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
self.$filter_buttons.removeClass("active");
|
this.$filter_buttons.removeClass("active");
|
||||||
var $target = $(event.currentTarget);
|
var $target = $(event.currentTarget);
|
||||||
$target.addClass("active");
|
$target.addClass("active");
|
||||||
self.filter = $target.data("filter");
|
this.filter = $target.data("filter");
|
||||||
|
this._update_team_activities_context();
|
||||||
self.user_context = _.extend({}, session.user_context, {
|
this._updateActivityPreview();
|
||||||
team_activities: self.filter === "team",
|
|
||||||
});
|
|
||||||
|
|
||||||
self._updateActivityPreview();
|
|
||||||
},
|
},
|
||||||
_onActivityFilterClick: function (event) {
|
_onActivityFilterClick: function (event) {
|
||||||
if (this.filter === "my") {
|
if (this.filter === "my") {
|
||||||
@ -63,12 +59,21 @@ ActivityMenu.include({
|
|||||||
[false, "form"],
|
[false, "form"],
|
||||||
],
|
],
|
||||||
search_view_id: [false],
|
search_view_id: [false],
|
||||||
domain: [["activity_team_user_ids", "in", session.uid]],
|
domain: [["activity_team_user_ids", "in", [session.uid]]],
|
||||||
context: context,
|
context: context,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
_open_boards_activities_domain: function () {
|
||||||
|
if (this.filter === "team") {
|
||||||
|
return {additional_context: {search_default_my_team_activities: 1}};
|
||||||
|
}
|
||||||
|
return this._super.apply(this, arguments);
|
||||||
|
},
|
||||||
_getActivityData: function () {
|
_getActivityData: function () {
|
||||||
|
if (this.filter !== "team") {
|
||||||
|
return this._super.apply(this, arguments);
|
||||||
|
}
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
return self
|
return self
|
||||||
@ -76,7 +81,7 @@ ActivityMenu.include({
|
|||||||
model: "res.users",
|
model: "res.users",
|
||||||
method: "systray_get_activities",
|
method: "systray_get_activities",
|
||||||
args: [],
|
args: [],
|
||||||
kwargs: {context: self.user_context},
|
kwargs: {context: session.user_context},
|
||||||
})
|
})
|
||||||
.then(function (data) {
|
.then(function (data) {
|
||||||
self._activities = data;
|
self._activities = data;
|
||||||
@ -89,6 +94,17 @@ ActivityMenu.include({
|
|||||||
);
|
);
|
||||||
self.$(".o_notification_counter").text(self.activityCounter);
|
self.$(".o_notification_counter").text(self.activityCounter);
|
||||||
self.$el.toggleClass("o_no_notification", !self.activityCounter);
|
self.$el.toggleClass("o_no_notification", !self.activityCounter);
|
||||||
|
// Unset context after we gather the info to avoid side effects
|
||||||
|
session.user_context.team_activities = false;
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
_onActivityMenuHide: function () {
|
||||||
|
this.filter = "my";
|
||||||
|
this._update_team_activities_context();
|
||||||
|
this._getActivityData();
|
||||||
|
this.$filter_buttons.removeClass("active");
|
||||||
|
var $target = $(".my_activities");
|
||||||
|
$target.addClass("active");
|
||||||
|
return this._super.apply(this, arguments);
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
@ -7,13 +7,13 @@
|
|||||||
<div>
|
<div>
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
class="btn btn-link o_filter_button active"
|
class="my_activities btn btn-link o_filter_button active"
|
||||||
data-filter='my'
|
data-filter='my'
|
||||||
role="tab"
|
role="tab"
|
||||||
> My Activities </button>
|
> My Activities </button>
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
class="btn btn-link o_filter_button"
|
class="team_activities btn btn-link o_filter_button"
|
||||||
data-filter='team'
|
data-filter='team'
|
||||||
role="tab"
|
role="tab"
|
||||||
> Team Activities </button>
|
> Team Activities </button>
|
||||||
|
@ -1,13 +1,15 @@
|
|||||||
# Copyright 2018-22 ForgeFlow S.L.
|
# Copyright 2018-22 ForgeFlow S.L.
|
||||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||||
|
|
||||||
from odoo.exceptions import ValidationError
|
from odoo.exceptions import ValidationError
|
||||||
from odoo.tests.common import TransactionCase
|
from odoo.tests.common import Form, TransactionCase
|
||||||
|
|
||||||
|
|
||||||
class TestMailActivityTeam(TransactionCase):
|
class TestMailActivityTeam(TransactionCase):
|
||||||
def setUp(self):
|
@classmethod
|
||||||
super(TestMailActivityTeam, self).setUp()
|
def setUpClass(cls):
|
||||||
|
super().setUpClass()
|
||||||
|
self = cls
|
||||||
self.env["mail.activity.team"].search([]).unlink()
|
self.env["mail.activity.team"].search([]).unlink()
|
||||||
|
|
||||||
self.employee = self.env["res.users"].create(
|
self.employee = self.env["res.users"].create(
|
||||||
@ -125,6 +127,18 @@ class TestMailActivityTeam(TransactionCase):
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def test_activity_members(self):
|
||||||
|
self.team1.member_ids |= self.employee2
|
||||||
|
self.partner_client.refresh()
|
||||||
|
self.assertIn(self.employee2, self.partner_client.activity_team_user_ids)
|
||||||
|
self.assertIn(self.employee, self.partner_client.activity_team_user_ids)
|
||||||
|
self.assertEqual(
|
||||||
|
self.partner_client,
|
||||||
|
self.env["res.partner"].search(
|
||||||
|
[("activity_team_user_ids", "=", self.employee.id)]
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
def test_team_and_user_onchange(self):
|
def test_team_and_user_onchange(self):
|
||||||
with self.assertRaises(ValidationError):
|
with self.assertRaises(ValidationError):
|
||||||
self.team1.member_ids = [(3, self.employee.id)]
|
self.team1.member_ids = [(3, self.employee.id)]
|
||||||
@ -144,31 +158,83 @@ class TestMailActivityTeam(TransactionCase):
|
|||||||
self.team2._onchange_user_id()
|
self.team2._onchange_user_id()
|
||||||
self.assertTrue(self.employee3 in self.team2.member_ids)
|
self.assertTrue(self.employee3 in self.team2.member_ids)
|
||||||
|
|
||||||
def test_activity_onchanges(self):
|
def test_activity_onchanges_keep_user(self):
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
self.act2.team_id, self.team1, "Error: Activity 2 should have Team 1."
|
self.act2.team_id, self.team1, "Error: Activity 2 should have Team 1."
|
||||||
)
|
)
|
||||||
self.act2._onchange_team_id()
|
with Form(self.act2) as form:
|
||||||
self.assertEqual(self.act2.user_id, self.employee)
|
form.team_id = self.env["mail.activity.team"]
|
||||||
self.act2.team_id = self.team2
|
self.assertEqual(form.user_id, self.employee)
|
||||||
self.act2._onchange_team_id()
|
|
||||||
self.assertEqual(self.act2.user_id, self.employee)
|
def test_activity_onchanges_user_no_member_team(self):
|
||||||
self.act2.user_id = self.employee2
|
self.assertEqual(
|
||||||
self.act2._onchange_user_id()
|
self.act2.team_id, self.team1, "Error: Activity 2 should have Team 1."
|
||||||
self.assertEqual(self.act2.team_id, self.team2)
|
)
|
||||||
|
with Form(self.act2) as form:
|
||||||
|
form.user_id = self.employee2
|
||||||
|
self.assertEqual(form.team_id, self.team2)
|
||||||
|
|
||||||
|
def test_activity_onchanges_user_no_team(self):
|
||||||
|
self.assertEqual(
|
||||||
|
self.act2.team_id, self.team1, "Error: Activity 2 should have Team 1."
|
||||||
|
)
|
||||||
|
with Form(self.act2) as form:
|
||||||
|
form.team_id = self.env["mail.activity.team"]
|
||||||
|
form.user_id = self.employee2
|
||||||
|
self.assertEqual(form.team_id, self.team2)
|
||||||
|
|
||||||
|
def test_activity_onchanges_team_no_member(self):
|
||||||
|
self.assertEqual(
|
||||||
|
self.act2.team_id, self.team1, "Error: Activity 2 should have Team 1."
|
||||||
|
)
|
||||||
|
self.team2.user_id = False
|
||||||
|
self.team2.member_ids = False
|
||||||
|
with Form(self.act2) as form:
|
||||||
|
form.team_id = self.team2
|
||||||
|
self.assertFalse(form.user_id)
|
||||||
|
|
||||||
|
def test_activity_onchanges_team_different_member(self):
|
||||||
|
self.assertEqual(
|
||||||
|
self.act2.team_id, self.team1, "Error: Activity 2 should have Team 1."
|
||||||
|
)
|
||||||
|
self.team2.user_id = self.employee2
|
||||||
|
self.team2.member_ids = self.employee2
|
||||||
|
with Form(self.act2) as form:
|
||||||
|
form.team_id = self.team2
|
||||||
|
self.assertEqual(form.user_id, self.employee2)
|
||||||
|
|
||||||
|
def test_activity_onchanges_team_different_member_no_leader(self):
|
||||||
|
self.assertEqual(
|
||||||
|
self.act2.team_id, self.team1, "Error: Activity 2 should have Team 1."
|
||||||
|
)
|
||||||
|
self.team2.user_id = False
|
||||||
|
self.team2.member_ids = self.employee2
|
||||||
|
with Form(self.act2) as form:
|
||||||
|
form.team_id = self.team2
|
||||||
|
self.assertEqual(form.user_id, self.employee2)
|
||||||
|
|
||||||
|
def test_activity_onchanges_activity_type_set_team(self):
|
||||||
|
self.assertEqual(
|
||||||
|
self.act2.team_id, self.team1, "Error: Activity 2 should have Team 1."
|
||||||
|
)
|
||||||
|
self.activity1.default_team_id = self.team2
|
||||||
|
self.assertEqual(self.act2.activity_type_id, self.activity2)
|
||||||
|
with Form(self.act2) as form:
|
||||||
|
form.activity_type_id = self.activity1
|
||||||
|
self.assertEqual(form.team_id, self.team2)
|
||||||
|
|
||||||
|
def test_activity_onchanges_activity_type_no_team(self):
|
||||||
|
self.assertEqual(
|
||||||
|
self.act2.team_id, self.team1, "Error: Activity 2 should have Team 1."
|
||||||
|
)
|
||||||
|
self.assertEqual(self.act2.activity_type_id, self.activity2)
|
||||||
|
with Form(self.act2) as form:
|
||||||
|
form.activity_type_id = self.activity1
|
||||||
|
self.assertEqual(form.team_id, self.team1)
|
||||||
|
|
||||||
|
def test_activity_constrain(self):
|
||||||
with self.assertRaises(ValidationError):
|
with self.assertRaises(ValidationError):
|
||||||
self.act2.write({"user_id": self.employee2.id, "team_id": self.team1.id})
|
self.act2.write({"user_id": self.employee2.id, "team_id": self.team1.id})
|
||||||
self.team1.user_id = False
|
|
||||||
self.act2.user_id = False
|
|
||||||
self.act2._onchange_user_id()
|
|
||||||
self.team2.member_ids = [(4, self.employee3.id)]
|
|
||||||
self.act2.team_id = self.team1
|
|
||||||
self.act2.team_id = False
|
|
||||||
self.act2.user_id = self.employee3
|
|
||||||
self.act2._onchange_user_id()
|
|
||||||
self.act2.team_id = self.team2
|
|
||||||
self.team2.member_ids = [(3, self.act2.user_id.id)]
|
|
||||||
self.act2._onchange_team_id()
|
|
||||||
|
|
||||||
def test_schedule_activity(self):
|
def test_schedule_activity(self):
|
||||||
"""Correctly assign teams to auto scheduled activities. Those won't
|
"""Correctly assign teams to auto scheduled activities. Those won't
|
||||||
@ -179,3 +245,70 @@ class TestMailActivityTeam(TransactionCase):
|
|||||||
activity_type_id=self.env.ref("mail.mail_activity_data_call").id,
|
activity_type_id=self.env.ref("mail.mail_activity_data_call").id,
|
||||||
)
|
)
|
||||||
self.assertEqual(activity.team_id, self.team2)
|
self.assertEqual(activity.team_id, self.team2)
|
||||||
|
|
||||||
|
def test_schedule_activity_default_team(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.with_user(self.employee.id)
|
||||||
|
self.env.ref("mail.mail_activity_data_call").default_team_id = self.team2
|
||||||
|
activity = partner_record.activity_schedule(
|
||||||
|
act_type_xmlid="mail.mail_activity_data_call",
|
||||||
|
user_id=self.employee2.id,
|
||||||
|
)
|
||||||
|
self.assertEqual(activity.team_id, self.team2)
|
||||||
|
self.assertEqual(activity.user_id, self.employee2)
|
||||||
|
|
||||||
|
def test_schedule_activity_default_team_no_user(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.with_user(self.employee.id)
|
||||||
|
self.activity2.default_team_id = self.team2
|
||||||
|
self.team2.member_ids = self.employee2
|
||||||
|
activity = partner_record.activity_schedule(
|
||||||
|
activity_type_id=self.activity2.id,
|
||||||
|
)
|
||||||
|
self.assertEqual(activity.team_id, self.team2)
|
||||||
|
self.assertEqual(activity.user_id, self.employee2)
|
||||||
|
|
||||||
|
def test_activity_count(self):
|
||||||
|
res = (
|
||||||
|
self.env["res.users"]
|
||||||
|
.with_user(self.employee.id)
|
||||||
|
.with_context(**{"team_activities": True})
|
||||||
|
.systray_get_activities()
|
||||||
|
)
|
||||||
|
self.assertEqual(res[0]["total_count"], 0)
|
||||||
|
self.assertEqual(res[0]["today_count"], 1)
|
||||||
|
partner_record = self.employee.partner_id.with_user(self.employee.id)
|
||||||
|
self.activity2.default_team_id = self.team2
|
||||||
|
activity = partner_record.activity_schedule(
|
||||||
|
activity_type_id=self.activity2.id, user_id=self.employee2.id
|
||||||
|
)
|
||||||
|
activity.flush()
|
||||||
|
res = (
|
||||||
|
self.env["res.users"]
|
||||||
|
.with_user(self.employee.id)
|
||||||
|
.with_context(**{"team_activities": True})
|
||||||
|
.systray_get_activities()
|
||||||
|
)
|
||||||
|
self.assertEqual(res[0]["total_count"], 1)
|
||||||
|
self.assertEqual(res[0]["today_count"], 2)
|
||||||
|
res = self.env["res.users"].with_user(self.employee.id).systray_get_activities()
|
||||||
|
self.assertEqual(res[0]["total_count"], 2)
|
||||||
|
|
||||||
|
def test_activity_schedule_next(self):
|
||||||
|
self.activity1.write(
|
||||||
|
{
|
||||||
|
"default_team_id": self.team1.id,
|
||||||
|
"triggered_next_type_id": self.activity2.id,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
self.activity2.default_team_id = self.team2
|
||||||
|
self.team2.member_ids = self.employee2
|
||||||
|
partner_record = self.employee.partner_id.with_user(self.employee.id)
|
||||||
|
activity = partner_record.activity_schedule(activity_type_id=self.activity1.id)
|
||||||
|
activity.flush()
|
||||||
|
_messages, next_activities = activity._action_done()
|
||||||
|
self.assertTrue(next_activities)
|
||||||
|
self.assertEqual(next_activities.team_id, self.team2)
|
||||||
|
self.assertEqual(next_activities.user_id, self.employee2)
|
||||||
|
22
mail_activity_team/views/mail_activity_type.xml
Normal file
22
mail_activity_team/views/mail_activity_type.xml
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8" ?>
|
||||||
|
<!-- Copyright 2022 CreuBlanca
|
||||||
|
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->
|
||||||
|
<odoo>
|
||||||
|
|
||||||
|
<record model="ir.ui.view" id="mail_activity_type_form_view">
|
||||||
|
<field name="name">mail.activity.type.form (in mail_activity_team)</field>
|
||||||
|
<field name="model">mail.activity.type</field>
|
||||||
|
<field name="inherit_id" ref="mail.mail_activity_type_view_form" />
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<field name="default_user_id" position="after">
|
||||||
|
<field
|
||||||
|
name="default_team_id"
|
||||||
|
options="{'no_create': True, 'no_edit': True}"
|
||||||
|
/>
|
||||||
|
</field>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
</odoo>
|
@ -6,8 +6,22 @@
|
|||||||
<field name="model">mail.activity</field>
|
<field name="model">mail.activity</field>
|
||||||
<field name="inherit_id" ref="mail.mail_activity_view_form_popup" />
|
<field name="inherit_id" ref="mail.mail_activity_view_form_popup" />
|
||||||
<field name="arch" type="xml">
|
<field name="arch" type="xml">
|
||||||
|
<field name="user_id" position="attributes">
|
||||||
|
<attribute
|
||||||
|
name="attrs"
|
||||||
|
>{'invisible': [('team_id', '!=', False)]}</attribute>
|
||||||
|
</field>
|
||||||
<field name="user_id" position="after">
|
<field name="user_id" position="after">
|
||||||
<field name="team_id" options="{'no_create': True, 'no_open': True}" />
|
<field
|
||||||
|
name="team_user_id"
|
||||||
|
attrs="{'invisible': [('team_id', '=', False)]}"
|
||||||
|
domain="[('activity_team_ids', '=', team_id)]"
|
||||||
|
/>
|
||||||
|
<field
|
||||||
|
name="team_id"
|
||||||
|
options="{'no_create': True, 'no_open': True}"
|
||||||
|
domain="['|', ('res_model_ids', '=', False), ('res_model_ids', '=', res_model_id)]"
|
||||||
|
/>
|
||||||
</field>
|
</field>
|
||||||
</field>
|
</field>
|
||||||
</record>
|
</record>
|
||||||
@ -31,8 +45,21 @@
|
|||||||
ref="mail_activity_board.mail_activity_view_form_board"
|
ref="mail_activity_board.mail_activity_view_form_board"
|
||||||
/>
|
/>
|
||||||
<field name="arch" type="xml">
|
<field name="arch" type="xml">
|
||||||
|
<field name="user_id" position="attributes">
|
||||||
|
<attribute
|
||||||
|
name="attrs"
|
||||||
|
>{'invisible': [('team_id', '=', False)]}</attribute>
|
||||||
|
</field>
|
||||||
<field name="user_id" position="after">
|
<field name="user_id" position="after">
|
||||||
<field name="team_id" />
|
<field
|
||||||
|
name="team_user_id"
|
||||||
|
attrs="{'invisible': [('team_id', '!=', False)]}"
|
||||||
|
domain="[('activity_team_ids', '=', team_id)]"
|
||||||
|
/>
|
||||||
|
<field
|
||||||
|
name="team_id"
|
||||||
|
domain="['|', ('res_model_ids', '=', False), ('res_model_ids', '=', res_model_id)]"
|
||||||
|
/>
|
||||||
</field>
|
</field>
|
||||||
</field>
|
</field>
|
||||||
</record>
|
</record>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user