Skip to content

Commit

Permalink
[ADD] mail_activity_default_assignee
Browse files Browse the repository at this point in the history
  • Loading branch information
trisdoan committed Nov 25, 2024
1 parent 54f32c1 commit 03791fc
Show file tree
Hide file tree
Showing 13 changed files with 625 additions and 0 deletions.
84 changes: 84 additions & 0 deletions mail_activity_default_assignee/README.rst
Original file line number Diff line number Diff line change
@@ -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 <https://github.com/OCA/social/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 <https://github.com/OCA/social/issues/new?body=module:%20mail_activity_default_assignee%0Aversion:%2017.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

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

Credits
=======

Authors
-------

* Camptocamp

Contributors
------------

- Tris Doan <tridm@trobz.com>
(`www.trobz.com <http://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 <https://github.com/OCA/social/tree/17.0/mail_activity_default_assignee>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
2 changes: 2 additions & 0 deletions mail_activity_default_assignee/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import models
from . import wizard
15 changes: 15 additions & 0 deletions mail_activity_default_assignee/__manifest__.py
Original file line number Diff line number Diff line change
@@ -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",
}
1 change: 1 addition & 0 deletions mail_activity_default_assignee/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import mail_activity_type
41 changes: 41 additions & 0 deletions mail_activity_default_assignee/models/mail_activity_type.py
Original file line number Diff line number Diff line change
@@ -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)

Check warning on line 33 in mail_activity_default_assignee/models/mail_activity_type.py

View check run for this annotation

Codecov / codecov/patch

mail_activity_default_assignee/models/mail_activity_type.py#L31-L33

Added lines #L31 - L33 were not covered by tests

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

Check warning on line 38 in mail_activity_default_assignee/models/mail_activity_type.py

View check run for this annotation

Codecov / codecov/patch

mail_activity_default_assignee/models/mail_activity_type.py#L37-L38

Added lines #L37 - L38 were not covered by tests
lambda field: field.model_id.model == self.res_model
)
return res

Check warning on line 41 in mail_activity_default_assignee/models/mail_activity_type.py

View check run for this annotation

Codecov / codecov/patch

mail_activity_default_assignee/models/mail_activity_type.py#L41

Added line #L41 was not covered by tests
3 changes: 3 additions & 0 deletions mail_activity_default_assignee/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["whool"]
build-backend = "whool.buildapi"
2 changes: 2 additions & 0 deletions mail_activity_default_assignee/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Tris Doan \<<tridm@trobz.com>\> (www.trobz.com)

1 change: 1 addition & 0 deletions mail_activity_default_assignee/readme/CREDITS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The creation of this module were financially supported by Camptocamp.
1 change: 1 addition & 0 deletions mail_activity_default_assignee/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This module implements the capability to set default assignee dynamically based on relational field, which is configured on Mail Activity Type
Loading

0 comments on commit 03791fc

Please sign in to comment.