diff --git a/mail_activity_default_assignee/README.rst b/mail_activity_default_assignee/README.rst new file mode 100644 index 0000000000..44a598d07b --- /dev/null +++ b/mail_activity_default_assignee/README.rst @@ -0,0 +1,84 @@ +============================== +Mail Activity Default Assignee +============================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:2aa7a5c9b7aae06d2a5bdb0ec4f11aacc50f2039d983b2dc829c2b9454a989cc + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fsocial-lightgray.png?logo=github + :target: https://github.com/OCA/social/tree/17.0/mail_activity_default_assignee + :alt: OCA/social +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/social-17-0/social-17-0-mail_activity_default_assignee + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png + :target: https://runboat.odoo-community.org/builds?repo=OCA/social&target_branch=17.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module implements the capability to set default assignee +dynamically based on relational field, which is configured on Mail +Activity Type + +**Table of contents** + +.. contents:: + :local: + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues `_. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us to smash it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +------- + +* Camptocamp + +Contributors +------------ + +- Tris Doan + (`www.trobz.com `__) + +Other credits +------------- + +The creation of this module were financially supported by Camptocamp. + +Maintainers +----------- + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +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. + +This module is part of the `OCA/social `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/mail_activity_default_assignee/__init__.py b/mail_activity_default_assignee/__init__.py new file mode 100644 index 0000000000..9b4296142f --- /dev/null +++ b/mail_activity_default_assignee/__init__.py @@ -0,0 +1,2 @@ +from . import models +from . import wizard diff --git a/mail_activity_default_assignee/__manifest__.py b/mail_activity_default_assignee/__manifest__.py new file mode 100644 index 0000000000..a3155d6735 --- /dev/null +++ b/mail_activity_default_assignee/__manifest__.py @@ -0,0 +1,15 @@ +# Copyright 2024 Camptocamp +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +{ + "name": "Mail Activity Default Assignee", + "summary": """Allow to set default assignee based on relational field""", + "version": "17.0.1.0.0", + "author": "Camptocamp,Odoo Community Association (OCA)", + "license": "AGPL-3", + "website": "https://github.com/OCA/social", + "depends": [ + "mail", + ], + "data": ["views/mail_activity_type_view.xml"], + "development_status": "Beta", +} diff --git a/mail_activity_default_assignee/models/__init__.py b/mail_activity_default_assignee/models/__init__.py new file mode 100644 index 0000000000..d4bcae014f --- /dev/null +++ b/mail_activity_default_assignee/models/__init__.py @@ -0,0 +1 @@ +from . import mail_activity_type diff --git a/mail_activity_default_assignee/models/mail_activity_type.py b/mail_activity_default_assignee/models/mail_activity_type.py new file mode 100644 index 0000000000..bba1556723 --- /dev/null +++ b/mail_activity_default_assignee/models/mail_activity_type.py @@ -0,0 +1,25 @@ +# Copyright 2024 Camptocamp +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import _, api, fields, models +from odoo.exceptions import ValidationError + + +class MailActivityType(models.Model): + _inherit = "mail.activity.type" + + default_user_field_id = fields.Many2one( + "ir.model.fields", + help="Default assignee is set based on this field", + ) + + @api.constrains("default_user_field_id") + def _check_default_user_field_id(self): + for rec in self: + if rec.default_user_field_id.model_id.model != rec.res_model: + raise ValidationError( + _( + f"{rec.default_user_field_id.field_description} " + f"does not exist in model {rec.res_model} " + ) + ) diff --git a/mail_activity_default_assignee/pyproject.toml b/mail_activity_default_assignee/pyproject.toml new file mode 100644 index 0000000000..4231d0cccb --- /dev/null +++ b/mail_activity_default_assignee/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/mail_activity_default_assignee/readme/CONTRIBUTORS.md b/mail_activity_default_assignee/readme/CONTRIBUTORS.md new file mode 100644 index 0000000000..a4d6805a35 --- /dev/null +++ b/mail_activity_default_assignee/readme/CONTRIBUTORS.md @@ -0,0 +1,2 @@ +- Tris Doan \<\> (www.trobz.com) + diff --git a/mail_activity_default_assignee/readme/CREDITS.md b/mail_activity_default_assignee/readme/CREDITS.md new file mode 100644 index 0000000000..40bfb9d25e --- /dev/null +++ b/mail_activity_default_assignee/readme/CREDITS.md @@ -0,0 +1 @@ +The creation of this module were financially supported by Camptocamp. diff --git a/mail_activity_default_assignee/readme/DESCRIPTION.md b/mail_activity_default_assignee/readme/DESCRIPTION.md new file mode 100644 index 0000000000..3632f07f73 --- /dev/null +++ b/mail_activity_default_assignee/readme/DESCRIPTION.md @@ -0,0 +1 @@ +This module implements the capability to set default assignee dynamically based on relational field, which is configured on Mail Activity Type diff --git a/mail_activity_default_assignee/static/description/index.html b/mail_activity_default_assignee/static/description/index.html new file mode 100644 index 0000000000..68b23d78b7 --- /dev/null +++ b/mail_activity_default_assignee/static/description/index.html @@ -0,0 +1,431 @@ + + + + + +Mail Activity Default Assignee + + + +
+

Mail Activity Default Assignee

+ + +

Beta License: AGPL-3 OCA/social Translate me on Weblate Try me on Runboat

+

This module implements the capability to set default assignee +dynamically based on relational field, which is configured on Mail +Activity Type

+

Table of contents

+ +
+

Bug Tracker

+

Bugs are tracked on GitHub Issues. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us to smash it by providing a detailed and welcomed +feedback.

+

Do not contact contributors directly about support or help with technical issues.

+
+
+

Credits

+
+

Authors

+
    +
  • Camptocamp
  • +
+
+ +
+

Other credits

+

The creation of this module were financially supported by Camptocamp.

+
+
+

Maintainers

+

This module is maintained by the OCA.

+ +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.

+

This module is part of the OCA/social project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/mail_activity_default_assignee/tests/__init__.py b/mail_activity_default_assignee/tests/__init__.py new file mode 100644 index 0000000000..26dbfc1469 --- /dev/null +++ b/mail_activity_default_assignee/tests/__init__.py @@ -0,0 +1 @@ +from . import test_mail_activity_default_assignee diff --git a/mail_activity_default_assignee/tests/test_mail_activity_default_assignee.py b/mail_activity_default_assignee/tests/test_mail_activity_default_assignee.py new file mode 100644 index 0000000000..01773e2618 --- /dev/null +++ b/mail_activity_default_assignee/tests/test_mail_activity_default_assignee.py @@ -0,0 +1,31 @@ +from odoo.tests import Form +from odoo.tests.common import TransactionCase + + +class TestMailActivityDefaultAssignee(TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.todo_act_type = cls.env.ref("mail.mail_activity_data_todo") + create_uid = cls.env["ir.model.fields"].search( + [("name", "=", "create_uid"), ("model", "=", "res.partner")], limit=1 + ) + cls.todo_act_type.res_model = "res.partner" + cls.todo_act_type.default_user_field_id = create_uid.id + + def test_mail_activity_default_assignee(self): + odoobot = self.env.ref("base.user_root") + wizard_form = Form( + self.env["mail.activity.schedule"] + .with_context( + active_ids=self.env.ref("base.res_partner_1").ids, + active_id=self.env.ref("base.res_partner_1").ids[:1], + active_model="res.partner", + ) + .create( + { + "activity_type_id": self.todo_act_type.id, + } + ) + ) + self.assertEqual(wizard_form.activity_user_id, odoobot) diff --git a/mail_activity_default_assignee/views/mail_activity_type_view.xml b/mail_activity_default_assignee/views/mail_activity_type_view.xml new file mode 100644 index 0000000000..0be1be68d6 --- /dev/null +++ b/mail_activity_default_assignee/views/mail_activity_type_view.xml @@ -0,0 +1,15 @@ + + + + mail.activity.type + + + + + + + + diff --git a/mail_activity_default_assignee/wizard/__init__.py b/mail_activity_default_assignee/wizard/__init__.py new file mode 100644 index 0000000000..6c7dc5222a --- /dev/null +++ b/mail_activity_default_assignee/wizard/__init__.py @@ -0,0 +1 @@ +from . import mail_activity_schedule diff --git a/mail_activity_default_assignee/wizard/mail_activity_schedule.py b/mail_activity_default_assignee/wizard/mail_activity_schedule.py new file mode 100644 index 0000000000..f93f7390de --- /dev/null +++ b/mail_activity_default_assignee/wizard/mail_activity_schedule.py @@ -0,0 +1,20 @@ +# Copyright 2024 Camptocamp +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import api, models + + +class MailActivitySchedule(models.TransientModel): + _inherit = "mail.activity.schedule" + + @api.depends("activity_type_id", "res_ids") + def _compute_activity_user_id(self): + res = super()._compute_activity_user_id() + for scheduler in self.filtered( + lambda rec: not rec.activity_type_id.default_user_id + and rec.activity_type_id.default_user_field_id + ): + fname = scheduler.activity_type_id.default_user_field_id.name + if users := scheduler._get_applied_on_records().mapped(fname): + scheduler.activity_user_id = users[:1] + return res