diff --git a/mail_multicompany/README.rst b/mail_multicompany/README.rst new file mode 100644 index 00000000000..7f516da650b --- /dev/null +++ b/mail_multicompany/README.rst @@ -0,0 +1,106 @@ +.. image:: https://odoo-community.org/readme-banner-image + :target: https://odoo-community.org/get-involved?utm_source=readme + :alt: Odoo Community Association + +=========================== +Email Gateway Multi company +=========================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:bb8143cb7dcc801c2367df4a1e0c06c48bb356102cfe60dfecfeeda07882c494 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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/license-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%2Fmulti--company-lightgray.png?logo=github + :target: https://github.com/OCA/multi-company/tree/19.0/mail_multicompany + :alt: OCA/multi-company +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/multi-company-19-0/multi-company-19-0-mail_multicompany + :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/multi-company&target_branch=19.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module adds company_id to the models ir.mail_server and +mail.message. Also inherits mail.message create function to set the +company mail_server. + +**Table of contents** + +.. contents:: + :local: + +Configuration +============= + +- Go to 'Settings / Technical / Outgoing Mail Servers', and add the + company. + +Usage +===== + +To use this module, you need to: + +- Send some email or message that comes out of Odoo. + +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 +------- + +* Comunitea + +Contributors +------------ + +- Jesús Ventosinos Mayor +- Cédric Pigeon +- Valentin Vinagre +- ``Heliconia Solutions Pvt. Ltd. ``\ \_ + +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. + +.. |maintainer-luisg123v| image:: https://github.com/luisg123v.png?size=40px + :target: https://github.com/luisg123v + :alt: luisg123v + +Current `maintainer `__: + +|maintainer-luisg123v| + +This module is part of the `OCA/multi-company `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/mail_multicompany/__init__.py b/mail_multicompany/__init__.py new file mode 100644 index 00000000000..4b76c7b2d5c --- /dev/null +++ b/mail_multicompany/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from . import models diff --git a/mail_multicompany/__manifest__.py b/mail_multicompany/__manifest__.py new file mode 100644 index 00000000000..ea91c9f8c6e --- /dev/null +++ b/mail_multicompany/__manifest__.py @@ -0,0 +1,15 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). +{ + "name": "Email Gateway Multi company", + "version": "19.0.1.0.0", + "category": "Extra Tools", + "author": "Odoo Community Association (OCA), Comunitea", + "maintainers": [ + "luisg123v", + ], + "website": "https://github.com/OCA/multi-company", + "license": "AGPL-3", + "depends": ["mail"], + "data": ["security/mail_security.xml", "views/ir_mail_server_view.xml"], + "installable": True, +} diff --git a/mail_multicompany/i18n/es.po b/mail_multicompany/i18n/es.po new file mode 100644 index 00000000000..6c4bf7a80d9 --- /dev/null +++ b/mail_multicompany/i18n/es.po @@ -0,0 +1,32 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * mail_multicompany +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0+e\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2023-05-12 21:07+0000\n" +"PO-Revision-Date: 2023-05-12 21:07+0000\n" +"Last-Translator: \n" +"Language-Team: \n" +"Language: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: mail_multicompany +#: model:ir.model.fields,field_description:mail_multicompany.field_ir_mail_server__company_id +msgid "Company" +msgstr "Compañía" + +#. module: mail_multicompany +#: model:ir.model,name:mail_multicompany.model_ir_mail_server +msgid "Mail Server" +msgstr "Servidor de correo" + +#. module: mail_multicompany +#: model:ir.model,name:mail_multicompany.model_mail_message +msgid "Message" +msgstr "Mensaje" diff --git a/mail_multicompany/i18n/it.po b/mail_multicompany/i18n/it.po new file mode 100644 index 00000000000..965e33cc636 --- /dev/null +++ b/mail_multicompany/i18n/it.po @@ -0,0 +1,32 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * mail_multicompany +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 17.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2024-07-23 09:58+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 5.6.2\n" + +#. module: mail_multicompany +#: model:ir.model.fields,field_description:mail_multicompany.field_ir_mail_server__company_id +msgid "Company" +msgstr "Azienda" + +#. module: mail_multicompany +#: model:ir.model,name:mail_multicompany.model_ir_mail_server +msgid "Mail Server" +msgstr "Server di posta" + +#. module: mail_multicompany +#: model:ir.model,name:mail_multicompany.model_mail_message +msgid "Message" +msgstr "Messaggio" diff --git a/mail_multicompany/i18n/mail_multicompany.pot b/mail_multicompany/i18n/mail_multicompany.pot new file mode 100644 index 00000000000..38d95939035 --- /dev/null +++ b/mail_multicompany/i18n/mail_multicompany.pot @@ -0,0 +1,29 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * mail_multicompany +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 18.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_multicompany +#: model:ir.model.fields,field_description:mail_multicompany.field_ir_mail_server__company_id +msgid "Company" +msgstr "" + +#. module: mail_multicompany +#: model:ir.model,name:mail_multicompany.model_ir_mail_server +msgid "Mail Server" +msgstr "" + +#. module: mail_multicompany +#: model:ir.model,name:mail_multicompany.model_mail_message +msgid "Message" +msgstr "" diff --git a/mail_multicompany/models/__init__.py b/mail_multicompany/models/__init__.py new file mode 100644 index 00000000000..fca8fa21570 --- /dev/null +++ b/mail_multicompany/models/__init__.py @@ -0,0 +1,4 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from . import ir_mail_server +from . import mail_message diff --git a/mail_multicompany/models/ir_mail_server.py b/mail_multicompany/models/ir_mail_server.py new file mode 100644 index 00000000000..ff8586e941e --- /dev/null +++ b/mail_multicompany/models/ir_mail_server.py @@ -0,0 +1,9 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from odoo import fields, models + + +class IrMailServer(models.Model): + _inherit = "ir.mail_server" + + company_id = fields.Many2one("res.company", "Company") diff --git a/mail_multicompany/models/mail_message.py b/mail_multicompany/models/mail_message.py new file mode 100644 index 00000000000..715cd67359c --- /dev/null +++ b/mail_multicompany/models/mail_message.py @@ -0,0 +1,29 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from odoo import api, models + + +class MailMessage(models.Model): + _inherit = "mail.message" + + @api.model_create_multi + def create(self, vals_list): + for vals in vals_list: + if vals.get("model") and vals.get("res_id"): + current_object = self.env[vals["model"]].browse(vals["res_id"]) + if hasattr(current_object, "company_id") and current_object.company_id: + vals["record_company_id"] = current_object.company_id.id + if not vals.get("record_company_id"): + vals["record_company_id"] = self.env.company.id + if not vals.get("mail_server_id"): + vals["mail_server_id"] = ( + self.sudo() + .env["ir.mail_server"] + .search( + [("company_id", "=", vals.get("record_company_id", False))], + order="sequence", + limit=1, + ) + .id + ) + return super().create(vals_list) diff --git a/mail_multicompany/pyproject.toml b/mail_multicompany/pyproject.toml new file mode 100644 index 00000000000..4231d0cccb3 --- /dev/null +++ b/mail_multicompany/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/mail_multicompany/readme/CONFIGURE.md b/mail_multicompany/readme/CONFIGURE.md new file mode 100644 index 00000000000..4d1ac7c812b --- /dev/null +++ b/mail_multicompany/readme/CONFIGURE.md @@ -0,0 +1,2 @@ +- Go to 'Settings / Technical / Outgoing Mail Servers', and add the + company. diff --git a/mail_multicompany/readme/CONTRIBUTORS.md b/mail_multicompany/readme/CONTRIBUTORS.md new file mode 100644 index 00000000000..797b1669957 --- /dev/null +++ b/mail_multicompany/readme/CONTRIBUTORS.md @@ -0,0 +1,4 @@ +- Jesús Ventosinos Mayor \<\> +- Cédric Pigeon \<\> +- Valentin Vinagre \<\> +- `Heliconia Solutions Pvt. Ltd. `_ diff --git a/mail_multicompany/readme/DESCRIPTION.md b/mail_multicompany/readme/DESCRIPTION.md new file mode 100644 index 00000000000..f0aacec072e --- /dev/null +++ b/mail_multicompany/readme/DESCRIPTION.md @@ -0,0 +1,3 @@ +This module adds company_id to the models ir.mail_server and +mail.message. Also inherits mail.message create function to set the +company mail_server. diff --git a/mail_multicompany/readme/USAGE.md b/mail_multicompany/readme/USAGE.md new file mode 100644 index 00000000000..382b10d8776 --- /dev/null +++ b/mail_multicompany/readme/USAGE.md @@ -0,0 +1,3 @@ +To use this module, you need to: + +- Send some email or message that comes out of Odoo. diff --git a/mail_multicompany/security/mail_security.xml b/mail_multicompany/security/mail_security.xml new file mode 100644 index 00000000000..fb6ed2e1e59 --- /dev/null +++ b/mail_multicompany/security/mail_security.xml @@ -0,0 +1,23 @@ + + + + mail_server multi-company + + + ['|',('company_id','=',False),('company_id', 'in', company_ids)] + + + mail_mail multi-company + + + ['|',('record_company_id','=',False),('record_company_id', 'in', company_ids)] + + diff --git a/mail_multicompany/static/description/icon.png b/mail_multicompany/static/description/icon.png new file mode 100644 index 00000000000..3a0328b516c Binary files /dev/null and b/mail_multicompany/static/description/icon.png differ diff --git a/mail_multicompany/static/description/index.html b/mail_multicompany/static/description/index.html new file mode 100644 index 00000000000..dfcd72f2c20 --- /dev/null +++ b/mail_multicompany/static/description/index.html @@ -0,0 +1,452 @@ + + + + + +README.rst + + + +
+ + + +Odoo Community Association + +
+

Email Gateway Multi company

+ +

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

+

This module adds company_id to the models ir.mail_server and +mail.message. Also inherits mail.message create function to set the +company mail_server.

+

Table of contents

+ +
+

Configuration

+
    +
  • Go to ‘Settings / Technical / Outgoing Mail Servers’, and add the +company.
  • +
+
+
+

Usage

+

To use this module, you need to:

+
    +
  • Send some email or message that comes out of Odoo.
  • +
+
+
+

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

+
    +
  • Comunitea
  • +
+
+
+

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.

+

Current maintainer:

+

luisg123v

+

This module is part of the OCA/multi-company project on GitHub.

+

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

+
+
+
+
+ + diff --git a/mail_multicompany/tests/__init__.py b/mail_multicompany/tests/__init__.py new file mode 100644 index 00000000000..7ac2693cc96 --- /dev/null +++ b/mail_multicompany/tests/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from . import test_mail_multicompany diff --git a/mail_multicompany/tests/test_mail_multicompany.py b/mail_multicompany/tests/test_mail_multicompany.py new file mode 100644 index 00000000000..5f2685bb620 --- /dev/null +++ b/mail_multicompany/tests/test_mail_multicompany.py @@ -0,0 +1,83 @@ +# Copyright 2018 ACSONE SA/NV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from odoo import Command +from odoo.tests.common import TransactionCase + + +class TestMailMultiCompany(TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.user_demo = cls.env["res.users"].create( + {"name": "Demo", "login": "demo", "email": "demo@demo.com"} + ) + cls.user_demo.partner_id.company_id = False + company_obj = cls.env["res.company"] + server_obj = cls.env["ir.mail_server"] + cls.company1 = company_obj.create({"name": "Company 1"}) + cls.company2 = company_obj.create({"name": "Company 2"}) + cls.user_demo.write( + { + "company_id": cls.company1.id, + "company_ids": [ + Command.link(cls.company1.id), + Command.link(cls.company2.id), + ], + } + ) + cls.server1 = server_obj.create({"name": "server 1", "smtp_host": "teset.smtp"}) + cls.server2 = server_obj.create({"name": "server 1", "smtp_host": "test.smtp"}) + + def _create_message(self): + return ( + self.env["mail.message"] + .with_user(self.user_demo) + .create( + { + "reply_to": "test.reply@example.com", + "email_from": "test.from@example.com", + "author_id": self.user_demo.partner_id.id, + } + ) + ) + + def test_01_mail_message_no_company_restriction(self): + # no company_id set on server, so no one should be set on message + + msg = self._create_message() + self.assertFalse(msg.mail_server_id) + + def test_02_mail_message_company_restriction(self): + # set company 1 on server 1 + # server on message should be server 1 + self.server1.write({"company_id": self.company1.id}) + msg = self._create_message() + self.assertEqual(msg.mail_server_id.id, self.server1.id) + + # Set company 2 on server 1 + # Server on message should be empty as the copany on user is still + # Company 1 + self.server1.write({"company_id": self.company2.id}) + msg = self._create_message() + self.assertFalse(msg.mail_server_id) + + # Set company 2 on user + # Server on message should be server 1 + self.user_demo.write({"company_id": self.company2.id}) + msg = self._create_message() + self.assertEqual(msg.mail_server_id.id, self.server1.id) + + # Set Company 1 on server 1 + # Set Company 2 on server 2 + # Server on message should be server 2 + self.server1.write({"company_id": self.company1.id}) + self.server2.write({"company_id": self.company2.id}) + msg = self._create_message() + self.assertEqual(msg.mail_server_id.id, self.server2.id) + + # Set Company 1 on user + # Server on message should be server 1 + self.user_demo.write({"company_id": self.company1.id}) + msg = self._create_message() + self.assertEqual(msg.mail_server_id.id, self.server1.id) diff --git a/mail_multicompany/views/ir_mail_server_view.xml b/mail_multicompany/views/ir_mail_server_view.xml new file mode 100644 index 00000000000..e3d369cab2a --- /dev/null +++ b/mail_multicompany/views/ir_mail_server_view.xml @@ -0,0 +1,25 @@ + + + + ir.mail_server + + + + + + + + + ir.mail_server + + + + + + + +