From ed137c8a499925fbe061c68b99916146f6c407c1 Mon Sep 17 00:00:00 2001 From: sbejaoui Date: Wed, 10 Jul 2019 13:27:59 +0200 Subject: [PATCH 01/19] [ADD] - Add multi-company management to mail templates --- mail_template_multi_company/README.rst | 74 +++ mail_template_multi_company/__init__.py | 1 + mail_template_multi_company/__manifest__.py | 15 + .../models/__init__.py | 1 + .../models/mail_template.py | 18 + .../readme/CONTRIBUTORS.rst | 2 + .../readme/DESCRIPTION.rst | 1 + .../security/mail_template.xml | 17 + .../static/description/index.html | 420 ++++++++++++++++++ .../views/mail_template.xml | 42 ++ 10 files changed, 591 insertions(+) create mode 100644 mail_template_multi_company/README.rst create mode 100644 mail_template_multi_company/__init__.py create mode 100644 mail_template_multi_company/__manifest__.py create mode 100644 mail_template_multi_company/models/__init__.py create mode 100644 mail_template_multi_company/models/mail_template.py create mode 100644 mail_template_multi_company/readme/CONTRIBUTORS.rst create mode 100644 mail_template_multi_company/readme/DESCRIPTION.rst create mode 100644 mail_template_multi_company/security/mail_template.xml create mode 100644 mail_template_multi_company/static/description/index.html create mode 100644 mail_template_multi_company/views/mail_template.xml diff --git a/mail_template_multi_company/README.rst b/mail_template_multi_company/README.rst new file mode 100644 index 00000000000..6e17cb8d4f3 --- /dev/null +++ b/mail_template_multi_company/README.rst @@ -0,0 +1,74 @@ +=========================== +Mail Template 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/12.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-12-0/multi-company-12-0-mail_template_multi_company + :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/12.0 + :alt: Try me on Runbot + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module add multi-company management to mail templates + +**Table of contents** + +.. contents:: + :local: + +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 +~~~~~~~ + +* ACSONE SA/NV + +Contributors +~~~~~~~~~~~~ + +* Olivier Laurent +* Souheil Bejaoui + +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_template_multi_company/__init__.py b/mail_template_multi_company/__init__.py new file mode 100644 index 00000000000..0650744f6bc --- /dev/null +++ b/mail_template_multi_company/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/mail_template_multi_company/__manifest__.py b/mail_template_multi_company/__manifest__.py new file mode 100644 index 00000000000..ecd4375795e --- /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', + 'description': """ + Make email template a multi company model""", + 'version': '12.0.1.0.0', + 'license': 'AGPL-3', + 'author': 'ACSONE SA/NV,' + 'Odoo Community Association (OCA)', + 'website': 'https://github.com/OCA/multi-company', + 'depends': ['mail'], + 'data': ['security/mail_template.xml', 'views/mail_template.xml'], +} 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..f00b816457c --- /dev/null +++ b/mail_template_multi_company/models/mail_template.py @@ -0,0 +1,18 @@ +# 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', + 'Company', + default=lambda self: self.env['res.company']._company_default_get( + 'mail.template' + ), + ondelete='cascade', + ) diff --git a/mail_template_multi_company/readme/CONTRIBUTORS.rst b/mail_template_multi_company/readme/CONTRIBUTORS.rst new file mode 100644 index 00000000000..508a7acf8c6 --- /dev/null +++ b/mail_template_multi_company/readme/CONTRIBUTORS.rst @@ -0,0 +1,2 @@ +* Olivier Laurent +* Souheil Bejaoui diff --git a/mail_template_multi_company/readme/DESCRIPTION.rst b/mail_template_multi_company/readme/DESCRIPTION.rst new file mode 100644 index 00000000000..3bb30ee5ea0 --- /dev/null +++ b/mail_template_multi_company/readme/DESCRIPTION.rst @@ -0,0 +1 @@ +This module add multi-company management to mail templates 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..336917ce0dd --- /dev/null +++ b/mail_template_multi_company/security/mail_template.xml @@ -0,0 +1,17 @@ + + + + + + + + Mail Template multi-company + + + ['|',('company_id','=',False),('company_id','child_of',[user.company_id.id])] + + + + + 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..5768a377197 --- /dev/null +++ b/mail_template_multi_company/static/description/index.html @@ -0,0 +1,420 @@ + + + + + + +Mail Template Multi Company + + + +
+

Mail Template Multi Company

+ + +

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

+

This module add multi-company management to mail templates

+

Table of contents

+ +
+

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

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

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_template_multi_company/views/mail_template.xml b/mail_template_multi_company/views/mail_template.xml new file mode 100644 index 00000000000..b67028c0246 --- /dev/null +++ b/mail_template_multi_company/views/mail_template.xml @@ -0,0 +1,42 @@ + + + + + + + + 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 + + + + + + + + + + From b4ef9504b5cb25042235b30a8d53feac7cc2afa7 Mon Sep 17 00:00:00 2001 From: sbejaoui Date: Mon, 29 Jul 2019 15:21:16 +0200 Subject: [PATCH 02/19] [FIX] - not set the company by default on all existing mail templates --- mail_template_multi_company/__init__.py | 9 +++++++ mail_template_multi_company/__manifest__.py | 1 + .../i18n/mail_template_multi_company.pot | 26 +++++++++++++++++++ .../models/mail_template.py | 2 +- .../static/description/index.html | 2 +- .../views/mail_template.xml | 4 +-- 6 files changed, 39 insertions(+), 5 deletions(-) create mode 100644 mail_template_multi_company/i18n/mail_template_multi_company.pot diff --git a/mail_template_multi_company/__init__.py b/mail_template_multi_company/__init__.py index 0650744f6bc..1b3dc293a68 100644 --- a/mail_template_multi_company/__init__.py +++ b/mail_template_multi_company/__init__.py @@ -1 +1,10 @@ from . import models + + +def post_init_hook(cr, registry): + """ We should not set the company by default on all existing mail templates + when installing this module. Because many standard template need not be + specialized by company. + OTOH, when this module is installed it makes sense that new templates + being created by users have a company set by default. """ + 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 index ecd4375795e..e2ddabf8900 100644 --- a/mail_template_multi_company/__manifest__.py +++ b/mail_template_multi_company/__manifest__.py @@ -11,5 +11,6 @@ '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'], } 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..e686b175564 --- /dev/null +++ b/mail_template_multi_company/i18n/mail_template_multi_company.pot @@ -0,0 +1,26 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * mail_template_multi_company +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 12.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_email_template_preview__company_id +#: 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/models/mail_template.py b/mail_template_multi_company/models/mail_template.py index f00b816457c..a6500c670e4 100644 --- a/mail_template_multi_company/models/mail_template.py +++ b/mail_template_multi_company/models/mail_template.py @@ -14,5 +14,5 @@ class MailTemplate(models.Model): default=lambda self: self.env['res.company']._company_default_get( 'mail.template' ), - ondelete='cascade', + ondelete="set null", ) diff --git a/mail_template_multi_company/static/description/index.html b/mail_template_multi_company/static/description/index.html index 5768a377197..d4c4578366c 100644 --- a/mail_template_multi_company/static/description/index.html +++ b/mail_template_multi_company/static/description/index.html @@ -3,7 +3,7 @@ - + Mail Template Multi Company