diff --git a/mail_template_multi_company/README.rst b/mail_template_multi_company/README.rst new file mode 100644 index 00000000000..ce026d2e248 --- /dev/null +++ b/mail_template_multi_company/README.rst @@ -0,0 +1,110 @@ +.. image:: https://odoo-community.org/readme-banner-image + :target: https://odoo-community.org/get-involved?utm_source=readme + :alt: Odoo Community Association + +=========================== +Mail Template Multi Company +=========================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:482bf79a33c0d9d05b608be3c5271c9bd47e27bdbb1132ceb9f6e3cc1b5bd21f + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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_template_multi_company + :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_template_multi_company + :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 add multi-company management to mail templates. + +**Table of contents** + +.. contents:: + :local: + +Configuration +============= + +- Go to *Settings > General Settings* +- Activate the multi-company +- Go to *Settings > User & Companies > Users* +- Select your user to edit it and active the multi-company + +Usage +===== + +- Go to *Settings* +- Activate the developer mode +- Go to *Settings > Technical > Email > Templates* +- Open a template and set the company field if the template is specific + to a company + +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 +------- + +* ACSONE SA/NV + +Contributors +------------ + +- Olivier Laurent +- Souheil Bejaoui +- Andrea Stirpe +- Alberto Nieto de Pablos + (https://braintec.com) +- `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-Olivier-LAURENT| image:: https://github.com/Olivier-LAURENT.png?size=40px + :target: https://github.com/Olivier-LAURENT + :alt: Olivier-LAURENT + +Current `maintainer `__: + +|maintainer-Olivier-LAURENT| + +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_template_multi_company/__init__.py b/mail_template_multi_company/__init__.py new file mode 100644 index 00000000000..a644efbb5dd --- /dev/null +++ b/mail_template_multi_company/__init__.py @@ -0,0 +1,11 @@ +from . import models + + +def post_init_hook(env): + """We should not set the company by default on all existing mail templates + when installing this module, as many standard templates do not need to + be company-specific. + Since Odoo 16.0, the default `company_id` on new mail templates has been `False`, + which aligns with this behavior. However, when users create new templates, + it is still reasonable to default to the current company if applicable.""" + env.cr.execute("UPDATE mail_template SET company_id=null") diff --git a/mail_template_multi_company/__manifest__.py b/mail_template_multi_company/__manifest__.py new file mode 100644 index 00000000000..a4fa3a1c1b5 --- /dev/null +++ b/mail_template_multi_company/__manifest__.py @@ -0,0 +1,15 @@ +# Copyright 2017 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +{ + "name": "Mail Template Multi Company", + "version": "19.0.1.0.0", + "license": "AGPL-3", + "author": "ACSONE SA/NV,Odoo Community Association (OCA)", + "website": "https://github.com/OCA/multi-company", + "depends": ["mail"], + "post_init_hook": "post_init_hook", + "data": ["security/mail_template.xml", "views/mail_template.xml"], + "development_status": "Beta", + "maintainers": ["Olivier-LAURENT"], +} diff --git a/mail_template_multi_company/i18n/es.po b/mail_template_multi_company/i18n/es.po new file mode 100644 index 00000000000..d7e970c3ad6 --- /dev/null +++ b/mail_template_multi_company/i18n/es.po @@ -0,0 +1,27 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * mail_template_multi_company +# +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_template_multi_company +#: model:ir.model.fields,field_description:mail_template_multi_company.field_mail_template__company_id +msgid "Company" +msgstr "Compañía" + +#. module: mail_template_multi_company +#: model:ir.model,name:mail_template_multi_company.model_mail_template +msgid "Email Templates" +msgstr "Plantillas de email" diff --git a/mail_template_multi_company/i18n/it.po b/mail_template_multi_company/i18n/it.po new file mode 100644 index 00000000000..da55f19f01c --- /dev/null +++ b/mail_template_multi_company/i18n/it.po @@ -0,0 +1,27 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * mail_template_multi_company +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2024-01-19 19:35+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_template_multi_company +#: model:ir.model.fields,field_description:mail_template_multi_company.field_mail_template__company_id +msgid "Company" +msgstr "Azienda" + +#. module: mail_template_multi_company +#: model:ir.model,name:mail_template_multi_company.model_mail_template +msgid "Email Templates" +msgstr "Modelli e-mail" diff --git a/mail_template_multi_company/i18n/mail_template_multi_company.pot b/mail_template_multi_company/i18n/mail_template_multi_company.pot new file mode 100644 index 00000000000..5fb7070d577 --- /dev/null +++ b/mail_template_multi_company/i18n/mail_template_multi_company.pot @@ -0,0 +1,24 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * mail_template_multi_company +# +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_template_multi_company +#: model:ir.model.fields,field_description:mail_template_multi_company.field_mail_template__company_id +msgid "Company" +msgstr "" + +#. module: mail_template_multi_company +#: model:ir.model,name:mail_template_multi_company.model_mail_template +msgid "Email Templates" +msgstr "" diff --git a/mail_template_multi_company/i18n/nl.po b/mail_template_multi_company/i18n/nl.po new file mode 100644 index 00000000000..3619108c28b --- /dev/null +++ b/mail_template_multi_company/i18n/nl.po @@ -0,0 +1,27 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * mail_template_multi_company +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 15.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2023-06-23 19:09+0000\n" +"Last-Translator: Bosd \n" +"Language-Team: none\n" +"Language: nl\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_template_multi_company +#: model:ir.model.fields,field_description:mail_template_multi_company.field_mail_template__company_id +msgid "Company" +msgstr "Bedrijf" + +#. module: mail_template_multi_company +#: model:ir.model,name:mail_template_multi_company.model_mail_template +msgid "Email Templates" +msgstr "Email Sjablonen" diff --git a/mail_template_multi_company/models/__init__.py b/mail_template_multi_company/models/__init__.py new file mode 100644 index 00000000000..44e83956ebe --- /dev/null +++ b/mail_template_multi_company/models/__init__.py @@ -0,0 +1 @@ +from . import mail_template diff --git a/mail_template_multi_company/models/mail_template.py b/mail_template_multi_company/models/mail_template.py new file mode 100644 index 00000000000..af32307ffe9 --- /dev/null +++ b/mail_template_multi_company/models/mail_template.py @@ -0,0 +1,13 @@ +# Copyright 2017 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import fields, models + + +class MailTemplate(models.Model): + _inherit = "mail.template" + + company_id = fields.Many2one( + "res.company", + ondelete="set null", + ) diff --git a/mail_template_multi_company/pyproject.toml b/mail_template_multi_company/pyproject.toml new file mode 100644 index 00000000000..4231d0cccb3 --- /dev/null +++ b/mail_template_multi_company/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/mail_template_multi_company/readme/CONFIGURE.md b/mail_template_multi_company/readme/CONFIGURE.md new file mode 100644 index 00000000000..d4f5cd11442 --- /dev/null +++ b/mail_template_multi_company/readme/CONFIGURE.md @@ -0,0 +1,4 @@ +- Go to *Settings \> General Settings* +- Activate the multi-company +- Go to *Settings \> User & Companies \> Users* +- Select your user to edit it and active the multi-company diff --git a/mail_template_multi_company/readme/CONTRIBUTORS.md b/mail_template_multi_company/readme/CONTRIBUTORS.md new file mode 100644 index 00000000000..ebf5a5e517d --- /dev/null +++ b/mail_template_multi_company/readme/CONTRIBUTORS.md @@ -0,0 +1,6 @@ +- Olivier Laurent \<\> +- Souheil Bejaoui \<\> +- Andrea Stirpe \<\> +- Alberto Nieto de Pablos \<\> + () +- [Heliconia Solutions Pvt. Ltd.](https://www.heliconia.io) diff --git a/mail_template_multi_company/readme/DESCRIPTION.md b/mail_template_multi_company/readme/DESCRIPTION.md new file mode 100644 index 00000000000..74ba8da34a1 --- /dev/null +++ b/mail_template_multi_company/readme/DESCRIPTION.md @@ -0,0 +1 @@ +This module add multi-company management to mail templates. diff --git a/mail_template_multi_company/readme/USAGE.md b/mail_template_multi_company/readme/USAGE.md new file mode 100644 index 00000000000..b49118a26ae --- /dev/null +++ b/mail_template_multi_company/readme/USAGE.md @@ -0,0 +1,5 @@ +- Go to *Settings* +- Activate the developer mode +- Go to *Settings \> Technical \> Email \> Templates* +- Open a template and set the company field if the template is specific + to a company diff --git a/mail_template_multi_company/security/mail_template.xml b/mail_template_multi_company/security/mail_template.xml new file mode 100644 index 00000000000..8b173000328 --- /dev/null +++ b/mail_template_multi_company/security/mail_template.xml @@ -0,0 +1,12 @@ + + + + + Mail Template multi-company + + + ['|',('company_id','=',False),('company_id','in',company_ids)] + + + diff --git a/mail_template_multi_company/static/description/icon.png b/mail_template_multi_company/static/description/icon.png new file mode 100644 index 00000000000..3a0328b516c Binary files /dev/null and b/mail_template_multi_company/static/description/icon.png differ diff --git a/mail_template_multi_company/static/description/index.html b/mail_template_multi_company/static/description/index.html new file mode 100644 index 00000000000..881d8a3b85d --- /dev/null +++ b/mail_template_multi_company/static/description/index.html @@ -0,0 +1,457 @@ + + + + + +README.rst + + + +
+ + + +Odoo Community Association + +
+

Mail Template Multi Company

+ +

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

+

This module add multi-company management to mail templates.

+

Table of contents

+ +
+

Configuration

+
    +
  • Go to Settings > General Settings
  • +
  • Activate the multi-company
  • +
  • Go to Settings > User & Companies > Users
  • +
  • Select your user to edit it and active the multi-company
  • +
+
+
+

Usage

+
    +
  • Go to Settings
  • +
  • Activate the developer mode
  • +
  • Go to Settings > Technical > Email > Templates
  • +
  • Open a template and set the company field if the template is specific +to a company
  • +
+
+
+

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

+
    +
  • ACSONE SA/NV
  • +
+
+ +
+

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:

+

Olivier-LAURENT

+

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_template_multi_company/tests/__init__.py b/mail_template_multi_company/tests/__init__.py new file mode 100644 index 00000000000..b3ad65b4633 --- /dev/null +++ b/mail_template_multi_company/tests/__init__.py @@ -0,0 +1 @@ +from . import test_mail_template diff --git a/mail_template_multi_company/tests/test_mail_template.py b/mail_template_multi_company/tests/test_mail_template.py new file mode 100644 index 00000000000..91a77e8fa51 --- /dev/null +++ b/mail_template_multi_company/tests/test_mail_template.py @@ -0,0 +1,97 @@ +from odoo import Command + +from odoo.addons.base.tests.common import BaseCommon + + +class TestMailTemplateMultiCompany(BaseCommon): + @classmethod + def setUpClass(cls): + super().setUpClass() + # Create a company + cls.company = cls.env["res.company"].create({"name": "Test Company"}) + + # Create a user in the multi-company group + cls.multi_company_user = cls.env["res.users"].create( + { + "name": "Multi Company User", + "login": "multi_company_user", + "email": "multi_company_user@example.com", + "group_ids": [ + (Command.set([cls.env.ref("base.group_multi_company").id])) + ], + } + ) + + # Create a mail template + cls.mail_template = cls.env["mail.template"].create( + { + "name": "Test Template", + "subject": "Test Subject", + "company_id": cls.company.id, + } + ) + + def test_company_id_field(self): + """Test that the company_id field is correctly set and retrieved.""" + self.assertEqual( + self.mail_template.company_id, + self.company, + "The company_id field should be correctly set in the mail template", + ) + + def test_field_visibility_in_views(self): + """Test that the company_id field appears in views for multi-company users.""" + FormView = self.env.ref("mail_template_multi_company.mail_template_form_view") + TreeView = self.env.ref("mail_template_multi_company.mail_template_tree_view") + SearchView = self.env.ref( + "mail_template_multi_company.mail_template_search_view" + ) + + # Simulate view rendering (pseudo-validation) + self.assertTrue( + "company_id" in FormView.arch, + "The company_id field should appear in the form view for mail templates", + ) + self.assertTrue( + "company_id" in TreeView.arch, + "The company_id field should appear in the tree view for mail templates", + ) + self.assertTrue( + "company_id" in SearchView.arch, + "The company_id field should appear in the search view for mail templates", + ) + + def test_field_accessibility(self): + # Create a user without access to the field + restricted_user = self.env["res.users"].create( + { + "name": "Restricted User", + "login": "restricted_user", + "email": "restricted_user@example.com", + "group_ids": [(6, 0, [self.env.ref("base.group_user").id])], + } + ) + + # Create a mail template as the restricted user + mail_template = ( + self.env["mail.template"] + .with_user(restricted_user) + .create( + { + "name": "Test Template", + "subject": "Test", + "body_html": "

Test Body

", + } + ) + ) + self.assertFalse(mail_template.company_id) + + def test_default_company_id(self): + """Test that the company_id field defaults to False if not set.""" + template_without_company = self.env["mail.template"].create( + {"name": "No Company Template"} + ) + self.assertFalse( + template_without_company.company_id, + "The company_id field should be empty by default if not explicitly set", + ) diff --git a/mail_template_multi_company/views/mail_template.xml b/mail_template_multi_company/views/mail_template.xml new file mode 100644 index 00000000000..b6775a6ae35 --- /dev/null +++ b/mail_template_multi_company/views/mail_template.xml @@ -0,0 +1,39 @@ + + + + + mail.template.form (in mail_template_multi_company) + mail.template + + + + + + + + + mail.template.search (in mail_template_multi_company) + mail.template + + + + + + + + + mail.template.tree (in mail_template_multi_company) + mail.template + + + + + + + +