Skip to content

Commit

Permalink
[ADD] mass_mailing_multi_company
Browse files Browse the repository at this point in the history
Makes the mass_mailing module multi-company.
  • Loading branch information
MarinaAForgeFlow committed Sep 9, 2024
1 parent f73d0f2 commit 382e4ef
Show file tree
Hide file tree
Showing 19 changed files with 838 additions and 0 deletions.
79 changes: 79 additions & 0 deletions mass_mailing_multi_company/README.rst
Original file line number Diff line number Diff line change
@@ -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 <https://github.com/OCA/multi-company/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 <https://github.com/OCA/multi-company/issues/new?body=module:%20mass_mailing_multi_company%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

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

Credits
=======

Authors
~~~~~~~

* ForgeFlow S.L.

Contributors
~~~~~~~~~~~~

* Marina Alapont <[email protected]>

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 <https://github.com/OCA/multi-company/tree/16.0/mass_mailing_multi_company>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
1 change: 1 addition & 0 deletions mass_mailing_multi_company/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
19 changes: 19 additions & 0 deletions mass_mailing_multi_company/__manifest__.py
Original file line number Diff line number Diff line change
@@ -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",
],
}
4 changes: 4 additions & 0 deletions mass_mailing_multi_company/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from . import mailing_contact
from . import mailing_mailing
from . import mailing_list
from . import mailing_contact_subscription
11 changes: 11 additions & 0 deletions mass_mailing_multi_company/models/mailing_contact.py
Original file line number Diff line number Diff line change
@@ -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")
12 changes: 12 additions & 0 deletions mass_mailing_multi_company/models/mailing_contact_subscription.py
Original file line number Diff line number Diff line change
@@ -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"
)
10 changes: 10 additions & 0 deletions mass_mailing_multi_company/models/mailing_list.py
Original file line number Diff line number Diff line change
@@ -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")
36 changes: 36 additions & 0 deletions mass_mailing_multi_company/models/mailing_mailing.py
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions mass_mailing_multi_company/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Marina Alapont <[email protected]>
4 changes: 4 additions & 0 deletions mass_mailing_multi_company/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -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.

27 changes: 27 additions & 0 deletions mass_mailing_multi_company/security/mass_mailing.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo noupdate="1">
<!-- mailing.mailing -->
<record model="ir.rule" id="mailing_mailing_rule">
<field name="name">mailing.mailing multi-company</field>
<field name="model_id" ref="mass_mailing.model_mailing_mailing" />
<field name="domain_force">
['|',('company_id','=',False),('company_id','in',company_ids)]
</field>
</record>
<!-- mailing.list -->
<record model="ir.rule" id="mailing_list_rule">
<field name="name">mailing.list multi-company</field>
<field name="model_id" ref="mass_mailing.model_mailing_list" />
<field name="domain_force">
['|',('company_id','=',False),('company_id','in',company_ids)]
</field>
</record>
<!-- mailing.contact -->
<record model="ir.rule" id="mailing_contact_rule">
<field name="name">mailing.contact multi-company</field>
<field name="model_id" ref="mass_mailing.model_mailing_contact" />
<field name="domain_force">
['|',('company_id','=',False),('company_id','in',company_ids)]
</field>
</record>
</odoo>
Loading

0 comments on commit 382e4ef

Please sign in to comment.