Skip to content

Commit

Permalink
[17.0][REF] mail_activity_team: use mail.activity.schedule wizard
Browse files Browse the repository at this point in the history
  • Loading branch information
vvrossem authored and ilo committed Oct 17, 2024
1 parent ed82ad5 commit 55a6fb8
Show file tree
Hide file tree
Showing 11 changed files with 174 additions and 12 deletions.
5 changes: 5 additions & 0 deletions mail_activity_team/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
-------------

Expand Down
1 change: 1 addition & 0 deletions mail_activity_team/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
from . import models
from . import wizard
3 changes: 3 additions & 0 deletions mail_activity_team/__manifest__.py
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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",
Expand All @@ -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/*",
],
},
Expand Down
20 changes: 19 additions & 1 deletion mail_activity_team/models/mail_activity.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand All @@ -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 (
Expand Down
3 changes: 3 additions & 0 deletions mail_activity_team/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@
- Raf Ven
- [Trobz] (https://trobz.com):
- Son Ho <sonhd@trobz.com>
- [Camptocamp] (https://camptocamp.com):
- Vincent Van Rossem <vincent.vanrossem@camptocamp.com>
- Italo Lopes <italo.lopes@camptocamp.com>
16 changes: 9 additions & 7 deletions mail_activity_team/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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 }
Expand All @@ -301,7 +300,7 @@
span.pre {
white-space: pre }

span.problematic, pre.problematic {
span.problematic {
color: red }

span.section-subtitle {
Expand Down Expand Up @@ -447,6 +446,11 @@ <h2><a class="toc-backref" href="#toc-entry-5">Contributors</a></h2>
<li>Son Ho <a class="reference external" href="mailto:sonhd&#64;trobz.com">sonhd&#64;trobz.com</a></li>
</ul>
</li>
<li>[Camptocamp] (<a class="reference external" href="https://camptocamp.com">https://camptocamp.com</a>):<ul>
<li>Vincent Van Rossem <a class="reference external" href="mailto:vincent.vanrossem&#64;camptocamp.com">vincent.vanrossem&#64;camptocamp.com</a></li>
<li>Italo Lopes <a class="reference external" href="mailto:italo.lopes&#64;camptocamp.com">italo.lopes&#64;camptocamp.com</a></li>
</ul>
</li>
</ul>
</div>
<div class="section" id="other-credits">
Expand All @@ -457,9 +461,7 @@ <h2><a class="toc-backref" href="#toc-entry-6">Other credits</a></h2>
<div class="section" id="maintainers">
<h2><a class="toc-backref" href="#toc-entry-7">Maintainers</a></h2>
<p>This module is maintained by the OCA.</p>
<a class="reference external image-reference" href="https://odoo-community.org">
<img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" />
</a>
<a class="reference external image-reference" href="https://odoo-community.org"><img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /></a>
<p>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.</p>
Expand Down
24 changes: 24 additions & 0 deletions mail_activity_team/static/src/core/web/activity.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8" ?>
<templates xml:space="preserve">

<t
t-name="mail_activity_team.Activity"
t-inherit="mail.Activity"
t-inherit-mode="extension"
>
<xpath
expr="//div/div[hasclass('o-mail-Activity-sidebar')]/img"
position="attributes"
>
<attribute name="t-if">activity.user_id</attribute>
</xpath>
<xpath
expr="//div/div/div[hasclass('o-mail-Activity-info')]/span[hasclass('o-mail-Activity-user')]"
position="attributes"
>
<attribute name="t-if">activity.user_id</attribute>
</xpath>

</t>

</templates>
10 changes: 6 additions & 4 deletions mail_activity_team/tests/test_mail_activity_team.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 = (
Expand Down Expand Up @@ -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"})
Expand Down
1 change: 1 addition & 0 deletions mail_activity_team/wizard/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import mail_activity_schedule
71 changes: 71 additions & 0 deletions mail_activity_team/wizard/mail_activity_schedule.py
Original file line number Diff line number Diff line change
@@ -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

Check warning on line 25 in mail_activity_team/wizard/mail_activity_schedule.py

View check run for this annotation

Codecov / codecov/patch

mail_activity_team/wizard/mail_activity_schedule.py#L25

Added line #L25 was not covered by tests
elif not scheduler.activity_team_id:
scheduler.activity_team_id = (

Check warning on line 27 in mail_activity_team/wizard/mail_activity_schedule.py

View check run for this annotation

Codecov / codecov/patch

mail_activity_team/wizard/mail_activity_schedule.py#L27

Added line #L27 was not covered by tests
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

Check warning on line 40 in mail_activity_team/wizard/mail_activity_schedule.py

View check run for this annotation

Codecov / codecov/patch

mail_activity_team/wizard/mail_activity_schedule.py#L40

Added line #L40 was not covered by tests
elif len(self.activity_team_id.member_ids) == 1:
new_user_id = self.activity_team_id.member_ids

Check warning on line 42 in mail_activity_team/wizard/mail_activity_schedule.py

View check run for this annotation

Codecov / codecov/patch

mail_activity_team/wizard/mail_activity_schedule.py#L42

Added line #L42 was not covered by tests
else:
new_user_id = self.env["res.users"]
self.activity_team_user_id = new_user_id
self.activity_user_id = new_user_id

Check warning on line 46 in mail_activity_team/wizard/mail_activity_schedule.py

View check run for this annotation

Codecov / codecov/patch

mail_activity_team/wizard/mail_activity_schedule.py#L44-L46

Added lines #L44 - L46 were not covered by tests

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

Check warning on line 55 in mail_activity_team/wizard/mail_activity_schedule.py

View check run for this annotation

Codecov / codecov/patch

mail_activity_team/wizard/mail_activity_schedule.py#L54-L55

Added lines #L54 - L55 were not covered by tests
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(

Check warning on line 62 in mail_activity_team/wizard/mail_activity_schedule.py

View check run for this annotation

Codecov / codecov/patch

mail_activity_team/wizard/mail_activity_schedule.py#L62

Added line #L62 was not covered by tests
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,
)
32 changes: 32 additions & 0 deletions mail_activity_team/wizard/mail_activity_schedule.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>

<record id="mail_activity_schedule_view_form" model="ir.ui.view">
<field name="model">mail.activity.schedule</field>
<field name="inherit_id" ref="mail.mail_activity_schedule_view_form" />
<field name="arch" type="xml">
<field name="activity_user_id" position="attributes">
<attribute name="invisible">activity_team_id</attribute>
<attribute
name="required"
add="and not activity_team_id"
separator=" "
/>
</field>
<field name="activity_user_id" position="after">
<field name="res_model_id" invisible="1" />
<field
name="activity_team_user_id"
invisible="not activity_team_id"
domain="[('activity_team_ids', '=', activity_team_id)]"
/>
<field
name="activity_team_id"
options="{'no_create': True, 'no_open': True}"
domain="['|', ('res_model_ids', '=', False), ('res_model_ids', '=', res_model_id)]"
/>
</field>
</field>
</record>

</odoo>

0 comments on commit 55a6fb8

Please sign in to comment.