From 9227010d4b6387369dc139774ec2738638f5cc96 Mon Sep 17 00:00:00 2001 From: AaronHForgeFlow Date: Tue, 14 Apr 2026 16:41:58 +0200 Subject: [PATCH] [ADD] mass_mailing_partner_subscription --- mass_mailing_partner_subscription/README.rst | 117 +++++ mass_mailing_partner_subscription/__init__.py | 1 + .../__manifest__.py | 15 + .../models/__init__.py | 1 + .../models/res_partner.py | 39 ++ .../pyproject.toml | 3 + .../readme/CONTRIBUTORS.md | 3 + .../readme/DESCRIPTION.md | 10 + .../readme/ROADMAP.md | 5 + .../readme/USAGE.md | 7 + .../static/description/index.html | 465 ++++++++++++++++++ .../tests/__init__.py | 1 + .../tests/test_res_partner_mailing_list.py | 41 ++ .../views/res_partner_views.xml | 29 ++ 14 files changed, 737 insertions(+) create mode 100644 mass_mailing_partner_subscription/README.rst create mode 100644 mass_mailing_partner_subscription/__init__.py create mode 100644 mass_mailing_partner_subscription/__manifest__.py create mode 100644 mass_mailing_partner_subscription/models/__init__.py create mode 100644 mass_mailing_partner_subscription/models/res_partner.py create mode 100644 mass_mailing_partner_subscription/pyproject.toml create mode 100644 mass_mailing_partner_subscription/readme/CONTRIBUTORS.md create mode 100644 mass_mailing_partner_subscription/readme/DESCRIPTION.md create mode 100644 mass_mailing_partner_subscription/readme/ROADMAP.md create mode 100644 mass_mailing_partner_subscription/readme/USAGE.md create mode 100644 mass_mailing_partner_subscription/static/description/index.html create mode 100644 mass_mailing_partner_subscription/tests/__init__.py create mode 100644 mass_mailing_partner_subscription/tests/test_res_partner_mailing_list.py create mode 100644 mass_mailing_partner_subscription/views/res_partner_views.xml diff --git a/mass_mailing_partner_subscription/README.rst b/mass_mailing_partner_subscription/README.rst new file mode 100644 index 0000000..f69281d --- /dev/null +++ b/mass_mailing_partner_subscription/README.rst @@ -0,0 +1,117 @@ +.. image:: https://odoo-community.org/readme-banner-image + :target: https://odoo-community.org/get-involved?utm_source=readme + :alt: Odoo Community Association + +================================= +Mass Mailing Partner Subscription +================================= + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:a4dd3c0775a8c41eada98373f9113c51291259074fd902efe6789bce719f1e6d + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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%2Fmass--mailing-lightgray.png?logo=github + :target: https://github.com/OCA/mass-mailing/tree/19.0/mass_mailing_partner_subscription + :alt: OCA/mass-mailing +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/mass-mailing-19-0/mass-mailing-19-0-mass_mailing_partner_subscription + :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/mass-mailing&target_branch=19.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module allows managing a partner's mailing list subscriptions +directly from the partner form, without navigating to the mailing +contact. + +Features +-------- + +- A **Mailing Lists** field is shown on the partner form (Sales & + Purchase tab), visible to mailing users. +- Editing the field updates the subscriptions of the linked mailing + contact. +- If the partner has no mailing contact yet, one is automatically + created when mailing lists are first assigned. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +Open a partner form and navigate to the **Sales & Purchase** tab. The +**Mailing Lists** field shows the mailing lists the partner is currently +subscribed to. + +Add or remove lists directly from this field. Changes are immediately +reflected on the linked mailing contact. If the partner is not yet +linked to a mailing contact, one is created automatically on the first +assignment. + +Known issues / Roadmap +====================== + +Known Issues +------------ + +- When a partner is linked to more than one mailing contact, only the + first contact's subscriptions are displayed and edited. Lists + belonging to other linked contacts are not visible in the partner + form. + +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 + +Contributors +------------ + +- `ForgeFlow `__: + + - Aaron Henriquez + +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/mass-mailing `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/mass_mailing_partner_subscription/__init__.py b/mass_mailing_partner_subscription/__init__.py new file mode 100644 index 0000000..0650744 --- /dev/null +++ b/mass_mailing_partner_subscription/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/mass_mailing_partner_subscription/__manifest__.py b/mass_mailing_partner_subscription/__manifest__.py new file mode 100644 index 0000000..1638093 --- /dev/null +++ b/mass_mailing_partner_subscription/__manifest__.py @@ -0,0 +1,15 @@ +# Copyright 2026 ForgeFlow S.L. (https://www.forgeflow.com) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +{ + "name": "Mass Mailing Partner Subscription", + "summary": "Manage mailing list subscriptions directly from the partner form", + "version": "19.0.1.0.0", + "author": "ForgeFlow, Odoo Community Association (OCA)", + "website": "https://github.com/OCA/mass-mailing", + "license": "AGPL-3", + "category": "Marketing", + "depends": ["mass_mailing_partner"], + "data": ["views/res_partner_views.xml"], + "installable": True, +} diff --git a/mass_mailing_partner_subscription/models/__init__.py b/mass_mailing_partner_subscription/models/__init__.py new file mode 100644 index 0000000..91fed54 --- /dev/null +++ b/mass_mailing_partner_subscription/models/__init__.py @@ -0,0 +1 @@ +from . import res_partner diff --git a/mass_mailing_partner_subscription/models/res_partner.py b/mass_mailing_partner_subscription/models/res_partner.py new file mode 100644 index 0000000..56fe919 --- /dev/null +++ b/mass_mailing_partner_subscription/models/res_partner.py @@ -0,0 +1,39 @@ +# Copyright 2026 ForgeFlow S.L. (https://www.forgeflow.com) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import api, fields, models + + +class ResPartner(models.Model): + _inherit = "res.partner" + + mailing_list_ids = fields.Many2many( + comodel_name="mailing.list", + string="Mailing Lists", + compute="_compute_mailing_list_ids", + inverse="_inverse_mailing_list_ids", + compute_sudo=True, + ) + + @api.depends("mass_mailing_contact_ids", "mass_mailing_contact_ids.list_ids") + def _compute_mailing_list_ids(self): + for partner in self: + contact = partner.mass_mailing_contact_ids[:1] + partner.mailing_list_ids = contact.list_ids + + def _inverse_mailing_list_ids(self): + MailingContact = self.env["mailing.contact"].sudo() + for partner in self: + lists = partner.mailing_list_ids + contact = partner.sudo().mass_mailing_contact_ids[:1] + if not contact: + if not lists: + continue + contact = MailingContact.create( + { + "name": partner.name, + "email": partner.email, + "partner_id": partner.id, + } + ) + contact.list_ids = lists diff --git a/mass_mailing_partner_subscription/pyproject.toml b/mass_mailing_partner_subscription/pyproject.toml new file mode 100644 index 0000000..4231d0c --- /dev/null +++ b/mass_mailing_partner_subscription/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/mass_mailing_partner_subscription/readme/CONTRIBUTORS.md b/mass_mailing_partner_subscription/readme/CONTRIBUTORS.md new file mode 100644 index 0000000..5eba992 --- /dev/null +++ b/mass_mailing_partner_subscription/readme/CONTRIBUTORS.md @@ -0,0 +1,3 @@ +- [ForgeFlow](https://www.forgeflow.com): + + > - Aaron Henriquez diff --git a/mass_mailing_partner_subscription/readme/DESCRIPTION.md b/mass_mailing_partner_subscription/readme/DESCRIPTION.md new file mode 100644 index 0000000..f1dfd4b --- /dev/null +++ b/mass_mailing_partner_subscription/readme/DESCRIPTION.md @@ -0,0 +1,10 @@ +This module allows managing a partner's mailing list subscriptions directly +from the partner form, without navigating to the mailing contact. + +## Features + +- A **Mailing Lists** field is shown on the partner form (Sales & Purchase tab), + visible to mailing users. +- Editing the field updates the subscriptions of the linked mailing contact. +- If the partner has no mailing contact yet, one is automatically created when + mailing lists are first assigned. diff --git a/mass_mailing_partner_subscription/readme/ROADMAP.md b/mass_mailing_partner_subscription/readme/ROADMAP.md new file mode 100644 index 0000000..f5192d0 --- /dev/null +++ b/mass_mailing_partner_subscription/readme/ROADMAP.md @@ -0,0 +1,5 @@ +## Known Issues + +- When a partner is linked to more than one mailing contact, only the first + contact's subscriptions are displayed and edited. Lists belonging to other + linked contacts are not visible in the partner form. diff --git a/mass_mailing_partner_subscription/readme/USAGE.md b/mass_mailing_partner_subscription/readme/USAGE.md new file mode 100644 index 0000000..3856561 --- /dev/null +++ b/mass_mailing_partner_subscription/readme/USAGE.md @@ -0,0 +1,7 @@ +Open a partner form and navigate to the **Sales & Purchase** tab. The +**Mailing Lists** field shows the mailing lists the partner is currently +subscribed to. + +Add or remove lists directly from this field. Changes are immediately +reflected on the linked mailing contact. If the partner is not yet linked +to a mailing contact, one is created automatically on the first assignment. diff --git a/mass_mailing_partner_subscription/static/description/index.html b/mass_mailing_partner_subscription/static/description/index.html new file mode 100644 index 0000000..4270525 --- /dev/null +++ b/mass_mailing_partner_subscription/static/description/index.html @@ -0,0 +1,465 @@ + + + + + +README.rst + + + +
+ + + +Odoo Community Association + +
+

Mass Mailing Partner Subscription

+ +

Beta License: AGPL-3 OCA/mass-mailing Translate me on Weblate Try me on Runboat

+

This module allows managing a partner’s mailing list subscriptions +directly from the partner form, without navigating to the mailing +contact.

+
+

Features

+
    +
  • A Mailing Lists field is shown on the partner form (Sales & +Purchase tab), visible to mailing users.
  • +
  • Editing the field updates the subscriptions of the linked mailing +contact.
  • +
  • If the partner has no mailing contact yet, one is automatically +created when mailing lists are first assigned.
  • +
+

Table of contents

+ +
+

Usage

+

Open a partner form and navigate to the Sales & Purchase tab. The +Mailing Lists field shows the mailing lists the partner is currently +subscribed to.

+

Add or remove lists directly from this field. Changes are immediately +reflected on the linked mailing contact. If the partner is not yet +linked to a mailing contact, one is created automatically on the first +assignment.

+
+ +
+
+

Known Issues

+
    +
  • When a partner is linked to more than one mailing contact, only the +first contact’s subscriptions are displayed and edited. Lists +belonging to other linked contacts are not visible in the partner +form.
  • +
+
+

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
  • +
+
+
+

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/mass-mailing project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/mass_mailing_partner_subscription/tests/__init__.py b/mass_mailing_partner_subscription/tests/__init__.py new file mode 100644 index 0000000..3328914 --- /dev/null +++ b/mass_mailing_partner_subscription/tests/__init__.py @@ -0,0 +1 @@ +from . import test_res_partner_mailing_list diff --git a/mass_mailing_partner_subscription/tests/test_res_partner_mailing_list.py b/mass_mailing_partner_subscription/tests/test_res_partner_mailing_list.py new file mode 100644 index 0000000..4e2b114 --- /dev/null +++ b/mass_mailing_partner_subscription/tests/test_res_partner_mailing_list.py @@ -0,0 +1,41 @@ +# Copyright 2026 ForgeFlow S.L. (https://www.forgeflow.com) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo.tests.common import TransactionCase + + +class TestResPartnerMailingList(TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.partner = cls.env["res.partner"].create( + {"name": "Test Partner", "email": "test@example.com"} + ) + cls.list_a = cls.env["mailing.list"].create({"name": "List A"}) + cls.list_b = cls.env["mailing.list"].create({"name": "List B"}) + + def test_set_mailing_lists_creates_contact(self): + """Writing mailing_list_ids on a partner with no contact auto-creates one.""" + partner = self.env["res.partner"].create( + {"name": "New Partner", "email": "new@example.com"} + ) + partner.mailing_list_ids = self.list_a + contact = partner.mass_mailing_contact_ids[:1] + self.assertTrue(contact) + self.assertIn(self.list_a, contact.list_ids) + + def test_edit_mailing_lists_updates_contact(self): + """Updating mailing_list_ids on a partner propagates to the linked contact.""" + contact = self.env["mailing.contact"].create( + { + "name": self.partner.name, + "email": self.partner.email, + "partner_id": self.partner.id, + "list_ids": [(4, self.list_a.id)], + } + ) + self.assertEqual(self.partner.mailing_list_ids, self.list_a) + self.partner.mailing_list_ids = self.list_a | self.list_b + self.assertIn(self.list_b, contact.list_ids) + self.partner.mailing_list_ids = self.list_b + self.assertNotIn(self.list_a, contact.list_ids) diff --git a/mass_mailing_partner_subscription/views/res_partner_views.xml b/mass_mailing_partner_subscription/views/res_partner_views.xml new file mode 100644 index 0000000..88801e4 --- /dev/null +++ b/mass_mailing_partner_subscription/views/res_partner_views.xml @@ -0,0 +1,29 @@ + + + + + res.partner.form.mailing.list + res.partner + + + + + + + + + + + + + + + + + +