From 2a07a826469ab91f323d7fdc01f98ef8cfb29219 Mon Sep 17 00:00:00 2001 From: trisdoan Date: Mon, 25 Nov 2024 12:20:28 +0700 Subject: [PATCH] [ADD] mail_activity_default_assignee --- mail_activity_default_assignee/README.rst | 84 ++++ mail_activity_default_assignee/__init__.py | 2 + .../__manifest__.py | 15 + .../models/__init__.py | 1 + .../models/mail_activity_type.py | 41 ++ mail_activity_default_assignee/pyproject.toml | 3 + .../readme/CONTRIBUTORS.md | 2 + .../readme/CREDITS.md | 1 + .../readme/DESCRIPTION.md | 1 + .../static/description/index.html | 431 ++++++++++++++++++ .../views/mail_activity_type_view.xml | 13 + .../wizard/__init__.py | 1 + .../wizard/mail_activity_schedule.py | 30 ++ 13 files changed, 625 insertions(+) create mode 100644 mail_activity_default_assignee/README.rst create mode 100644 mail_activity_default_assignee/__init__.py create mode 100644 mail_activity_default_assignee/__manifest__.py create mode 100644 mail_activity_default_assignee/models/__init__.py create mode 100644 mail_activity_default_assignee/models/mail_activity_type.py create mode 100644 mail_activity_default_assignee/pyproject.toml create mode 100644 mail_activity_default_assignee/readme/CONTRIBUTORS.md create mode 100644 mail_activity_default_assignee/readme/CREDITS.md create mode 100644 mail_activity_default_assignee/readme/DESCRIPTION.md create mode 100644 mail_activity_default_assignee/static/description/index.html create mode 100644 mail_activity_default_assignee/views/mail_activity_type_view.xml create mode 100644 mail_activity_default_assignee/wizard/__init__.py create mode 100644 mail_activity_default_assignee/wizard/mail_activity_schedule.py 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..36d8ed0cc2 --- /dev/null +++ b/mail_activity_default_assignee/models/mail_activity_type.py @@ -0,0 +1,41 @@ +# Copyright 2024 Camptocamp +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import api, fields, models + +MAGIC_FIELDS = models.MAGIC_COLUMNS + + +class MailActivityType(models.Model): + _inherit = "mail.activity.type" + + model_id = fields.Many2one("ir.model", compute="_compute_model_id") + + default_user_field_id = fields.Many2one( + "ir.model.fields", + domain=f""" + [ + ("name", "not in", {str(MAGIC_FIELDS)}), + ("ttype", "in", ["one2many","many2one", "many2many"]), + ("model_id", "=", model_id), + ("relation", "=", "res.users") + ] + """, + help="Default assignee is set based on this field", + ) + + @api.depends("res_model") + def _compute_model_id(self): + for rec in self: + if not rec.res_model: + rec.model_id = False + continue + rec.model_id = self.env["ir.model"]._get_id(rec.res_model) + + @api.onchange("res_model") + def _onchange_res_model(self): + res = super()._onchange_res_model() + self.default_user_field_id = self.default_user_field_id.filtered( + lambda field: field.model_id.model == self.res_model + ) + return res 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/views/mail_activity_type_view.xml b/mail_activity_default_assignee/views/mail_activity_type_view.xml new file mode 100644 index 0000000000..cf6fd6e157 --- /dev/null +++ b/mail_activity_default_assignee/views/mail_activity_type_view.xml @@ -0,0 +1,13 @@ + + + + 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..f938f89c24 --- /dev/null +++ b/mail_activity_default_assignee/wizard/mail_activity_schedule.py @@ -0,0 +1,30 @@ +# 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") + 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 + res_model = self.env[scheduler.res_model] + user_ids = scheduler._get_user_ids(res_model, fname) + if not user_ids: + continue + scheduler.activity_user_id = user_ids[0] + return res + + def _get_user_ids(self, model, fname): + context = self.env.context + active_id = context.get("active_id") + res_id = model.browse(active_id) + user_ids = getattr(res_id, fname) + return user_ids.ids if user_ids else []