diff --git a/mail_activity_team/README.rst b/mail_activity_team/README.rst index 5a31c52cc7..832bf56980 100644 --- a/mail_activity_team/README.rst +++ b/mail_activity_team/README.rst @@ -101,6 +101,11 @@ Contributors - Son Ho sonhd@trobz.com +- [Camptocamp] (https://camptocamp.com): + + - Vincent Van Rossem vincent.vanrossem@camptocamp.com + - Italo Lopes italo.lopes@camptocamp.com + Other credits ------------- diff --git a/mail_activity_team/__init__.py b/mail_activity_team/__init__.py index 0650744f6b..9b4296142f 100644 --- a/mail_activity_team/__init__.py +++ b/mail_activity_team/__init__.py @@ -1 +1,2 @@ from . import models +from . import wizard diff --git a/mail_activity_team/__manifest__.py b/mail_activity_team/__manifest__.py index 33444635d3..00b1d60754 100644 --- a/mail_activity_team/__manifest__.py +++ b/mail_activity_team/__manifest__.py @@ -1,6 +1,7 @@ # Copyright 2018-22 ForgeFlow 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", @@ -15,6 +16,7 @@ "data": [ "security/ir.model.access.csv", "security/mail_activity_team_security.xml", + "wizard/mail_activity_schedule.xml", "views/ir_actions_server_views.xml", "views/mail_activity_type.xml", "views/mail_activity_team_views.xml", @@ -24,6 +26,7 @@ "assets": { "web.assets_backend": [ "mail_activity_team/static/src/components/*/*", + "mail_activity_team/static/src/core/*/*", "mail_activity_team/static/src/models/*", ], }, diff --git a/mail_activity_team/models/mail_activity.py b/mail_activity_team/models/mail_activity.py index 49641addfd..c3b3220dcd 100644 --- a/mail_activity_team/models/mail_activity.py +++ b/mail_activity_team/models/mail_activity.py @@ -20,7 +20,7 @@ def _get_default_team_id(self, user_id=None): ) return self.env["mail.activity.team"].search(domain, limit=1) - user_id = fields.Many2one(string="User", required=False) + user_id = fields.Many2one(string="User", required=False, default=False) team_user_id = fields.Many2one( string="Team user", related="user_id", readonly=False ) @@ -31,6 +31,24 @@ def _get_default_team_id(self, user_id=None): index=True, ) + @api.model_create_multi + def create(self, vals_list): + # Differently from the previous odoo version, + # the create method is called from (mail.activity.mixin).activity_schedule() + # and on this method we are forcing the user_id to be the current user from + # odoo import api, fields, models the default one linked to the activity type. + # We don't want this behavior because using the team_id, we want to assign the + # activity to the whole team. + for vals in vals_list: + # we need to be sure that we are in a context where the team_id is set, + # and we don't want to use user_id + if "team_id" in vals: + # using team, we have user_id = team_user_id, + # so if we don't have a user_team_id we don't want user_id too + if "user_id" in vals and not vals.get("team_user_id", False): + del vals["user_id"] + return super().create(vals_list) + @api.onchange("user_id") def _onchange_user_id(self): if not self.user_id or ( diff --git a/mail_activity_team/readme/CONTRIBUTORS.md b/mail_activity_team/readme/CONTRIBUTORS.md index 85b9598b77..889edd54c1 100644 --- a/mail_activity_team/readme/CONTRIBUTORS.md +++ b/mail_activity_team/readme/CONTRIBUTORS.md @@ -9,3 +9,6 @@ - Raf Ven - [Trobz] (https://trobz.com): - Son Ho +- [Camptocamp] (https://camptocamp.com): + - Vincent Van Rossem + - Italo Lopes diff --git a/mail_activity_team/static/description/index.html b/mail_activity_team/static/description/index.html index 31e4e0bcfb..e740b33447 100644 --- a/mail_activity_team/static/description/index.html +++ b/mail_activity_team/static/description/index.html @@ -8,11 +8,10 @@ /* :Author: David Goodger (goodger@python.org) -:Id: $Id: html4css1.css 9511 2024-01-13 09:50:07Z milde $ +:Id: $Id: html4css1.css 8954 2022-01-20 10:10:25Z milde $ :Copyright: This stylesheet has been placed in the public domain. Default cascading style sheet for the HTML output of Docutils. -Despite the name, some widely supported CSS2 features are used. See https://docutils.sourceforge.io/docs/howto/html-stylesheets.html for how to customize this style sheet. @@ -275,7 +274,7 @@ margin-left: 2em ; margin-right: 2em } -pre.code .ln { color: gray; } /* line numbers */ +pre.code .ln { color: grey; } /* line numbers */ pre.code, code { background-color: #eeeeee } pre.code .comment, code .comment { color: #5C6576 } pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold } @@ -301,7 +300,7 @@ span.pre { white-space: pre } -span.problematic, pre.problematic { +span.problematic { color: red } span.section-subtitle { @@ -447,6 +446,11 @@

Contributors

  • Son Ho sonhd@trobz.com
  • +
  • [Camptocamp] (https://camptocamp.com): +
  • @@ -457,9 +461,7 @@

    Other credits

    Maintainers

    This module is maintained by the OCA.

    - -Odoo Community Association - +Odoo Community Association

    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.

    diff --git a/mail_activity_team/static/src/core/web/activity.xml b/mail_activity_team/static/src/core/web/activity.xml new file mode 100644 index 0000000000..1d5c7f05a4 --- /dev/null +++ b/mail_activity_team/static/src/core/web/activity.xml @@ -0,0 +1,24 @@ + + + + + + activity.user_id + + + activity.user_id + + + + + diff --git a/mail_activity_team/tests/test_mail_activity_team.py b/mail_activity_team/tests/test_mail_activity_team.py index 97889025db..2604b964f2 100644 --- a/mail_activity_team/tests/test_mail_activity_team.py +++ b/mail_activity_team/tests/test_mail_activity_team.py @@ -242,10 +242,10 @@ def test_schedule_activity_default_team(self): 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) + # As we are in a 'team activity' context, the user should not be set + self.assertEqual(activity.user_id, self.env["res.users"]) def test_schedule_activity_default_team_no_user(self): """Correctly assign teams to auto scheduled activities. Those won't @@ -257,7 +257,8 @@ def test_schedule_activity_default_team_no_user(self): activity_type_id=self.activity2.id, ) self.assertEqual(activity.team_id, self.team2) - self.assertEqual(activity.user_id, self.employee2) + # As we are in a 'team activity' context, the user should not be set + self.assertEqual(activity.user_id, self.env["res.users"]) def test_activity_count(self): res = ( @@ -300,7 +301,8 @@ def test_activity_schedule_next(self): _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) + # As we are in a 'team activity' context, the user should not be set + self.assertEqual(next_activities.user_id, self.env["res.users"]) def test_schedule_activity_from_server_action(self): partner = self.env["res.partner"].create({"name": "Test Partner"}) diff --git a/mail_activity_team/wizard/__init__.py b/mail_activity_team/wizard/__init__.py new file mode 100644 index 0000000000..6c7dc5222a --- /dev/null +++ b/mail_activity_team/wizard/__init__.py @@ -0,0 +1 @@ +from . import mail_activity_schedule diff --git a/mail_activity_team/wizard/mail_activity_schedule.py b/mail_activity_team/wizard/mail_activity_schedule.py new file mode 100644 index 0000000000..aac6d850bb --- /dev/null +++ b/mail_activity_team/wizard/mail_activity_schedule.py @@ -0,0 +1,71 @@ +# Copyright 2024 Camptocamp SA +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo import api, fields, models + + +class MailActivitySchedule(models.TransientModel): + _inherit = "mail.activity.schedule" + + activity_team_user_id = fields.Many2one( + string="Team user", related="activity_user_id", store=True, readonly=False + ) + activity_team_id = fields.Many2one( + "mail.activity.team", + "Team assigned to", + compute="_compute_activity_team_id", + store=True, + readonly=False, + ) + + @api.depends("activity_type_id") + def _compute_activity_team_id(self): + for scheduler in self: + if scheduler.activity_type_id.default_team_id: + scheduler.activity_team_id = scheduler.activity_type_id.default_team_id + elif not scheduler.activity_team_id: + scheduler.activity_team_id = ( + self.env["mail.activity"] + .with_context(default_res_model=self.sudo().res_model_id.model) + ._get_default_team_id(user_id=scheduler.activity_team_user_id.id) + ) + + @api.onchange("activity_team_id") + def _onchange_activity_team_id(self): + if ( + self.activity_team_id + and self.activity_team_user_id not in self.activity_team_id.member_ids + ): + if self.activity_team_id.user_id: + new_user_id = self.activity_team_id.user_id + elif len(self.activity_team_id.member_ids) == 1: + new_user_id = self.activity_team_id.member_ids + else: + new_user_id = self.env["res.users"] + self.activity_team_user_id = new_user_id + self.activity_user_id = new_user_id + + @api.onchange("activity_team_user_id") + def _onchange_activity_team_user_id(self): + if not self.activity_team_user_id or ( + self.activity_team_user_id + and self.activity_team_user_id in self.activity_team_id.member_ids + ): + return + self.activity_team_id = ( + self.env["mail.activity"] + .with_context(default_res_model=self.sudo().res_model_id.model) + ._get_default_team_id(user_id=self.activity_team_user_id.id) + ) + + def _action_schedule_activities(self): + return self._get_applied_on_records().activity_schedule( + activity_type_id=self.activity_type_id.id, + automated=False, + summary=self.summary, + note=self.note, + user_id=self.activity_team_user_id.id, + team_user_id=self.activity_team_user_id.id, + team_id=self.activity_team_id.id, + date_deadline=self.date_deadline, + ) diff --git a/mail_activity_team/wizard/mail_activity_schedule.xml b/mail_activity_team/wizard/mail_activity_schedule.xml new file mode 100644 index 0000000000..2b0584c24c --- /dev/null +++ b/mail_activity_team/wizard/mail_activity_schedule.xml @@ -0,0 +1,32 @@ + + + + + mail.activity.schedule + + + + activity_team_id + + + + + + + + + + +