From 382e4efef20a838f3db39c77b7e0432dd5a4b57c Mon Sep 17 00:00:00 2001 From: Marina Alapont Date: Mon, 9 Sep 2024 11:44:37 +0200 Subject: [PATCH] [ADD] mass_mailing_multi_company Makes the mass_mailing module multi-company. --- mass_mailing_multi_company/README.rst | 79 ++++ mass_mailing_multi_company/__init__.py | 1 + mass_mailing_multi_company/__manifest__.py | 19 + mass_mailing_multi_company/models/__init__.py | 4 + .../models/mailing_contact.py | 11 + .../models/mailing_contact_subscription.py | 12 + .../models/mailing_list.py | 10 + .../models/mailing_mailing.py | 36 ++ .../readme/CONTRIBUTORS.rst | 1 + .../readme/DESCRIPTION.rst | 4 + .../security/mass_mailing.xml | 27 ++ .../static/description/index.html | 422 ++++++++++++++++++ mass_mailing_multi_company/tests/__init__.py | 1 + .../tests/test_mass_mailing_multi_company.py | 68 +++ .../views/mailing_contact_views.xml | 40 ++ .../views/mailing_list_views.xml | 47 ++ .../views/mailing_mailing_views.xml | 49 ++ .../odoo/addons/mass_mailing_multi_company | 1 + setup/mass_mailing_multi_company/setup.py | 6 + 19 files changed, 838 insertions(+) create mode 100644 mass_mailing_multi_company/README.rst create mode 100644 mass_mailing_multi_company/__init__.py create mode 100644 mass_mailing_multi_company/__manifest__.py create mode 100644 mass_mailing_multi_company/models/__init__.py create mode 100644 mass_mailing_multi_company/models/mailing_contact.py create mode 100644 mass_mailing_multi_company/models/mailing_contact_subscription.py create mode 100644 mass_mailing_multi_company/models/mailing_list.py create mode 100644 mass_mailing_multi_company/models/mailing_mailing.py create mode 100644 mass_mailing_multi_company/readme/CONTRIBUTORS.rst create mode 100644 mass_mailing_multi_company/readme/DESCRIPTION.rst create mode 100644 mass_mailing_multi_company/security/mass_mailing.xml create mode 100644 mass_mailing_multi_company/static/description/index.html create mode 100644 mass_mailing_multi_company/tests/__init__.py create mode 100644 mass_mailing_multi_company/tests/test_mass_mailing_multi_company.py create mode 100644 mass_mailing_multi_company/views/mailing_contact_views.xml create mode 100644 mass_mailing_multi_company/views/mailing_list_views.xml create mode 100644 mass_mailing_multi_company/views/mailing_mailing_views.xml create mode 120000 setup/mass_mailing_multi_company/odoo/addons/mass_mailing_multi_company create mode 100644 setup/mass_mailing_multi_company/setup.py diff --git a/mass_mailing_multi_company/README.rst b/mass_mailing_multi_company/README.rst new file mode 100644 index 00000000000..b8a2785f035 --- /dev/null +++ b/mass_mailing_multi_company/README.rst @@ -0,0 +1,79 @@ +========================== +Mass Mailing Multi Company +========================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:888dbb914348b16006efb3682ed186e3c59140537690b30242cd5c8f4a4b859c + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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/16.0/mass_mailing_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-16-0/multi-company-16-0-mass_mailing_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=16.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module adds the company_id field to the models mailing.mailing, mailing.list, mailing.contact and mailing.contact.subscription. +It also ensures that the lists available for selection in the mailing.mailing and mailing.contact forms are restricted by the company_id value. +For the mailing.mailing domain, an expression matching only contacts/mailing contacts with the same company or without company is added when parsing the domain. + + +**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 to smash it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* ForgeFlow S.L. + +Contributors +~~~~~~~~~~~~ + +* Marina Alapont + +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/mass_mailing_multi_company/__init__.py b/mass_mailing_multi_company/__init__.py new file mode 100644 index 00000000000..0650744f6bc --- /dev/null +++ b/mass_mailing_multi_company/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/mass_mailing_multi_company/__manifest__.py b/mass_mailing_multi_company/__manifest__.py new file mode 100644 index 00000000000..345a884eb29 --- /dev/null +++ b/mass_mailing_multi_company/__manifest__.py @@ -0,0 +1,19 @@ +# Copyright 2024 ForgeFlow S.L. +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +{ + "name": "Mass Mailing Multi Company", + "summary": "Adds the company_id field to the models mailing.mailing," + " mailing.list and mailing.contact", + "version": "16.0.1.0.0", + "license": "AGPL-3", + "author": "ForgeFlow S.L., Odoo Community Association (OCA)", + "website": "https://github.com/OCA/multi-company", + "depends": ["mass_mailing"], + "data": [ + "security/mass_mailing.xml", + "views/mailing_mailing_views.xml", + "views/mailing_list_views.xml", + "views/mailing_contact_views.xml", + ], +} diff --git a/mass_mailing_multi_company/models/__init__.py b/mass_mailing_multi_company/models/__init__.py new file mode 100644 index 00000000000..bfc21a82793 --- /dev/null +++ b/mass_mailing_multi_company/models/__init__.py @@ -0,0 +1,4 @@ +from . import mailing_contact +from . import mailing_mailing +from . import mailing_list +from . import mailing_contact_subscription diff --git a/mass_mailing_multi_company/models/mailing_contact.py b/mass_mailing_multi_company/models/mailing_contact.py new file mode 100644 index 00000000000..465ab84a30a --- /dev/null +++ b/mass_mailing_multi_company/models/mailing_contact.py @@ -0,0 +1,11 @@ +# Copyright 2024 ForgeFlow S.L. +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + + +from odoo import fields, models + + +class MassMailingContact(models.Model): + _inherit = "mailing.contact" + + company_id = fields.Many2one("res.company", "Company") diff --git a/mass_mailing_multi_company/models/mailing_contact_subscription.py b/mass_mailing_multi_company/models/mailing_contact_subscription.py new file mode 100644 index 00000000000..e9cb2a945a5 --- /dev/null +++ b/mass_mailing_multi_company/models/mailing_contact_subscription.py @@ -0,0 +1,12 @@ +# Copyright 2024 ForgeFlow S.L. +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import fields, models + + +class MassMailingContactListRel(models.Model): + _inherit = "mailing.contact.subscription" + + company_id = fields.Many2one( + "res.company", "Company", related="contact_id.company_id" + ) diff --git a/mass_mailing_multi_company/models/mailing_list.py b/mass_mailing_multi_company/models/mailing_list.py new file mode 100644 index 00000000000..e529bcd099e --- /dev/null +++ b/mass_mailing_multi_company/models/mailing_list.py @@ -0,0 +1,10 @@ +# Copyright 2024 ForgeFlow S.L. +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import fields, models + + +class MassMailingList(models.Model): + _inherit = "mailing.list" + + company_id = fields.Many2one("res.company", "Company") diff --git a/mass_mailing_multi_company/models/mailing_mailing.py b/mass_mailing_multi_company/models/mailing_mailing.py new file mode 100644 index 00000000000..ac955a654d9 --- /dev/null +++ b/mass_mailing_multi_company/models/mailing_mailing.py @@ -0,0 +1,36 @@ +# Copyright 2024 ForgeFlow S.L. +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import _, fields, models +from odoo.odoo.exceptions import ValidationError +from odoo.osv import expression + + +class MassMailing(models.Model): + _inherit = "mailing.mailing" + + company_id = fields.Many2one("res.company", "Company") + + def _parse_mailing_domain(self): + domain = super()._parse_mailing_domain() + company_domain = [ + "|", + ("company_id", "=", self.company_id.id), + ("company_id", "=", False), + ] + existing_company_expressions = [ + expr for expr in domain if expr[0] == "company_id" + ] + if existing_company_expressions: + for expr in existing_company_expressions: + if expr[2] and expr[2] != self.company_id.id: + raise ValidationError( + _( + "If the newsletter has a company ID, existing company ID" + " expressions in the filter domain should match the current" + " newsletter company ID. Please adjust the domain accordingly." + ) + ) + elif self.company_id: + domain = expression.AND([domain, company_domain]) + return domain diff --git a/mass_mailing_multi_company/readme/CONTRIBUTORS.rst b/mass_mailing_multi_company/readme/CONTRIBUTORS.rst new file mode 100644 index 00000000000..82fa316ae83 --- /dev/null +++ b/mass_mailing_multi_company/readme/CONTRIBUTORS.rst @@ -0,0 +1 @@ +* Marina Alapont diff --git a/mass_mailing_multi_company/readme/DESCRIPTION.rst b/mass_mailing_multi_company/readme/DESCRIPTION.rst new file mode 100644 index 00000000000..4c746518b81 --- /dev/null +++ b/mass_mailing_multi_company/readme/DESCRIPTION.rst @@ -0,0 +1,4 @@ +This module adds the company_id field to the models mailing.mailing, mailing.list, mailing.contact and mailing.contact.subscription. +It also ensures that the lists available for selection in the mailing.mailing and mailing.contact forms are restricted by the company_id value. +For the mailing.mailing domain, an expression matching only contacts/mailing contacts with the same company or without company is added when parsing the domain. + diff --git a/mass_mailing_multi_company/security/mass_mailing.xml b/mass_mailing_multi_company/security/mass_mailing.xml new file mode 100644 index 00000000000..c34f61c030b --- /dev/null +++ b/mass_mailing_multi_company/security/mass_mailing.xml @@ -0,0 +1,27 @@ + + + + + mailing.mailing multi-company + + + ['|',('company_id','=',False),('company_id','in',company_ids)] + + + + + mailing.list multi-company + + + ['|',('company_id','=',False),('company_id','in',company_ids)] + + + + + mailing.contact multi-company + + + ['|',('company_id','=',False),('company_id','in',company_ids)] + + + diff --git a/mass_mailing_multi_company/static/description/index.html b/mass_mailing_multi_company/static/description/index.html new file mode 100644 index 00000000000..b06b5a8f2f4 --- /dev/null +++ b/mass_mailing_multi_company/static/description/index.html @@ -0,0 +1,422 @@ + + + + + +Mass Mailing Multi Company + + + +
+

Mass Mailing Multi Company

+ + +

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

+

This module adds the company_id field to the models mailing.mailing, mailing.list, mailing.contact and mailing.contact.subscription. +It also ensures that the lists available for selection in the mailing.mailing and mailing.contact forms are restricted by the company_id value. +For the mailing.mailing domain, an expression matching only contacts/mailing contacts with the same company or without company is added when parsing the domain.

+

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 to smash it by providing a detailed and welcomed +feedback.

+

Do not contact contributors directly about support or help with technical issues.

+
+
+

Credits

+
+

Authors

+
    +
  • ForgeFlow S.L.
  • +
+
+
+

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/mass_mailing_multi_company/tests/__init__.py b/mass_mailing_multi_company/tests/__init__.py new file mode 100644 index 00000000000..54e85a50f2b --- /dev/null +++ b/mass_mailing_multi_company/tests/__init__.py @@ -0,0 +1 @@ +from . import test_mass_mailing_multi_company diff --git a/mass_mailing_multi_company/tests/test_mass_mailing_multi_company.py b/mass_mailing_multi_company/tests/test_mass_mailing_multi_company.py new file mode 100644 index 00000000000..c8ffdfb17f0 --- /dev/null +++ b/mass_mailing_multi_company/tests/test_mass_mailing_multi_company.py @@ -0,0 +1,68 @@ +# Copyright 2024 ForgeFlow S.L. +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo.odoo.exceptions import ValidationError +from odoo.tests.common import TransactionCase + + +class TestMassMailingMultiCompany(TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + + cls.company1 = cls.env["res.company"].create({"name": "Company 1"}) + + cls.mailing = cls.env["mailing.mailing"].create( + { + "name": "Test Mailing", + "subject": "Test", + "company_id": cls.company1.id, + "mailing_domain": [("is_blacklisted", "=", False)], + } + ) + + def test_parse_mailing_domain(self): + """Test the _parse_mailing_domain method""" + self.mailing.company_id = False + self.assertEqual( + self.mailing._parse_mailing_domain(), [("is_blacklisted", "=", False)] + ) + + self.mailing.company_id = self.company1 + expected_domain = [ + "&", + ("is_blacklisted", "=", False), + "|", + ("company_id", "=", self.company1.id), + ("company_id", "=", False), + ] + self.assertEqual(self.mailing._parse_mailing_domain(), expected_domain) + + self.mailing.mailing_domain = "invalid_domain" + self.assertEqual( + self.mailing._parse_mailing_domain(), + [ + "&", + ("id", "in", []), + "|", + ("company_id", "=", self.company1.id), + ("company_id", "=", False), + ], + ) + + expected_domain = [ + "|", + ("company_id", "=", self.company1.id), + ("company_id", "=", False), + ] + self.mailing.mailing_domain = ( + "['|', ('company_id', '=', %s), ('company_id', '=', False)]" + % self.company1.id + ) + self.assertEqual(self.mailing._parse_mailing_domain(), expected_domain) + + self.mailing.mailing_domain = ( + "['|', ('company_id', '=', 5623), ('company_id', '=', False)]" + ) + with self.assertRaises(ValidationError): + self.mailing._parse_mailing_domain() diff --git a/mass_mailing_multi_company/views/mailing_contact_views.xml b/mass_mailing_multi_company/views/mailing_contact_views.xml new file mode 100644 index 00000000000..25c92f5fc9c --- /dev/null +++ b/mass_mailing_multi_company/views/mailing_contact_views.xml @@ -0,0 +1,40 @@ + + + + mailing.contact.view.tree + mailing.contact + + + + + + + + + + mailing.contact.view.form + mailing.contact + + + + + + + + + + + ['|',('company_id', '=', company_id),('company_id', '=', False)] + + + + + diff --git a/mass_mailing_multi_company/views/mailing_list_views.xml b/mass_mailing_multi_company/views/mailing_list_views.xml new file mode 100644 index 00000000000..81ba18218ea --- /dev/null +++ b/mass_mailing_multi_company/views/mailing_list_views.xml @@ -0,0 +1,47 @@ + + + + mailing.list.view.tree + mailing.list + + + + + + + + + + mailing.list.form + mailing.list + + + + + + + + + + mailing.list.form.simplified + mailing.list + + + + + + + + diff --git a/mass_mailing_multi_company/views/mailing_mailing_views.xml b/mass_mailing_multi_company/views/mailing_mailing_views.xml new file mode 100644 index 00000000000..d813127a13b --- /dev/null +++ b/mass_mailing_multi_company/views/mailing_mailing_views.xml @@ -0,0 +1,49 @@ + + + + mailing.mailing.tree + mailing.mailing + + + + + + + + + + mailing.mailing.form + mailing.mailing + + + + + + + + + + + + + + ['|',('company_id', '=', company_id),('company_id', '=', False)] + + + + + diff --git a/setup/mass_mailing_multi_company/odoo/addons/mass_mailing_multi_company b/setup/mass_mailing_multi_company/odoo/addons/mass_mailing_multi_company new file mode 120000 index 00000000000..a7c83558da3 --- /dev/null +++ b/setup/mass_mailing_multi_company/odoo/addons/mass_mailing_multi_company @@ -0,0 +1 @@ +../../../../mass_mailing_multi_company \ No newline at end of file diff --git a/setup/mass_mailing_multi_company/setup.py b/setup/mass_mailing_multi_company/setup.py new file mode 100644 index 00000000000..28c57bb6403 --- /dev/null +++ b/setup/mass_mailing_multi_company/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)