diff --git a/mail_template_substitute_account_move/README.rst b/mail_template_substitute_account_move/README.rst new file mode 100644 index 000000000..dbee9536d --- /dev/null +++ b/mail_template_substitute_account_move/README.rst @@ -0,0 +1,104 @@ +===================================== +Mail Template Substitute Account Move +===================================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:b0e4bf34d022b96d8821d6a18a6941cd9f6224ce1328a2c899271b4f60c97320 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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%2Faccount--financial--tools-lightgray.png?logo=github + :target: https://github.com/OCA/account-financial-tools/tree/17.0/mail_template_substitute_account_move + :alt: OCA/account-financial-tools +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/account-financial-tools-17-0/account-financial-tools-17-0-mail_template_substitute_account_move + :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/account-financial-tools&target_branch=17.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module extends the functionality of mail_template_substitute to +support the substitution for account.move. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +To use this module, you need to: + +1. Go to 'Email' / 'Templates' +2. Select the desired template you want to substitute +3. In the substitutions page add a new line +4. Select the substitution template +5. Set a domain to specify when this substitution should happen + +Known issues / Roadmap +====================== + + + +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 +------- + +* Sodexis + +Contributors +------------ + +- Sodexis https://www.sodexis.com + +- SodexisTeam +- Sakthivel + +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-SodexisTeam| image:: https://github.com/SodexisTeam.png?size=40px + :target: https://github.com/SodexisTeam + :alt: SodexisTeam + +Current `maintainer `__: + +|maintainer-SodexisTeam| + +This module is part of the `OCA/account-financial-tools `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/mail_template_substitute_account_move/__init__.py b/mail_template_substitute_account_move/__init__.py new file mode 100644 index 000000000..31660d6a9 --- /dev/null +++ b/mail_template_substitute_account_move/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from . import models diff --git a/mail_template_substitute_account_move/__manifest__.py b/mail_template_substitute_account_move/__manifest__.py new file mode 100644 index 000000000..d78381c63 --- /dev/null +++ b/mail_template_substitute_account_move/__manifest__.py @@ -0,0 +1,18 @@ +# Copyright 2024 Sodexis +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +{ + "name": "Mail Template Substitute Account Move", + "summary": "Module to support Mail Template Substitution for Account Move", + "version": "17.0.1.0.0", + "category": "Accounting", + "website": "https://github.com/OCA/account-financial-tools", + "author": "Sodexis, Odoo Community Association (OCA)", + "maintainers": ["SodexisTeam"], + "license": "AGPL-3", + "installable": True, + "depends": [ + "account", + "mail_template_substitute", + ], + "auto_install": ["account", "mail_template_substitute"], +} diff --git a/mail_template_substitute_account_move/models/__init__.py b/mail_template_substitute_account_move/models/__init__.py new file mode 100644 index 000000000..0c439503c --- /dev/null +++ b/mail_template_substitute_account_move/models/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from . import account_move diff --git a/mail_template_substitute_account_move/models/account_move.py b/mail_template_substitute_account_move/models/account_move.py new file mode 100644 index 000000000..8c27f17a8 --- /dev/null +++ b/mail_template_substitute_account_move/models/account_move.py @@ -0,0 +1,35 @@ +# Copyright 2024 Sodexis +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import models + + +class AccountMove(models.Model): + _inherit = "account.move" + + def action_send_and_print(self): + report_action = super().action_send_and_print() + substitution_template = ( + self.env["mail.compose.message"] + .sudo() + ._get_substitution_template( + ( + report_action["context"]["composition_mode"] + if "composition_mode" in report_action["context"] + else "comment" + ), + self.env["mail.template"].browse( + report_action["context"]["default_mail_template_id"] + ), + ( + report_action["context"]["active_ids"] + if "active_ids" in report_action["context"] + else [] + ), + ) + ) + if substitution_template: + report_action["context"][ + "default_mail_template_id" + ] = substitution_template.id + return report_action diff --git a/mail_template_substitute_account_move/pyproject.toml b/mail_template_substitute_account_move/pyproject.toml new file mode 100644 index 000000000..4231d0ccc --- /dev/null +++ b/mail_template_substitute_account_move/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/mail_template_substitute_account_move/readme/CONTRIBUTORS.md b/mail_template_substitute_account_move/readme/CONTRIBUTORS.md new file mode 100644 index 000000000..0d2ea2493 --- /dev/null +++ b/mail_template_substitute_account_move/readme/CONTRIBUTORS.md @@ -0,0 +1,4 @@ +* Sodexis + +- SodexisTeam \<\> +- Sakthivel \<\> \ No newline at end of file diff --git a/mail_template_substitute_account_move/readme/DESCRIPTION.md b/mail_template_substitute_account_move/readme/DESCRIPTION.md new file mode 100644 index 000000000..dcb077c50 --- /dev/null +++ b/mail_template_substitute_account_move/readme/DESCRIPTION.md @@ -0,0 +1,2 @@ +This module extends the functionality of mail_template_substitute to support the substitution for account.move. + diff --git a/mail_template_substitute_account_move/readme/ROADMAP.md b/mail_template_substitute_account_move/readme/ROADMAP.md new file mode 100644 index 000000000..8b1378917 --- /dev/null +++ b/mail_template_substitute_account_move/readme/ROADMAP.md @@ -0,0 +1 @@ + diff --git a/mail_template_substitute_account_move/readme/USAGE.md b/mail_template_substitute_account_move/readme/USAGE.md new file mode 100644 index 000000000..43527d9f3 --- /dev/null +++ b/mail_template_substitute_account_move/readme/USAGE.md @@ -0,0 +1,7 @@ +To use this module, you need to: + +1. Go to 'Email' / 'Templates' +2. Select the desired template you want to substitute +3. In the substitutions page add a new line +4. Select the substitution template +5. Set a domain to specify when this substitution should happen diff --git a/mail_template_substitute_account_move/static/description/icon.png b/mail_template_substitute_account_move/static/description/icon.png new file mode 100644 index 000000000..3a0328b51 Binary files /dev/null and b/mail_template_substitute_account_move/static/description/icon.png differ diff --git a/mail_template_substitute_account_move/static/description/icon.svg b/mail_template_substitute_account_move/static/description/icon.svg new file mode 100644 index 000000000..a7a26d093 --- /dev/null +++ b/mail_template_substitute_account_move/static/description/icon.svg @@ -0,0 +1,79 @@ + + + + + + + + image/svg+xml + + + + + + + + + + + diff --git a/mail_template_substitute_account_move/static/description/index.html b/mail_template_substitute_account_move/static/description/index.html new file mode 100644 index 000000000..0a4c8624b --- /dev/null +++ b/mail_template_substitute_account_move/static/description/index.html @@ -0,0 +1,444 @@ + + + + + +Mail Template Substitute Account Move + + + +
+

Mail Template Substitute Account Move

+ + +

Beta License: AGPL-3 OCA/account-financial-tools Translate me on Weblate Try me on Runboat

+

This module extends the functionality of mail_template_substitute to +support the substitution for account.move.

+

Table of contents

+ +
+

Usage

+

To use this module, you need to:

+
    +
  1. Go to ‘Email’ / ‘Templates’
  2. +
  3. Select the desired template you want to substitute
  4. +
  5. In the substitutions page add a new line
  6. +
  7. Select the substitution template
  8. +
  9. Set a domain to specify when this substitution should happen
  10. +
+
+ +
+

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

+
    +
  • Sodexis
  • +
+
+
+

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:

+

SodexisTeam

+

This module is part of the OCA/account-financial-tools project on GitHub.

+

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

+
+
+
+ + diff --git a/mail_template_substitute_account_move/tests/__init__.py b/mail_template_substitute_account_move/tests/__init__.py new file mode 100644 index 000000000..ed9510c3c --- /dev/null +++ b/mail_template_substitute_account_move/tests/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from . import test_mail_template_substitute_account_move diff --git a/mail_template_substitute_account_move/tests/test_mail_template_substitute_account_move.py b/mail_template_substitute_account_move/tests/test_mail_template_substitute_account_move.py new file mode 100644 index 000000000..70e77a7c8 --- /dev/null +++ b/mail_template_substitute_account_move/tests/test_mail_template_substitute_account_move.py @@ -0,0 +1,56 @@ +# Copyright 2024 Sodexis +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo.tests.common import TransactionCase + + +class TestMailTemplateSubstitute(TransactionCase): + def setUp(self): + super().setUp() + self.smt2 = self.env["mail.template"].create( + { + "name": "substitute_template_2", + "model_id": self.env.ref("account.model_account_move").id, + } + ) + self.smt1 = self.env["mail.template"].create( + { + "name": "substitute_template_1", + "model_id": self.env.ref("account.model_account_move").id, + "mail_template_substitution_rule_ids": [ + ( + 0, + 0, + { + "substitution_mail_template_id": self.smt2.id, + "domain": "[('id', '=', False)]", + }, + ) + ], + } + ) + self.mt = self.env["mail.template"].create( + { + "name": "base_template", + "model_id": self.env.ref("account.model_account_move").id, + "mail_template_substitution_rule_ids": [ + (0, 0, {"substitution_mail_template_id": self.smt1.id}) + ], + } + ) + self.mail_compose = self.env["mail.compose.message"].create( + {"template_id": self.mt.id, "composition_mode": "mass_mail"} + ) + self.moves = ( + self.env["account.move"] + .search([]) + .filtered(lambda move: move.is_sale_document(include_receipts=True)) + ) + self.move = self.moves and self.moves[0] + + def test_action_send_and_print(self): + result = self.move.action_send_and_print() + self.assertFalse( + result["context"]["default_mail_template_id"] + == self.mail_compose.template_id.id + )