diff --git a/mail_multicompany/README.rst b/mail_multicompany/README.rst new file mode 100644 index 0000000..bf642a5 --- /dev/null +++ b/mail_multicompany/README.rst @@ -0,0 +1,87 @@ +=========================== +Email Gateway Multi company +=========================== + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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%2Fmulti--company-lightgray.png?logo=github + :target: https://github.com/OCA/multi-company/tree/14.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-14-0/multi-company-14-0-mail_multicompany + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png + :target: https://runbot.odoo-community.org/runbot/133/14.0 + :alt: Try me on Runbot + +|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 smashing 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 + +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/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 0000000..4b76c7b --- /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 0000000..3240c82 --- /dev/null +++ b/mail_multicompany/__manifest__.py @@ -0,0 +1,13 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). +{ + "name": "Email Gateway Multi company", + "version": "12.0.0.1.0", + "category": "Extra Tools", + "author": "Odoo Community Association (OCA), " "Comunitea, " "GRAP", + "maintainers": ["quentinDupont"], + "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 0000000..42c40ca --- /dev/null +++ b/mail_multicompany/i18n/es.po @@ -0,0 +1,34 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * mail_multicompany +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 13.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2021-03-09 17:45+0000\n" +"Last-Translator: Ana Suárez \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.3.2\n" + +#. module: mail_multicompany +#: model:ir.model.fields,field_description:mail_multicompany.field_ir_mail_server__company_id +#: model:ir.model.fields,field_description:mail_multicompany.field_mail_mail__company_id +#: model:ir.model.fields,field_description:mail_multicompany.field_mail_message__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 email" + +#. module: mail_multicompany +#: model:ir.model,name:mail_multicompany.model_mail_message +msgid "Message" +msgstr "Mensaje" diff --git a/mail_multicompany/i18n/mail_multicompany.pot b/mail_multicompany/i18n/mail_multicompany.pot new file mode 100644 index 0000000..88d5a36 --- /dev/null +++ b/mail_multicompany/i18n/mail_multicompany.pot @@ -0,0 +1,49 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * mail_multicompany +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 14.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 +#: model:ir.model.fields,field_description:mail_multicompany.field_mail_mail__company_id +#: model:ir.model.fields,field_description:mail_multicompany.field_mail_message__company_id +msgid "Company" +msgstr "" + +#. module: mail_multicompany +#: model:ir.model.fields,field_description:mail_multicompany.field_ir_mail_server__display_name +#: model:ir.model.fields,field_description:mail_multicompany.field_mail_message__display_name +msgid "Display Name" +msgstr "" + +#. module: mail_multicompany +#: model:ir.model.fields,field_description:mail_multicompany.field_ir_mail_server__id +#: model:ir.model.fields,field_description:mail_multicompany.field_mail_message__id +msgid "ID" +msgstr "" + +#. module: mail_multicompany +#: model:ir.model.fields,field_description:mail_multicompany.field_ir_mail_server____last_update +#: model:ir.model.fields,field_description:mail_multicompany.field_mail_message____last_update +msgid "Last Modified on" +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 0000000..fca8fa2 --- /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 0000000..791f7d3 --- /dev/null +++ b/mail_multicompany/models/ir_mail_server.py @@ -0,0 +1,10 @@ +# 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 0000000..ab8def4 --- /dev/null +++ b/mail_multicompany/models/mail_message.py @@ -0,0 +1,34 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from odoo import api, fields, models + + +class MailMessage(models.Model): + + _inherit = "mail.message" + + company_id = fields.Many2one("res.company", "Company") + + @api.model_create_multi + def create(self, values_list): + for vals in values_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["company_id"] = current_object.company_id.id + if not vals.get("company_id"): + vals["company_id"] = self.env.user.company_id.id + # Search SMTP server with company_id or shared SMTP server + if not vals.get("mail_server_id"): + vals["mail_server_id"] = ( + self.sudo() + .env["ir.mail_server"] + .search( + ['|', ("company_id", "=", vals.get("company_id", False)), + ("company_id", "=", False)], + order="sequence", + limit=1, + ) + .id + ) + return super(MailMessage, self).create(vals) diff --git a/mail_multicompany/readme/CONFIGURE.rst b/mail_multicompany/readme/CONFIGURE.rst new file mode 100644 index 0000000..01942ce --- /dev/null +++ b/mail_multicompany/readme/CONFIGURE.rst @@ -0,0 +1,2 @@ +* Go to 'Settings / Technical / Outgoing Mail Servers', and add the company. +* Note that Odoo will select the server (using sequence) from among the available servers (those with the correct company_id and shared servers). diff --git a/mail_multicompany/readme/CONTRIBUTORS.rst b/mail_multicompany/readme/CONTRIBUTORS.rst new file mode 100644 index 0000000..df86ddd --- /dev/null +++ b/mail_multicompany/readme/CONTRIBUTORS.rst @@ -0,0 +1,4 @@ +* Jesús Ventosinos Mayor +* Cédric Pigeon +* Valentin Vinagre +* Quentin Dupont diff --git a/mail_multicompany/readme/DESCRIPTION.rst b/mail_multicompany/readme/DESCRIPTION.rst new file mode 100644 index 0000000..4b34854 --- /dev/null +++ b/mail_multicompany/readme/DESCRIPTION.rst @@ -0,0 +1 @@ +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.rst b/mail_multicompany/readme/USAGE.rst new file mode 100644 index 0000000..734066e --- /dev/null +++ b/mail_multicompany/readme/USAGE.rst @@ -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 0000000..1821e40 --- /dev/null +++ b/mail_multicompany/security/mail_security.xml @@ -0,0 +1,19 @@ + + + + mail_server multi-company + + + ['|',('company_id','=',False),('company_id','child_of',[user.company_id.id])] + + + mail_mail multi-company + + + ['|',('company_id','=',False),('company_id','child_of',[user.company_id.id])] + + diff --git a/mail_multicompany/static/description/icon.png b/mail_multicompany/static/description/icon.png new file mode 100644 index 0000000..3a0328b 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 0000000..9dce96d --- /dev/null +++ b/mail_multicompany/static/description/index.html @@ -0,0 +1,436 @@ + + + + + + +Email Gateway Multi company + + + +
+

Email Gateway Multi company

+ + +

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

+

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

+

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 0000000..7ac2693 --- /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 0000000..d565bd7 --- /dev/null +++ b/mail_multicompany/tests/test_mail_multicompany.py @@ -0,0 +1,78 @@ +# Copyright 2018 ACSONE SA/NV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from odoo.tests.common import TransactionCase + + +class TestMailMultiCompany(TransactionCase): + def _create_message(self): + return ( + self.env["mail.message"] + .sudo(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 setUp(self): + super().setUp() + self.user_demo = self.env.ref("base.user_demo") + company_obj = self.env["res.company"] + server_obj = self.env["ir.mail_server"] + self.company1 = company_obj.create({"name": "Company 1"}) + self.company2 = company_obj.create({"name": "Company 2"}) + self.user_demo.write( + { + "company_id": self.company1.id, + "company_ids": [(4, self.company1.id), (4, self.company2.id)], + } + ) + self.server1 = server_obj.create( + {"name": "server 1", "smtp_host": "test.smtp1", "sequence": 1} + ) + self.server2 = server_obj.create( + {"name": "server 2", "smtp_host": "test.smtp2", "sequence": 2}) + + def test_mail_message_no_company_restriction(self): + # no company_id set on server, so it's should be the first on list + msg = self._create_message() + self.assertEqual(msg.mail_server_id.id, self.server1.id) + + def test_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 and server 2 + # Server on message should be empty as the company on user is still + # Company 1 + self.server1.write({"company_id": self.company2.id}) + self.server2.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 0000000..e3d369c --- /dev/null +++ b/mail_multicompany/views/ir_mail_server_view.xml @@ -0,0 +1,25 @@ + + + + ir.mail_server + + + + + + + + + ir.mail_server + + + + + + + +