diff --git a/mail_user_signature_mass_edit/README.rst b/mail_user_signature_mass_edit/README.rst new file mode 100644 index 000000000..010028d4d --- /dev/null +++ b/mail_user_signature_mass_edit/README.rst @@ -0,0 +1,122 @@ +============================= +Mail User Signature Mass Edit +============================= + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:d357b4ba6133d43b6b13b074617e6df2d2aeb9500d1856e3a75728bf85b16690 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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%2Fmail-lightgray.png?logo=github + :target: https://github.com/OCA/mail/tree/18.0/mail_user_signature_mass_edit + :alt: OCA/mail +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/mail-18-0/mail-18-0-mail_user_signature_mass_edit + :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/mail&target_branch=18.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module lets administrators update users email signatures in bulk. + +Administrators define one HTML signature template on a mass edit record, +select a company, and confirm the operation. The template is rendered +for each matching internal user. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +1. Give the user the *Signature Mass Edit* access right in Email + Marketing. + +2. Go to *Email Marketing > Configuration > Signature Mass Edits*. + + Administrators can also access the same records from *Settings > + Users & Companies > Signature Mass Edits*. + +3. Create a new record. + +4. Select the company whose internal users must be updated. + +5. Optionally select one or more groups to restrict the update to users + belonging to those groups. Only internal users are updated. + +6. Enter the HTML signature template in the *Source* tab. Use the + *Preview* tab to check the rendered signature. + +7. Click *Confirm*. + +The signature template is rendered on the ``res.users`` model. For +example: + +.. code:: html + +

+ {{ object.name }}
+ {{ object.company_id.name }}
+ {{ object.email or '' }} +

+ +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 +------- + +* ACSONE SA/NV + +Contributors +------------ + +- 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. + +.. |maintainer-sbejaoui| image:: https://github.com/sbejaoui.png?size=40px + :target: https://github.com/sbejaoui + :alt: sbejaoui + +Current `maintainer `__: + +|maintainer-sbejaoui| + +This module is part of the `OCA/mail `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/mail_user_signature_mass_edit/__init__.py b/mail_user_signature_mass_edit/__init__.py new file mode 100644 index 000000000..0650744f6 --- /dev/null +++ b/mail_user_signature_mass_edit/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/mail_user_signature_mass_edit/__manifest__.py b/mail_user_signature_mass_edit/__manifest__.py new file mode 100644 index 000000000..75fadd699 --- /dev/null +++ b/mail_user_signature_mass_edit/__manifest__.py @@ -0,0 +1,20 @@ +# Copyright 2026 ACSONE SA/NV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +{ + "name": "Mail User Signature Mass Edit", + "summary": "Mass-edit user email signatures from an HTML template, " + "rendered per user and filtered by company.", + "category": "Mail", + "version": "18.0.1.0.0", + "license": "AGPL-3", + "author": "ACSONE SA/NV,Odoo Community Association (OCA)", + "maintainers": ["sbejaoui"], + "website": "https://github.com/OCA/mail", + "depends": ["mail", "mass_mailing"], + "data": [ + "security/res_groups.xml", + "security/signature_mass_edit.xml", + "views/signature_mass_edit_views.xml", + ], +} diff --git a/mail_user_signature_mass_edit/models/__init__.py b/mail_user_signature_mass_edit/models/__init__.py new file mode 100644 index 000000000..693aa52a7 --- /dev/null +++ b/mail_user_signature_mass_edit/models/__init__.py @@ -0,0 +1,4 @@ +# Copyright 2026 ACSONE SA/NV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from . import signature_mass_edit diff --git a/mail_user_signature_mass_edit/models/signature_mass_edit.py b/mail_user_signature_mass_edit/models/signature_mass_edit.py new file mode 100644 index 000000000..4dd4ada92 --- /dev/null +++ b/mail_user_signature_mass_edit/models/signature_mass_edit.py @@ -0,0 +1,134 @@ +# Copyright 2026 ACSONE SA/NV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import api, fields, models +from odoo.exceptions import UserError + + +class SignatureMassEdit(models.Model): + _name = "signature.mass.edit" + _description = "Signature Mass Edit" + _order = "id desc" + + signature = fields.Html(string="Signature Template", required=True) + company_id = fields.Many2one( + comodel_name="res.company", + string="Company", + required=True, + default=lambda self: self.env.company, + ) + group_ids = fields.Many2many( + comodel_name="res.groups", + string="Groups", + help="Apply the signature only to users belonging to at least one of " + "these groups. Leave empty to apply it to all company users.", + ) + state = fields.Selection( + selection=[("draft", "Draft"), ("done", "Done")], + string="Status", + required=True, + readonly=True, + copy=False, + default="draft", + ) + user_count = fields.Integer(string="Users", compute="_compute_user_count") + processed_user_count = fields.Integer( + string="Processed Users", readonly=True, copy=False + ) + + @api.depends("company_id", "group_ids") + def _compute_display_name(self): + for record in self: + if not record.company_id: + record.display_name = self.env._("Signature Mass Edit") + continue + display_name = self.env._( + "Signature Mass Edit - %(company)s", company=record.company_id.name + ) + if record.group_ids: + group_names = ", ".join(record.group_ids.mapped("display_name")) + display_name = self.env._( + "%(display_name)s (%(groups)s)", + display_name=display_name, + groups=group_names, + ) + record.display_name = display_name + + @api.depends("company_id", "group_ids") + def _compute_user_count(self): + for record in self: + record.user_count = len(record._get_target_users()) + + def action_confirm(self): + for record in self: + record._check_can_confirm() + record._process_signature_mass_edit() + return True + + def action_view_users(self): + self.ensure_one() + return { + "type": "ir.actions.act_window", + "name": self.env._("Users"), + "res_model": "res.users", + "view_mode": "list,form", + "views": [ + (False, "list"), + (self.env.ref("base.view_users_form").id, "form"), + ], + "domain": self._get_target_users_domain(), + } + + def action_reset_to_draft(self): + self.write({"state": "draft"}) + return True + + def _check_can_confirm(self): + self.ensure_one() + if self.state != "draft": + raise UserError( + self.env._("Only draft signature mass edits can be confirmed.") + ) + + def _get_target_users_domain(self): + self.ensure_one() + internal_user_group = self.env.ref("base.group_user") + domain = [ + ("active", "=", True), + ("company_ids", "in", self.company_id.id), + ("groups_id", "in", internal_user_group.id), + ] + if self.group_ids: + domain.append(("groups_id", "in", self.group_ids.ids)) + return domain + + def _get_target_users(self): + self.ensure_one() + return self.env["res.users"].sudo().search(self._get_target_users_domain()) + + def _process_signature_mass_edit(self): + self.ensure_one() + users = self._get_target_users() + for user in users: + self._process_user_signature(user) + self._mark_signature_mass_edit_done(len(users)) + + def _process_user_signature(self, user): + self.ensure_one() + user.ensure_one() + rendered_signatures = ( + self.env["mail.render.mixin"] + .sudo() + ._render_template( + self.signature, + "res.users", + user.ids, + engine="inline_template", + options={"post_process": True}, + ) + ) + user.sudo().write({"signature": rendered_signatures.get(user.id, "")}) + + def _mark_signature_mass_edit_done(self, processed_count): + self.ensure_one() + self.write({"processed_user_count": processed_count, "state": "done"}) diff --git a/mail_user_signature_mass_edit/pyproject.toml b/mail_user_signature_mass_edit/pyproject.toml new file mode 100644 index 000000000..4231d0ccc --- /dev/null +++ b/mail_user_signature_mass_edit/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/mail_user_signature_mass_edit/readme/CONTRIBUTORS.md b/mail_user_signature_mass_edit/readme/CONTRIBUTORS.md new file mode 100644 index 000000000..fc5fcbefe --- /dev/null +++ b/mail_user_signature_mass_edit/readme/CONTRIBUTORS.md @@ -0,0 +1 @@ +- Souheil Bejaoui \<\> diff --git a/mail_user_signature_mass_edit/readme/DESCRIPTION.md b/mail_user_signature_mass_edit/readme/DESCRIPTION.md new file mode 100644 index 000000000..214484e50 --- /dev/null +++ b/mail_user_signature_mass_edit/readme/DESCRIPTION.md @@ -0,0 +1,5 @@ +This module lets administrators update users email signatures in bulk. + +Administrators define one HTML signature template on a mass edit record, select a +company, and confirm the operation. The template is rendered for each matching +internal user. diff --git a/mail_user_signature_mass_edit/readme/USAGE.md b/mail_user_signature_mass_edit/readme/USAGE.md new file mode 100644 index 000000000..62cef9c83 --- /dev/null +++ b/mail_user_signature_mass_edit/readme/USAGE.md @@ -0,0 +1,22 @@ +1. Give the user the *Signature Mass Edit* access right in Email Marketing. +2. Go to *Email Marketing > Configuration > Signature Mass Edits*. + + Administrators can also access the same records from + *Settings > Users & Companies > Signature Mass Edits*. +3. Create a new record. +4. Select the company whose internal users must be updated. +5. Optionally select one or more groups to restrict the update to users belonging + to those groups. Only internal users are updated. +6. Enter the HTML signature template in the *Source* tab. Use the *Preview* + tab to check the rendered signature. +7. Click *Confirm*. + +The signature template is rendered on the `res.users` model. For example: + +```html +

+ {{ object.name }}
+ {{ object.company_id.name }}
+ {{ object.email or '' }} +

+``` diff --git a/mail_user_signature_mass_edit/security/res_groups.xml b/mail_user_signature_mass_edit/security/res_groups.xml new file mode 100644 index 000000000..64d22d707 --- /dev/null +++ b/mail_user_signature_mass_edit/security/res_groups.xml @@ -0,0 +1,16 @@ + + + + + Signature Mass Edit + + + + diff --git a/mail_user_signature_mass_edit/security/signature_mass_edit.xml b/mail_user_signature_mass_edit/security/signature_mass_edit.xml new file mode 100644 index 000000000..a4567d338 --- /dev/null +++ b/mail_user_signature_mass_edit/security/signature_mass_edit.xml @@ -0,0 +1,34 @@ + + + + + signature.mass.edit user + + + + + + + + + + signature.mass.edit system + + + + + + + + + + Signature Mass Edit: multi-company + + [("company_id", "in", company_ids)] + + + diff --git a/mail_user_signature_mass_edit/static/description/icon.png b/mail_user_signature_mass_edit/static/description/icon.png new file mode 100644 index 000000000..3a0328b51 Binary files /dev/null and b/mail_user_signature_mass_edit/static/description/icon.png differ diff --git a/mail_user_signature_mass_edit/static/description/index.html b/mail_user_signature_mass_edit/static/description/index.html new file mode 100644 index 000000000..abe097ede --- /dev/null +++ b/mail_user_signature_mass_edit/static/description/index.html @@ -0,0 +1,462 @@ + + + + + +Mail User Signature Mass Edit + + + +
+

Mail User Signature Mass Edit

+ + +

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

+

This module lets administrators update users email signatures in bulk.

+

Administrators define one HTML signature template on a mass edit record, +select a company, and confirm the operation. The template is rendered +for each matching internal user.

+

Table of contents

+ +
+

Usage

+
    +
  1. Give the user the Signature Mass Edit access right in Email +Marketing.

    +
  2. +
  3. Go to Email Marketing > Configuration > Signature Mass Edits.

    +

    Administrators can also access the same records from Settings > +Users & Companies > Signature Mass Edits.

    +
  4. +
  5. Create a new record.

    +
  6. +
  7. Select the company whose internal users must be updated.

    +
  8. +
  9. Optionally select one or more groups to restrict the update to users +belonging to those groups. Only internal users are updated.

    +
  10. +
  11. Enter the HTML signature template in the Source tab. Use the +Preview tab to check the rendered signature.

    +
  12. +
  13. Click Confirm.

    +
  14. +
+

The signature template is rendered on the res.users model. For +example:

+
+<p>
+  <strong>{{ object.name }}</strong><br/>
+  {{ object.company_id.name }}<br/>
+  {{ object.email or '' }}
+</p>
+
+
+
+

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

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

+

Current maintainer:

+

sbejaoui

+

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

+

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

+
+
+
+ + diff --git a/mail_user_signature_mass_edit/tests/__init__.py b/mail_user_signature_mass_edit/tests/__init__.py new file mode 100644 index 000000000..ab484d63d --- /dev/null +++ b/mail_user_signature_mass_edit/tests/__init__.py @@ -0,0 +1,4 @@ +# Copyright 2026 ACSONE SA/NV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from . import test_signature_mass_edit diff --git a/mail_user_signature_mass_edit/tests/test_signature_mass_edit.py b/mail_user_signature_mass_edit/tests/test_signature_mass_edit.py new file mode 100644 index 000000000..eab2208d4 --- /dev/null +++ b/mail_user_signature_mass_edit/tests/test_signature_mass_edit.py @@ -0,0 +1,166 @@ +# Copyright 2026 ACSONE SA/NV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo.exceptions import UserError +from odoo.tests.common import TransactionCase, new_test_user, tagged + + +@tagged("post_install", "-at_install") +class TestSignatureMassEdit(TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.company = cls.env["res.company"].create({"name": "Signature Company"}) + cls.other_company = cls.env["res.company"].create( + {"name": "Other Signature Company"} + ) + cls.group_settings = cls.env.ref("base.group_system") + cls.group_signature_mass_edit = cls.env.ref( + "mail_user_signature_mass_edit.group_signature_mass_edit" + ) + cls.user = new_test_user( + cls.env, + login="signature_user", + groups="base.group_user", + context={"no_reset_password": True}, + name="Signature User", + company_id=cls.company.id, + email="signature_user@example.com", + ) + cls.other_user = new_test_user( + cls.env, + login="other_signature_user", + groups="base.group_user", + context={"no_reset_password": True}, + name="Other Signature User", + company_id=cls.other_company.id, + email="other_signature_user@example.com", + ) + cls.portal_user = new_test_user( + cls.env, + login="portal_signature_user", + groups="base.group_portal", + context={"no_reset_password": True}, + name="Portal Signature User", + company_id=cls.company.id, + email="portal_signature_user@example.com", + ) + + def test_confirm_renders_signature_for_company_users(self): + mass_edit = self.env["signature.mass.edit"].create( + { + "company_id": self.company.id, + "signature": "

{{ object.name }} - {{ object.company_id.name }}

", + } + ) + self.assertEqual( + mass_edit.display_name, + "Signature Mass Edit - Signature Company", + ) + self.assertEqual(mass_edit.user_count, 1) + + mass_edit.action_confirm() + + self.assertEqual(mass_edit.state, "done") + self.assertEqual(mass_edit.processed_user_count, 1) + self.assertEqual( + self.user.signature, + "

Signature User - Signature Company

", + ) + self.assertNotEqual( + self.other_user.signature, + "

Other Signature User - Other Signature Company

", + ) + + def test_confirm_only_updates_internal_users(self): + mass_edit = self.env["signature.mass.edit"].create( + { + "company_id": self.company.id, + "signature": "

{{ object.name }}

", + } + ) + + mass_edit.action_confirm() + + self.assertEqual(mass_edit.processed_user_count, 1) + self.assertEqual(self.user.signature, "

Signature User

") + self.assertNotEqual(self.portal_user.signature, "

Portal Signature User

") + + def test_confirm_only_updates_users_in_selected_groups(self): + mass_edit = self.env["signature.mass.edit"].create( + { + "company_id": self.company.id, + "group_ids": [(6, 0, self.group_settings.ids)], + "signature": "

{{ object.name }}

", + } + ) + + mass_edit.action_confirm() + + self.assertEqual(mass_edit.processed_user_count, 0) + self.assertNotEqual(self.user.signature, "

Signature User

") + + action = mass_edit.action_reset_to_draft() + self.assertTrue(action) + self.assertEqual(mass_edit.state, "draft") + + def test_only_draft_records_can_be_confirmed(self): + mass_edit = self.env["signature.mass.edit"].create( + { + "company_id": self.company.id, + "signature": "

{{ object.name }}

", + } + ) + mass_edit.action_confirm() + + with self.assertRaisesRegex(UserError, "Only draft signature mass edits"): + mass_edit.action_confirm() + + def test_action_view_users(self): + mass_edit = self.env["signature.mass.edit"].create( + { + "company_id": self.company.id, + "signature": "

{{ object.name }}

", + } + ) + + action = mass_edit.action_view_users() + + self.assertEqual(action["type"], "ir.actions.act_window") + self.assertEqual(action["res_model"], "res.users") + self.assertEqual(action["view_mode"], "list,form") + self.assertEqual( + action["views"], + [(False, "list"), (self.env.ref("base.view_users_form").id, "form")], + ) + self.assertEqual(action["domain"], mass_edit._get_target_users_domain()) + + def test_signature_mass_edit_group_can_confirm_without_user_admin_rights(self): + marketing_user = new_test_user( + self.env, + login="signature_marketing_user", + groups="mail_user_signature_mass_edit.group_signature_mass_edit", + context={"no_reset_password": True}, + name="Signature Marketing User", + company_id=self.company.id, + company_ids=[(6, 0, self.company.ids)], + email="signature_marketing_user@example.com", + ) + mass_edit = ( + self.env["signature.mass.edit"] + .with_user(marketing_user) + .create( + { + "company_id": self.company.id, + "group_ids": [(6, 0, self.group_signature_mass_edit.ids)], + "signature": "

{{ object.name }}

", + } + ) + ) + + mass_edit.with_user(marketing_user).action_confirm() + + self.assertFalse(marketing_user.has_group("base.group_system")) + self.assertEqual(mass_edit.state, "done") + self.assertEqual(mass_edit.processed_user_count, 1) + self.assertEqual(marketing_user.signature, "

Signature Marketing User

") diff --git a/mail_user_signature_mass_edit/views/signature_mass_edit_views.xml b/mail_user_signature_mass_edit/views/signature_mass_edit_views.xml new file mode 100644 index 000000000..29073621c --- /dev/null +++ b/mail_user_signature_mass_edit/views/signature_mass_edit_views.xml @@ -0,0 +1,148 @@ + + + + + signature.mass.edit + + + + + + + + + + + + + signature.mass.edit + +
+
+
+ +
+ +
+ + + + + + + + + + + + + + + + +
+
+
+
+ + + signature.mass.edit + + + + + + + + + + + + + + + + User Signature Mass Edits + signature.mass.edit + list,form + + + + + +
diff --git a/mail_user_signature_mass_edit_queued/README.rst b/mail_user_signature_mass_edit_queued/README.rst new file mode 100644 index 000000000..0006c799a --- /dev/null +++ b/mail_user_signature_mass_edit_queued/README.rst @@ -0,0 +1,88 @@ +==================================== +Mail User Signature Mass Edit Queued +==================================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:41e0242a97006f0d8fdbcf4049566ce873915f457bc3f4a367f5b040ff2517f4 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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%2Fmail-lightgray.png?logo=github + :target: https://github.com/OCA/mail/tree/18.0/mail_user_signature_mass_edit_queued + :alt: OCA/mail +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/mail-18-0/mail-18-0-mail_user_signature_mass_edit_queued + :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/mail&target_branch=18.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module lets signature mass edit operations run through queue jobs. + +A new *Run in Queue Job* option is added to signature mass edits. When +enabled, confirming a mass edit moves it to *In Progress*, creates one +queue job per matching user. + +**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 +------- + +* ACSONE SA/NV + +Contributors +------------ + +- 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. + +.. |maintainer-sbejaoui| image:: https://github.com/sbejaoui.png?size=40px + :target: https://github.com/sbejaoui + :alt: sbejaoui + +Current `maintainer `__: + +|maintainer-sbejaoui| + +This module is part of the `OCA/mail `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/mail_user_signature_mass_edit_queued/__init__.py b/mail_user_signature_mass_edit_queued/__init__.py new file mode 100644 index 000000000..dc64a01c2 --- /dev/null +++ b/mail_user_signature_mass_edit_queued/__init__.py @@ -0,0 +1,4 @@ +# Copyright 2026 ACSONE SA/NV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from . import models diff --git a/mail_user_signature_mass_edit_queued/__manifest__.py b/mail_user_signature_mass_edit_queued/__manifest__.py new file mode 100644 index 000000000..ea62d0025 --- /dev/null +++ b/mail_user_signature_mass_edit_queued/__manifest__.py @@ -0,0 +1,19 @@ +# Copyright 2026 ACSONE SA/NV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +{ + "name": "Mail User Signature Mass Edit Queued", + "summary": "Queue mass user email signature updates generated from HTML templates.", + "category": "Discuss", + "version": "18.0.1.0.0", + "license": "AGPL-3", + "author": "ACSONE SA/NV,Odoo Community Association (OCA)", + "maintainers": ["sbejaoui"], + "website": "https://github.com/OCA/mail", + "depends": ["mail_user_signature_mass_edit", "queue_job"], + "data": [ + "data/queue_job_channel.xml", + "data/queue_job_function.xml", + "views/signature_mass_edit_views.xml", + ], +} diff --git a/mail_user_signature_mass_edit_queued/data/queue_job_channel.xml b/mail_user_signature_mass_edit_queued/data/queue_job_channel.xml new file mode 100644 index 000000000..230f2a66a --- /dev/null +++ b/mail_user_signature_mass_edit_queued/data/queue_job_channel.xml @@ -0,0 +1,9 @@ + + + + + signature_mass_edit + + + diff --git a/mail_user_signature_mass_edit_queued/data/queue_job_function.xml b/mail_user_signature_mass_edit_queued/data/queue_job_function.xml new file mode 100644 index 000000000..705713139 --- /dev/null +++ b/mail_user_signature_mass_edit_queued/data/queue_job_function.xml @@ -0,0 +1,25 @@ + + + + + + _queued_process_user_signature + + + + + + _queued_mark_signature_mass_edit_done + + + diff --git a/mail_user_signature_mass_edit_queued/models/__init__.py b/mail_user_signature_mass_edit_queued/models/__init__.py new file mode 100644 index 000000000..693aa52a7 --- /dev/null +++ b/mail_user_signature_mass_edit_queued/models/__init__.py @@ -0,0 +1,4 @@ +# Copyright 2026 ACSONE SA/NV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from . import signature_mass_edit diff --git a/mail_user_signature_mass_edit_queued/models/signature_mass_edit.py b/mail_user_signature_mass_edit_queued/models/signature_mass_edit.py new file mode 100644 index 000000000..3409399c6 --- /dev/null +++ b/mail_user_signature_mass_edit_queued/models/signature_mass_edit.py @@ -0,0 +1,69 @@ +# Copyright 2026 ACSONE SA/NV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import fields, models + +from odoo.addons.queue_job.delay import chain, group + + +class SignatureMassEdit(models.Model): + _inherit = "signature.mass.edit" + + state = fields.Selection( + selection_add=[("in_progress", "In Progress"), ("done",)], + ondelete={"in_progress": "set default"}, + ) + run_in_queue_job = fields.Boolean(string="Run in Queue Job") + + def action_confirm(self): + sync_records = self.filtered(lambda record: not record.run_in_queue_job) + if sync_records: + super(SignatureMassEdit, sync_records).action_confirm() + for record in self - sync_records: + record._check_can_confirm() + users = record._get_target_users() + record.write({"processed_user_count": 0, "state": "in_progress"}) + if not users: + record._mark_signature_mass_edit_done(0) + continue + record._delay_process_user_signatures(users) + return True + + def _delay_process_user_signatures(self, users): + self.ensure_one() + user_jobs = group( + *( + self.delayable() + .set( + description=self.env._( + "User signature mass edit - %(user)s", + user=user.display_name, + ) + ) + ._queued_process_user_signature(user.id) + for user in users + ) + ) + done_job = ( + self.delayable() + .set( + description=self.env._( + "Mark user signature mass edit done - %(name)s", + name=self.display_name, + ) + ) + ._queued_mark_signature_mass_edit_done(len(users)) + ) + chain(user_jobs, done_job).delay() + + def _queued_process_user_signature(self, user_id): + self.ensure_one() + user = self.env["res.users"].browse(user_id).exists() + if user: + self._process_user_signature(user) + return True + + def _queued_mark_signature_mass_edit_done(self, processed_count): + self.ensure_one() + self._mark_signature_mass_edit_done(processed_count) + return True diff --git a/mail_user_signature_mass_edit_queued/pyproject.toml b/mail_user_signature_mass_edit_queued/pyproject.toml new file mode 100644 index 000000000..4231d0ccc --- /dev/null +++ b/mail_user_signature_mass_edit_queued/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/mail_user_signature_mass_edit_queued/readme/CONTRIBUTORS.md b/mail_user_signature_mass_edit_queued/readme/CONTRIBUTORS.md new file mode 100644 index 000000000..fc5fcbefe --- /dev/null +++ b/mail_user_signature_mass_edit_queued/readme/CONTRIBUTORS.md @@ -0,0 +1 @@ +- Souheil Bejaoui \<\> diff --git a/mail_user_signature_mass_edit_queued/readme/DESCRIPTION.md b/mail_user_signature_mass_edit_queued/readme/DESCRIPTION.md new file mode 100644 index 000000000..27c59186e --- /dev/null +++ b/mail_user_signature_mass_edit_queued/readme/DESCRIPTION.md @@ -0,0 +1,5 @@ +This module lets signature mass edit operations run through queue jobs. + +A new *Run in Queue Job* option is added to signature mass edits. +When enabled, confirming a mass edit moves it to *In Progress*, creates one +queue job per matching user. diff --git a/mail_user_signature_mass_edit_queued/static/description/icon.png b/mail_user_signature_mass_edit_queued/static/description/icon.png new file mode 100644 index 000000000..3a0328b51 Binary files /dev/null and b/mail_user_signature_mass_edit_queued/static/description/icon.png differ diff --git a/mail_user_signature_mass_edit_queued/static/description/index.html b/mail_user_signature_mass_edit_queued/static/description/index.html new file mode 100644 index 000000000..5e8990f57 --- /dev/null +++ b/mail_user_signature_mass_edit_queued/static/description/index.html @@ -0,0 +1,428 @@ + + + + + +Mail User Signature Mass Edit Queued + + + +
+

Mail User Signature Mass Edit Queued

+ + +

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

+

This module lets signature mass edit operations run through queue jobs.

+

A new Run in Queue Job option is added to signature mass edits. When +enabled, confirming a mass edit moves it to In Progress, creates one +queue job per matching user.

+

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

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

+

Current maintainer:

+

sbejaoui

+

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

+

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

+
+
+
+ + diff --git a/mail_user_signature_mass_edit_queued/tests/__init__.py b/mail_user_signature_mass_edit_queued/tests/__init__.py new file mode 100644 index 000000000..69543f6a7 --- /dev/null +++ b/mail_user_signature_mass_edit_queued/tests/__init__.py @@ -0,0 +1,4 @@ +# Copyright 2026 ACSONE SA/NV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from . import test_signature_mass_edit_queued diff --git a/mail_user_signature_mass_edit_queued/tests/test_signature_mass_edit_queued.py b/mail_user_signature_mass_edit_queued/tests/test_signature_mass_edit_queued.py new file mode 100644 index 000000000..aedcd5a9c --- /dev/null +++ b/mail_user_signature_mass_edit_queued/tests/test_signature_mass_edit_queued.py @@ -0,0 +1,123 @@ +# Copyright 2026 ACSONE SA/NV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo.tests.common import TransactionCase, new_test_user, tagged + +from odoo.addons.queue_job.tests.common import trap_jobs + + +@tagged("post_install", "-at_install") +class TestSignatureMassEditQueued(TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.company = cls.env["res.company"].create( + {"name": "Queued Signature Company"} + ) + cls.user = new_test_user( + cls.env, + login="queued_signature_user", + groups="base.group_user", + context={"no_reset_password": True}, + name="Queued Signature User", + company_id=cls.company.id, + email="queued_signature_user@example.com", + ) + cls.other_user = new_test_user( + cls.env, + login="other_queued_signature_user", + groups="base.group_user", + context={"no_reset_password": True}, + name="Other Queued Signature User", + company_id=cls.company.id, + email="other_queued_signature_user@example.com", + ) + + def test_confirm_enqueues_one_signature_job_per_user_and_done_job(self): + mass_edit = self.env["signature.mass.edit"].create( + { + "company_id": self.company.id, + "run_in_queue_job": True, + "signature": "

{{ object.name }}

", + } + ) + + with trap_jobs() as trap: + mass_edit.action_confirm() + + self.assertEqual(mass_edit.state, "in_progress") + trap.assert_jobs_count(3) + for user in self.user | self.other_user: + trap.assert_enqueued_job( + mass_edit._queued_process_user_signature, + args=(user.id,), + properties={ + "description": f"User signature mass edit - {user.display_name}" + }, + ) + trap.assert_enqueued_job( + mass_edit._queued_mark_signature_mass_edit_done, + args=(2,), + properties={ + "description": ( + f"Mark user signature mass edit done - {mass_edit.display_name}" + ) + }, + ) + jobs_by_call = list(zip(trap.calls, trap.enqueued_jobs, strict=True)) + user_jobs = { + job + for call, job in jobs_by_call + if call.method.__func__ == mass_edit._queued_process_user_signature.__func__ + } + done_jobs = [ + job + for call, job in jobs_by_call + if call.method.__func__ + == mass_edit._queued_mark_signature_mass_edit_done.__func__ + ] + self.assertEqual(len(user_jobs), 2) + self.assertEqual(len(done_jobs), 1) + done_job = done_jobs[0] + self.assertEqual(done_job.depends_on, user_jobs) + self.assertTrue(done_job.graph_uuid) + self.assertTrue(all(job.graph_uuid == done_job.graph_uuid for job in user_jobs)) + self.assertTrue(all(done_job in job.reverse_depends_on for job in user_jobs)) + + def test_user_jobs_process_signature_mass_edit(self): + mass_edit = self.env["signature.mass.edit"].create( + { + "company_id": self.company.id, + "run_in_queue_job": True, + "signature": "

{{ object.name }}

", + } + ) + + with trap_jobs() as trap: + mass_edit.action_confirm() + trap.perform_enqueued_jobs() + + self.assertEqual(mass_edit.state, "done") + self.assertEqual(mass_edit.processed_user_count, 2) + self.assertEqual(self.user.signature, "

Queued Signature User

") + self.assertEqual( + self.other_user.signature, + "

Other Queued Signature User

", + ) + + def test_confirm_processes_synchronously_by_default(self): + mass_edit = self.env["signature.mass.edit"].create( + { + "company_id": self.company.id, + "signature": "

{{ object.name }}

", + } + ) + + with trap_jobs() as trap: + mass_edit.action_confirm() + + trap.assert_jobs_count(0) + self.assertFalse(mass_edit.run_in_queue_job) + self.assertEqual(mass_edit.state, "done") + self.assertEqual(mass_edit.processed_user_count, 2) + self.assertEqual(self.user.signature, "

Queued Signature User

") diff --git a/mail_user_signature_mass_edit_queued/views/signature_mass_edit_views.xml b/mail_user_signature_mass_edit_queued/views/signature_mass_edit_views.xml new file mode 100644 index 000000000..0da600bdd --- /dev/null +++ b/mail_user_signature_mass_edit_queued/views/signature_mass_edit_views.xml @@ -0,0 +1,34 @@ + + + + + signature.mass.edit + + + + + + + + + + signature.mass.edit + + + + + + + +