mirror of https://github.com/OCA/social.git
[FIX] mail_activity_team: scheduled activity
When an activity is scheduled due to automatic processes the onchanges won't adapt the proper user team, so we could have a mismatch that provokes an exceptions due to the designed constaintspull/1321/head
parent
77ee579afd
commit
e1dc5d9c14
|
@ -79,6 +79,9 @@ Contributors
|
||||||
* Jordi Ballester Alomar (jordi.ballester@forgeflow.com)
|
* Jordi Ballester Alomar (jordi.ballester@forgeflow.com)
|
||||||
* Miquel Raïch (miquel.raich@forgeflow.com)
|
* Miquel Raïch (miquel.raich@forgeflow.com)
|
||||||
* Pedro Gonzalez (pedro.gonzalez@pesol.es)
|
* Pedro Gonzalez (pedro.gonzalez@pesol.es)
|
||||||
|
* `Tecnativa <https://www.tecnativa.com>`_:
|
||||||
|
|
||||||
|
* David Vidal
|
||||||
|
|
||||||
Maintainers
|
Maintainers
|
||||||
~~~~~~~~~~~
|
~~~~~~~~~~~
|
||||||
|
|
|
@ -23,6 +23,11 @@ msgstr ""
|
||||||
msgid "Activity"
|
msgid "Activity"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
|
#. module: mail_activity_team
|
||||||
|
#: model:ir.model,name:mail_activity_team.model_mail_activity_mixin
|
||||||
|
msgid "Activity Mixin"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
#. module: mail_activity_team
|
#. module: mail_activity_team
|
||||||
#: model_terms:ir.ui.view,arch_db:mail_activity_team.mail_activity_team_view_form
|
#: model_terms:ir.ui.view,arch_db:mail_activity_team.mail_activity_team_view_form
|
||||||
msgid "Activity Team"
|
msgid "Activity Team"
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
from . import mail_activity_team
|
from . import mail_activity_team
|
||||||
from . import mail_activity
|
from . import mail_activity
|
||||||
|
from . import mail_activity_mixin
|
||||||
from . import res_users
|
from . import res_users
|
||||||
|
|
|
@ -0,0 +1,32 @@
|
||||||
|
# Copyright 2021 Tecnativa - David Vidal
|
||||||
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||||
|
from odoo import models
|
||||||
|
|
||||||
|
|
||||||
|
class MailActivityMixin(models.AbstractModel):
|
||||||
|
_inherit = "mail.activity.mixin"
|
||||||
|
|
||||||
|
def activity_schedule(
|
||||||
|
self, act_type_xmlid="", date_deadline=None, summary="", note="", **act_values
|
||||||
|
):
|
||||||
|
"""With automatic activities, the user onchange won't act so we must
|
||||||
|
ensure the right group is set and no exceptions are raised due to
|
||||||
|
user-team missmatch. We can hook onto `act_values` dict as it's passed
|
||||||
|
to the create activity method.
|
||||||
|
"""
|
||||||
|
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)
|
||||||
|
)
|
||||||
|
if team:
|
||||||
|
act_values.update({"team_id": team.id})
|
||||||
|
return super().activity_schedule(
|
||||||
|
act_type_xmlid=act_type_xmlid,
|
||||||
|
date_deadline=date_deadline,
|
||||||
|
summary=summary,
|
||||||
|
note=note,
|
||||||
|
**act_values
|
||||||
|
)
|
|
@ -3,3 +3,6 @@
|
||||||
* Jordi Ballester Alomar (jordi.ballester@forgeflow.com)
|
* Jordi Ballester Alomar (jordi.ballester@forgeflow.com)
|
||||||
* Miquel Raïch (miquel.raich@forgeflow.com)
|
* Miquel Raïch (miquel.raich@forgeflow.com)
|
||||||
* Pedro Gonzalez (pedro.gonzalez@pesol.es)
|
* Pedro Gonzalez (pedro.gonzalez@pesol.es)
|
||||||
|
* `Tecnativa <https://www.tecnativa.com>`_:
|
||||||
|
|
||||||
|
* David Vidal
|
||||||
|
|
|
@ -425,6 +425,10 @@ If you spotted it first, help us smashing it by providing a detailed and welcome
|
||||||
<li>Pedro Gonzalez (<a class="reference external" href="mailto:pedro.gonzalez@pesol.es">pedro.gonzalez@pesol.es</a>)</li>
|
<li>Pedro Gonzalez (<a class="reference external" href="mailto:pedro.gonzalez@pesol.es">pedro.gonzalez@pesol.es</a>)</li>
|
||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
|
<li><a class="reference external" href="https://www.tecnativa.com">Tecnativa</a>:<ul>
|
||||||
|
<li>David Vidal</li>
|
||||||
|
</ul>
|
||||||
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
<div class="section" id="maintainers">
|
<div class="section" id="maintainers">
|
||||||
|
|
|
@ -179,3 +179,13 @@ class TestMailActivityTeam(TransactionCase):
|
||||||
self.act2.team_id = self.team2
|
self.act2.team_id = self.team2
|
||||||
self.team2.member_ids = [(3, self.act2.user_id.id)]
|
self.team2.member_ids = [(3, self.act2.user_id.id)]
|
||||||
self.act2._onchange_team_id()
|
self.act2._onchange_team_id()
|
||||||
|
|
||||||
|
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)
|
||||||
|
activity = partner_record.activity_schedule(
|
||||||
|
user_id=self.employee2.id,
|
||||||
|
activity_type_id=self.env.ref("mail.mail_activity_data_call").id,
|
||||||
|
)
|
||||||
|
self.assertEqual(activity.team_id, self.team2)
|
||||||
|
|
Loading…
Reference in New Issue