diff --git a/mail_partner_forwarding/README.rst b/mail_partner_forwarding/README.rst new file mode 100644 index 0000000000..30791ae808 --- /dev/null +++ b/mail_partner_forwarding/README.rst @@ -0,0 +1,95 @@ +======================= +Partner Mail Forwarding +======================= + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:6aea6f497ed772e5eac7409531ab7f024bd98331ebe2a6cc8250cde45b4361c0 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Production%2FStable-green.png + :target: https://odoo-community.org/page/development-status + :alt: Production/Stable +.. |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/18.0/mail_partner_forwarding + :alt: OCA/social +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/social-18-0/social-18-0-mail_partner_forwarding + :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=18.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module allows to select a related user (called "Forwarding +partner") in each partner in order to send all the notifications to the +Forwarding partner. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +To use this module, you need to: + +- Install it. +- Set a Forwarding partner in your partner. +- Your Forwarding partner also will be notify of your notifications + +Changelog +========= + +13.0.1.0.0 (2022-01-03) +----------------------- + +- [NEW] Module in v13. + +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 +------- + +* ADHOC SA + +Contributors +------------ + +- Nicolás Mac Rouillon + +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_partner_forwarding/__init__.py b/mail_partner_forwarding/__init__.py new file mode 100644 index 0000000000..0650744f6b --- /dev/null +++ b/mail_partner_forwarding/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/mail_partner_forwarding/__manifest__.py b/mail_partner_forwarding/__manifest__.py new file mode 100644 index 0000000000..8b41ab4ff8 --- /dev/null +++ b/mail_partner_forwarding/__manifest__.py @@ -0,0 +1,17 @@ +# Copyright 2022 AdHoc SA - Pablo Paez +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +{ + "name": "Partner Mail Forwarding", + "summary": "Forwarding notifications for partners", + "version": "18.0.1.0.0", + "category": "Social Network", + "website": "https://github.com/OCA/social", + "author": "ADHOC SA, Odoo Community Association (OCA)", + "license": "AGPL-3", + "installable": True, + "depends": ["mail"], + "data": ["views/res_user_views.xml", "views/res_partner_views.xml"], + "development_status": "Production/Stable", + "maintainers": [], +} diff --git a/mail_partner_forwarding/i18n/es.po b/mail_partner_forwarding/i18n/es.po new file mode 100644 index 0000000000..8cd2d191d4 --- /dev/null +++ b/mail_partner_forwarding/i18n/es.po @@ -0,0 +1,56 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * mail_partner_forwarding +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 17.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2024-02-08 19:35+0000\n" +"Last-Translator: Ivorra78 \n" +"Language-Team: none\n" +"Language: es\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n != 1;\n" +"X-Generator: Weblate 4.17\n" + +#. module: mail_partner_forwarding +#: model:ir.model,name:mail_partner_forwarding.model_res_partner +msgid "Contact" +msgstr "Contacto" + +#. module: mail_partner_forwarding +#: model:ir.model,name:mail_partner_forwarding.model_mail_thread +msgid "Email Thread" +msgstr "Hilo de Correo Electrónico" + +#. module: mail_partner_forwarding +#: model:ir.model.fields,field_description:mail_partner_forwarding.field_res_partner__forwarding_partner_id +#: model:ir.model.fields,field_description:mail_partner_forwarding.field_res_users__forwarding_partner_id +msgid "Forwarding Partner" +msgstr "Socio Transitario" + +#. module: mail_partner_forwarding +#: model:ir.model.fields,help:mail_partner_forwarding.field_res_partner__forwarding_partner_id +#: model:ir.model.fields,help:mail_partner_forwarding.field_res_users__forwarding_partner_id +msgid "" +"Messages will be forwarded only for partners that are followers but no " +"partners being notify because they belong to channel that is following the " +"thread" +msgstr "" +"Los mensajes sólo se reenviarán a los socios que sean seguidores, pero no se " +"notificará a los socios que pertenezcan a un canal que esté siguiendo el hilo" + +#. module: mail_partner_forwarding +#. odoo-python +#: code:addons/mail_partner_forwarding/tests/test_mail_forwarding.py:0 +#, python-format +msgid "Test" +msgstr "Prueba" + +#. module: mail_partner_forwarding +#: model:ir.model,name:mail_partner_forwarding.model_res_users +msgid "User" +msgstr "Usuario" diff --git a/mail_partner_forwarding/i18n/it.po b/mail_partner_forwarding/i18n/it.po new file mode 100644 index 0000000000..7de317e84b --- /dev/null +++ b/mail_partner_forwarding/i18n/it.po @@ -0,0 +1,56 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * mail_partner_forwarding +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 17.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2024-02-04 22:34+0000\n" +"Last-Translator: mymage \n" +"Language-Team: none\n" +"Language: it\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n != 1;\n" +"X-Generator: Weblate 4.17\n" + +#. module: mail_partner_forwarding +#: model:ir.model,name:mail_partner_forwarding.model_res_partner +msgid "Contact" +msgstr "Contatto" + +#. module: mail_partner_forwarding +#: model:ir.model,name:mail_partner_forwarding.model_mail_thread +msgid "Email Thread" +msgstr "Discussione e-mail" + +#. module: mail_partner_forwarding +#: model:ir.model.fields,field_description:mail_partner_forwarding.field_res_partner__forwarding_partner_id +#: model:ir.model.fields,field_description:mail_partner_forwarding.field_res_users__forwarding_partner_id +msgid "Forwarding Partner" +msgstr "Partner inoltro" + +#. module: mail_partner_forwarding +#: model:ir.model.fields,help:mail_partner_forwarding.field_res_partner__forwarding_partner_id +#: model:ir.model.fields,help:mail_partner_forwarding.field_res_users__forwarding_partner_id +msgid "" +"Messages will be forwarded only for partners that are followers but no " +"partners being notify because they belong to channel that is following the " +"thread" +msgstr "" +"I messaggi verranno inoltrati solo per partner che seguono ma nessun partner " +"è stato avvisato perché apprtiene al canale che segue la discussione" + +#. module: mail_partner_forwarding +#. odoo-python +#: code:addons/mail_partner_forwarding/tests/test_mail_forwarding.py:0 +#, python-format +msgid "Test" +msgstr "Test" + +#. module: mail_partner_forwarding +#: model:ir.model,name:mail_partner_forwarding.model_res_users +msgid "User" +msgstr "Utente" diff --git a/mail_partner_forwarding/i18n/mail_partner_forwarding.pot b/mail_partner_forwarding/i18n/mail_partner_forwarding.pot new file mode 100644 index 0000000000..e9d65fdadb --- /dev/null +++ b/mail_partner_forwarding/i18n/mail_partner_forwarding.pot @@ -0,0 +1,51 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * mail_partner_forwarding +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 17.0\n" +"Report-Msgid-Bugs-To: \n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: mail_partner_forwarding +#: model:ir.model,name:mail_partner_forwarding.model_res_partner +msgid "Contact" +msgstr "" + +#. module: mail_partner_forwarding +#: model:ir.model,name:mail_partner_forwarding.model_mail_thread +msgid "Email Thread" +msgstr "" + +#. module: mail_partner_forwarding +#: model:ir.model.fields,field_description:mail_partner_forwarding.field_res_partner__forwarding_partner_id +#: model:ir.model.fields,field_description:mail_partner_forwarding.field_res_users__forwarding_partner_id +msgid "Forwarding Partner" +msgstr "" + +#. module: mail_partner_forwarding +#: model:ir.model.fields,help:mail_partner_forwarding.field_res_partner__forwarding_partner_id +#: model:ir.model.fields,help:mail_partner_forwarding.field_res_users__forwarding_partner_id +msgid "" +"Messages will be forwarded only for partners that are followers but no " +"partners being notify because they belong to channel that is following the " +"thread" +msgstr "" + +#. module: mail_partner_forwarding +#. odoo-python +#: code:addons/mail_partner_forwarding/tests/test_mail_forwarding.py:0 +#, python-format +msgid "Test" +msgstr "" + +#. module: mail_partner_forwarding +#: model:ir.model,name:mail_partner_forwarding.model_res_users +msgid "User" +msgstr "" diff --git a/mail_partner_forwarding/models/__init__.py b/mail_partner_forwarding/models/__init__.py new file mode 100644 index 0000000000..8df12c7a1c --- /dev/null +++ b/mail_partner_forwarding/models/__init__.py @@ -0,0 +1,3 @@ +from . import res_partner +from . import res_user +from . import mail_thread diff --git a/mail_partner_forwarding/models/mail_thread.py b/mail_partner_forwarding/models/mail_thread.py new file mode 100644 index 0000000000..06738e3c58 --- /dev/null +++ b/mail_partner_forwarding/models/mail_thread.py @@ -0,0 +1,43 @@ +from odoo import models + + +class MailThread(models.AbstractModel): + _inherit = "mail.thread" + + def _notify_get_recipients(self, message, msg_vals, **kwargs): + """Inherit this method to add in the list of partners to be notify + the forwarding_partner_id of any partners in the list""" + recipient_data = super()._notify_get_recipients(message, msg_vals, **kwargs) + if not recipient_data: + return recipient_data + partner_dict = {x.get("id"): x for x in recipient_data} + forwarded_partner_ids = [] + # for each partner being notified we check if it has a + # forwarding_partner_id configured that is not being notified yet + for partner in ( + self.env["res.partner"] + .sudo() + .with_context(prefetch_fields=False) + .browse(partner_dict.keys()) + ): + if ( + partner.forwarding_partner_id + and partner.forwarding_partner_id.id not in partner_dict.keys() + and partner.forwarding_partner_id.id not in forwarded_partner_ids + ): + forwarded_partner_ids.append(partner.forwarding_partner_id.id) + data = partner_dict[partner.id].copy() + notif = ( + partner.forwarding_partner_id.user_ids + and partner.forwarding_partner_id.user_ids[0].notification_type + or "email" + ) + data.update( + { + "id": partner.forwarding_partner_id.id, + "share": partner.partner_share, + "notif": notif, + } + ) + recipient_data.append(data) + return recipient_data diff --git a/mail_partner_forwarding/models/res_partner.py b/mail_partner_forwarding/models/res_partner.py new file mode 100644 index 0000000000..4ad22227a0 --- /dev/null +++ b/mail_partner_forwarding/models/res_partner.py @@ -0,0 +1,13 @@ +from odoo import fields, models + + +class ResPartner(models.Model): + _inherit = "res.partner" + + forwarding_partner_id = fields.Many2one( + "res.partner", + string="Forwarding Partner", + help="Messages will be forwarded only for partners that are followers but no" + " partners being notify because they belong to channel that is following" + " the thread", + ) diff --git a/mail_partner_forwarding/models/res_user.py b/mail_partner_forwarding/models/res_user.py new file mode 100644 index 0000000000..2472b28402 --- /dev/null +++ b/mail_partner_forwarding/models/res_user.py @@ -0,0 +1,17 @@ +from odoo import fields, models + + +class ResUsers(models.Model): + _inherit = "res.users" + + forwarding_partner_id = fields.Many2one( + related="partner_id.forwarding_partner_id", readonly=False + ) + + @property + def SELF_WRITEABLE_FIELDS(self): + return super().SELF_WRITEABLE_FIELDS + ["forwarding_partner_id"] + + @property + def SELF_READABLE_FIELDS(self): + return super().SELF_READABLE_FIELDS + ["forwarding_partner_id"] diff --git a/mail_partner_forwarding/pyproject.toml b/mail_partner_forwarding/pyproject.toml new file mode 100644 index 0000000000..4231d0cccb --- /dev/null +++ b/mail_partner_forwarding/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/mail_partner_forwarding/readme/CONTRIBUTORS.md b/mail_partner_forwarding/readme/CONTRIBUTORS.md new file mode 100644 index 0000000000..f4990492be --- /dev/null +++ b/mail_partner_forwarding/readme/CONTRIBUTORS.md @@ -0,0 +1 @@ +- Nicolás Mac Rouillon \<\> diff --git a/mail_partner_forwarding/readme/DESCRIPTION.md b/mail_partner_forwarding/readme/DESCRIPTION.md new file mode 100644 index 0000000000..85a51b4ca0 --- /dev/null +++ b/mail_partner_forwarding/readme/DESCRIPTION.md @@ -0,0 +1,3 @@ +This module allows to select a related user (called "Forwarding +partner") in each partner in order to send all the notifications to the +Forwarding partner. diff --git a/mail_partner_forwarding/readme/HISTORY.md b/mail_partner_forwarding/readme/HISTORY.md new file mode 100644 index 0000000000..2021642be7 --- /dev/null +++ b/mail_partner_forwarding/readme/HISTORY.md @@ -0,0 +1,3 @@ +## 13.0.1.0.0 (2022-01-03) + +- \[NEW\] Module in v13. diff --git a/mail_partner_forwarding/readme/USAGE.md b/mail_partner_forwarding/readme/USAGE.md new file mode 100644 index 0000000000..594a8769dc --- /dev/null +++ b/mail_partner_forwarding/readme/USAGE.md @@ -0,0 +1,5 @@ +To use this module, you need to: + +- Install it. +- Set a Forwarding partner in your partner. +- Your Forwarding partner also will be notify of your notifications diff --git a/mail_partner_forwarding/static/description/icon.png b/mail_partner_forwarding/static/description/icon.png new file mode 100644 index 0000000000..3a0328b516 Binary files /dev/null and b/mail_partner_forwarding/static/description/icon.png differ diff --git a/mail_partner_forwarding/static/description/index.html b/mail_partner_forwarding/static/description/index.html new file mode 100644 index 0000000000..84cef4b2d9 --- /dev/null +++ b/mail_partner_forwarding/static/description/index.html @@ -0,0 +1,448 @@ + + + + + +Partner Mail Forwarding + + + +
+

Partner Mail Forwarding

+ + +

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

+

This module allows to select a related user (called “Forwarding +partner”) in each partner in order to send all the notifications to the +Forwarding partner.

+

Table of contents

+ +
+

Usage

+

To use this module, you need to:

+
    +
  • Install it.
  • +
  • Set a Forwarding partner in your partner.
  • +
  • Your Forwarding partner also will be notify of your notifications
  • +
+
+
+

Changelog

+
+

13.0.1.0.0 (2022-01-03)

+
    +
  • [NEW] Module in v13.
  • +
+
+
+
+

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

+
    +
  • ADHOC SA
  • +
+
+
+

Contributors

+ +
+
+

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_partner_forwarding/tests/__init__.py b/mail_partner_forwarding/tests/__init__.py new file mode 100644 index 0000000000..99035941c3 --- /dev/null +++ b/mail_partner_forwarding/tests/__init__.py @@ -0,0 +1 @@ +from . import test_mail_forwarding diff --git a/mail_partner_forwarding/tests/models/__init__.py b/mail_partner_forwarding/tests/models/__init__.py new file mode 100644 index 0000000000..4327a4b6eb --- /dev/null +++ b/mail_partner_forwarding/tests/models/__init__.py @@ -0,0 +1 @@ +from . import fake_order diff --git a/mail_partner_forwarding/tests/models/fake_order.py b/mail_partner_forwarding/tests/models/fake_order.py new file mode 100644 index 0000000000..b14a40f17e --- /dev/null +++ b/mail_partner_forwarding/tests/models/fake_order.py @@ -0,0 +1,13 @@ +# Copyright 2021 Camptocamp (http://www.camptocamp.com). +# @author Iván Todorovich +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import fields, models + + +class FakeOrder(models.Model): + _name = "fake.order" + _inherit = "mail.thread" + _description = "Fake sale.order like model" + + partner_id = fields.Many2one("res.partner", required=True) diff --git a/mail_partner_forwarding/tests/test_mail_forwarding.py b/mail_partner_forwarding/tests/test_mail_forwarding.py new file mode 100644 index 0000000000..55a4d66afb --- /dev/null +++ b/mail_partner_forwarding/tests/test_mail_forwarding.py @@ -0,0 +1,46 @@ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo_test_helper import FakeModelLoader + +from odoo import _ +from odoo.tests.common import TransactionCase, tagged + + +@tagged("post_install", "-at_install") +class TestMailForwarding(TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + # Setup env + cls.env = cls.env(context=dict(cls.env.context, tracking_disable=True)) + # Load fake order model + cls.loader = FakeModelLoader(cls.env, cls.__module__) + cls.loader.backup_registry() + from .models.fake_order import FakeOrder + + cls.loader.update_registry((FakeOrder,)) + cls.fake_order_model = cls.env["ir.model"].search( + [("model", "=", "fake.order")] + ) + # Partner To forward + cls.partner_1 = cls.env.ref("base.user_demo").partner_id + cls.partner_2 = cls.env.ref("base.user_admin").partner_id + + # Configurate in the user setting the user to be forwarding + cls.partner_2.forwarding_partner_id = cls.partner_1 + # Empty fake.order + cls.order = cls.env["fake.order"].create({"partner_id": cls.partner_2.id}) + + @classmethod + def tearDownClass(cls): + cls.loader.restore_registry() + return super().tearDownClass() + + def test_message_post_forwarding(self): + """Test forwarding when send a message for the user""" + self.order.message_post( + body=_("Test"), + message_type="comment", + subtype_id=self.env.ref("mail.mt_comment").id, + partner_ids=[self.partner_2.id], + ) diff --git a/mail_partner_forwarding/views/res_partner_views.xml b/mail_partner_forwarding/views/res_partner_views.xml new file mode 100644 index 0000000000..0295f1688e --- /dev/null +++ b/mail_partner_forwarding/views/res_partner_views.xml @@ -0,0 +1,14 @@ + + + + res.partner.form.forwarding + res.partner + + + + + + + + diff --git a/mail_partner_forwarding/views/res_user_views.xml b/mail_partner_forwarding/views/res_user_views.xml new file mode 100644 index 0000000000..25d5b0b5cf --- /dev/null +++ b/mail_partner_forwarding/views/res_user_views.xml @@ -0,0 +1,26 @@ + + + + res.users.form.user.forwarding + res.users + + + + + + + + + res.users.form.user.forwarding.preferences + res.users + + + + + + + +