From 1f08c058312aa286f0ac9f93e3df6a12b0a90c6d Mon Sep 17 00:00:00 2001 From: mpascual Date: Fri, 20 Dec 2024 11:01:17 +0100 Subject: [PATCH] [ADD] mail_autosubscribe_partner_parent: New module mail_autosubscribe_partner_parent --- mail_autosubscribe_partner_parent/README.rst | 100 ++++ mail_autosubscribe_partner_parent/__init__.py | 1 + .../__manifest__.py | 13 + .../models/__init__.py | 1 + .../models/base.py | 10 + .../readme/CONTRIBUTORS.md | 2 + .../readme/DESCRIPTION.md | 1 + .../readme/USAGE.md | 7 + .../static/description/index.html | 439 ++++++++++++++++++ .../tests/__init__.py | 1 + .../tests/models/__init__.py | 1 + .../tests/models/fake_order.py | 9 + .../tests/test_mail_autosubscribe.py | 55 +++ .../addons/mail_autosubscribe_partner_parent | 1 + .../setup.py | 6 + 15 files changed, 647 insertions(+) create mode 100644 mail_autosubscribe_partner_parent/README.rst create mode 100644 mail_autosubscribe_partner_parent/__init__.py create mode 100644 mail_autosubscribe_partner_parent/__manifest__.py create mode 100644 mail_autosubscribe_partner_parent/models/__init__.py create mode 100644 mail_autosubscribe_partner_parent/models/base.py create mode 100644 mail_autosubscribe_partner_parent/readme/CONTRIBUTORS.md create mode 100644 mail_autosubscribe_partner_parent/readme/DESCRIPTION.md create mode 100644 mail_autosubscribe_partner_parent/readme/USAGE.md create mode 100644 mail_autosubscribe_partner_parent/static/description/index.html create mode 100644 mail_autosubscribe_partner_parent/tests/__init__.py create mode 100644 mail_autosubscribe_partner_parent/tests/models/__init__.py create mode 100644 mail_autosubscribe_partner_parent/tests/models/fake_order.py create mode 100644 mail_autosubscribe_partner_parent/tests/test_mail_autosubscribe.py create mode 120000 setup/mail_autosubscribe_partner_parent/odoo/addons/mail_autosubscribe_partner_parent create mode 100644 setup/mail_autosubscribe_partner_parent/setup.py diff --git a/mail_autosubscribe_partner_parent/README.rst b/mail_autosubscribe_partner_parent/README.rst new file mode 100644 index 0000000000..d2affdf044 --- /dev/null +++ b/mail_autosubscribe_partner_parent/README.rst @@ -0,0 +1,100 @@ +============================ +Autosubscribe Partner Parent +============================ + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:6f0c9e80ca722a371969a9bc4d020480a6ffb2b15491bf45f1910d1dd024eadc + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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%2Fsocial-lightgray.png?logo=github + :target: https://github.com/OCA/social/tree/16.0/mail_autosubscribe_partner_parent + :alt: OCA/social +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/social-16-0/social-16-0-mail_autosubscribe_partner_parent + :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/social&target_branch=16.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module extends mail_autosubscribe functionality to add the partner +parent in copy of their child partner documents. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +When creating a selected autosubscribe record, it adds the partner +parent in copy of it. + +For example, if you have invoice selected on mail_autosubscribe_ids: + +Go to Invoicing > Create a new Invoice > Select the wanted partner > +Confirm the invoice + +The parent partner will be automatically added in copy of the invoice. + +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 +------- + +* Miquel Pascual + +Contributors +------------ + +- `APSL-Nagarro `__: + + - Miquel Pascual <> + +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-mpascuall| image:: https://github.com/mpascuall.png?size=40px + :target: https://github.com/mpascuall + :alt: mpascuall + +Current `maintainer `__: + +|maintainer-mpascuall| + +This module is part of the `OCA/social `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/mail_autosubscribe_partner_parent/__init__.py b/mail_autosubscribe_partner_parent/__init__.py new file mode 100644 index 0000000000..0650744f6b --- /dev/null +++ b/mail_autosubscribe_partner_parent/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/mail_autosubscribe_partner_parent/__manifest__.py b/mail_autosubscribe_partner_parent/__manifest__.py new file mode 100644 index 0000000000..26aea1fb06 --- /dev/null +++ b/mail_autosubscribe_partner_parent/__manifest__.py @@ -0,0 +1,13 @@ +{ + "name": "Autosubscribe Partner Parent", + "version": "16.0.1.0.0", + "summary": """Autosubscribes the parent of the partner to the record followers""", + "category": "Marketing", + "license": "AGPL-3", + "author": """Miquel Pascual, Odoo Community Association (OCA)""", + "website": "https://github.com/OCA/social", + "depends": ["mail_autosubscribe", "base_partner_company_group"], + "installable": True, + "application": False, + "maintainers": ["mpascuall"], +} diff --git a/mail_autosubscribe_partner_parent/models/__init__.py b/mail_autosubscribe_partner_parent/models/__init__.py new file mode 100644 index 0000000000..0e44449338 --- /dev/null +++ b/mail_autosubscribe_partner_parent/models/__init__.py @@ -0,0 +1 @@ +from . import base diff --git a/mail_autosubscribe_partner_parent/models/base.py b/mail_autosubscribe_partner_parent/models/base.py new file mode 100644 index 0000000000..89f469d591 --- /dev/null +++ b/mail_autosubscribe_partner_parent/models/base.py @@ -0,0 +1,10 @@ +from odoo import api, models + + +class BaseModel(models.AbstractModel): + _inherit = "base" + + @api.model + def _message_get_autosubscribe_followers(self, partners): + res = super()._message_get_autosubscribe_followers(partners) + return res + (res.mapped("parent_id")) diff --git a/mail_autosubscribe_partner_parent/readme/CONTRIBUTORS.md b/mail_autosubscribe_partner_parent/readme/CONTRIBUTORS.md new file mode 100644 index 0000000000..968156fa1a --- /dev/null +++ b/mail_autosubscribe_partner_parent/readme/CONTRIBUTORS.md @@ -0,0 +1,2 @@ +- [APSL-Nagarro](): + - Miquel Pascual \<\<\>\> \ No newline at end of file diff --git a/mail_autosubscribe_partner_parent/readme/DESCRIPTION.md b/mail_autosubscribe_partner_parent/readme/DESCRIPTION.md new file mode 100644 index 0000000000..2f82b23e69 --- /dev/null +++ b/mail_autosubscribe_partner_parent/readme/DESCRIPTION.md @@ -0,0 +1 @@ +This module extends mail_autosubscribe functionality to add the partner parent in copy of their child partner documents. \ No newline at end of file diff --git a/mail_autosubscribe_partner_parent/readme/USAGE.md b/mail_autosubscribe_partner_parent/readme/USAGE.md new file mode 100644 index 0000000000..382bd437c6 --- /dev/null +++ b/mail_autosubscribe_partner_parent/readme/USAGE.md @@ -0,0 +1,7 @@ +When creating a selected autosubscribe record, it adds the partner parent in copy of it. + +For example, if you have invoice selected on mail_autosubscribe_ids: + +Go to Invoicing > Create a new Invoice > Select the wanted partner > Confirm the invoice + +The parent partner will be automatically added in copy of the invoice. \ No newline at end of file diff --git a/mail_autosubscribe_partner_parent/static/description/index.html b/mail_autosubscribe_partner_parent/static/description/index.html new file mode 100644 index 0000000000..1755cd953a --- /dev/null +++ b/mail_autosubscribe_partner_parent/static/description/index.html @@ -0,0 +1,439 @@ + + + + + +Autosubscribe Partner Parent + + + +
+

Autosubscribe Partner Parent

+ + +

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

+

This module extends mail_autosubscribe functionality to add the partner +parent in copy of their child partner documents.

+

Table of contents

+ +
+

Usage

+

When creating a selected autosubscribe record, it adds the partner +parent in copy of it.

+

For example, if you have invoice selected on mail_autosubscribe_ids:

+

Go to Invoicing > Create a new Invoice > Select the wanted partner > +Confirm the invoice

+

The parent partner will be automatically added in copy of the invoice.

+
+
+

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

+
    +
  • Miquel Pascual
  • +
+
+
+

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.

+

Current maintainer:

+

mpascuall

+

This module is part of the OCA/social project on GitHub.

+

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

+
+
+
+ + diff --git a/mail_autosubscribe_partner_parent/tests/__init__.py b/mail_autosubscribe_partner_parent/tests/__init__.py new file mode 100644 index 0000000000..988556bfe2 --- /dev/null +++ b/mail_autosubscribe_partner_parent/tests/__init__.py @@ -0,0 +1 @@ +from . import test_mail_autosubscribe \ No newline at end of file diff --git a/mail_autosubscribe_partner_parent/tests/models/__init__.py b/mail_autosubscribe_partner_parent/tests/models/__init__.py new file mode 100644 index 0000000000..167ad69056 --- /dev/null +++ b/mail_autosubscribe_partner_parent/tests/models/__init__.py @@ -0,0 +1 @@ +from . import fake_order \ No newline at end of file diff --git a/mail_autosubscribe_partner_parent/tests/models/fake_order.py b/mail_autosubscribe_partner_parent/tests/models/fake_order.py new file mode 100644 index 0000000000..c0ec6e6609 --- /dev/null +++ b/mail_autosubscribe_partner_parent/tests/models/fake_order.py @@ -0,0 +1,9 @@ +from odoo import fields, models + + +class FakeOrder(models.Model): + _name = "fake.order" + _inherit = "mail.thread" + _description = "Fake sale.order like model" + + partner_id = fields.Many2one("res.partner", required=True) diff --git a/mail_autosubscribe_partner_parent/tests/test_mail_autosubscribe.py b/mail_autosubscribe_partner_parent/tests/test_mail_autosubscribe.py new file mode 100644 index 0000000000..19785a1a97 --- /dev/null +++ b/mail_autosubscribe_partner_parent/tests/test_mail_autosubscribe.py @@ -0,0 +1,55 @@ +from odoo_test_helper import FakeModelLoader + +from odoo.tests.common import Form, TransactionCase, tagged + + +@tagged("post_install", "-at_install") +class TestMailAutosubscribe(TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.env = cls.env( + context=dict( + cls.env.context, tracking_disable=True, test_mail_autosubscribe=True + ) + ) + cls.loader = FakeModelLoader(cls.env, cls.__module__) + cls.loader.backup_registry() + from .models.fake_order import FakeOrder + + cls.loader.update_registry((FakeOrder,)) + cls.fake_order_model = cls.env["ir.model"].search( + [("model", "=", "fake.order")] + ) + cls.mail_template = cls.env["mail.template"].create( + { + "model_id": cls.fake_order_model.id, + "name": "Fake Order", + "subject": "Fake Order: {{object.partner_id.name}}", + "partner_to": "{{object.partner_id.id}}", + "body_html": "Fake Order", + } + ) + cls.commercial_partner = cls.env.ref("base.res_partner_4") + cls.partner_1 = cls.env.ref("base.res_partner_address_13") + cls.partner_2 = cls.env.ref("base.res_partner_address_14") + cls.partner_3 = cls.env.ref("base.res_partner_address_24") + cls.autosubscribe_fake_order = cls.env["mail.autosubscribe"].create( + {"model_id": cls.fake_order_model.id} + ) + cls.partner_3.mail_autosubscribe_ids = [(4, cls.autosubscribe_fake_order.id)] + cls.order = cls.env["fake.order"].create({"partner_id": cls.partner_2.id}) + + @classmethod + def tearDownClass(cls): + cls.loader.restore_registry() + return super().tearDownClass() + + def test_message_subscribe(self): + self.assertFalse(self.order.message_partner_ids, "No subscribers yet") + self.order.message_subscribe([self.order.partner_id.id]) + self.assertEqual( + self.order.message_partner_ids, + self.partner_2 | self.partner_3 | self.commercial_partner, + "Partner 3 is automatically subscribed", + ) \ No newline at end of file diff --git a/setup/mail_autosubscribe_partner_parent/odoo/addons/mail_autosubscribe_partner_parent b/setup/mail_autosubscribe_partner_parent/odoo/addons/mail_autosubscribe_partner_parent new file mode 120000 index 0000000000..fe65d822d5 --- /dev/null +++ b/setup/mail_autosubscribe_partner_parent/odoo/addons/mail_autosubscribe_partner_parent @@ -0,0 +1 @@ +../../../../mail_autosubscribe_partner_parent \ No newline at end of file diff --git a/setup/mail_autosubscribe_partner_parent/setup.py b/setup/mail_autosubscribe_partner_parent/setup.py new file mode 100644 index 0000000000..28c57bb640 --- /dev/null +++ b/setup/mail_autosubscribe_partner_parent/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)