-
-
Notifications
You must be signed in to change notification settings - Fork 104
[18.0][MIG] mail_template_conditional_attachment: Migration to 18.0 #97
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
P-H-Phuc
wants to merge
4
commits into
OCA:18.0
Choose a base branch
from
P-H-Phuc:18.0-mig-mail_template_conditional_attachment
base: 18.0
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
54e4405
ADD mail_template_conditional_attachment
ivantodorovich ebf1083
[UPD] Update mail_template_conditional_attachment.pot
druidoo-transbot 4e49ecc
[IMP] mail_template_conditional_attachment: pre-commit auto fixes
036a40c
[MIG] mail_template_conditional_attachment: Migration to 18.0
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| ===================================== | ||
| Email Template Conditional Attachment | ||
| ===================================== | ||
|
|
||
| .. | ||
| !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
| !! This file is generated by oca-gen-addon-readme !! | ||
| !! changes will be overwritten. !! | ||
| !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
| !! source digest: sha256:e946bc852d29c20d8537f93a45fe27469ce18f4e39ae3c4f585c591468ad14a5 | ||
| !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
|
|
||
| .. |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_template_conditional_attachment | ||
| :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_template_conditional_attachment | ||
| :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| | ||
|
|
||
| Allows to add conditional attachments to email templates. | ||
|
|
||
| **Table of contents** | ||
|
|
||
| .. contents:: | ||
| :local: | ||
|
|
||
| Usage | ||
| ===== | ||
|
|
||
| To use conditional attachments, you need to: | ||
|
|
||
| 1. Go to the corresponding Email Template record. | ||
| 2. You should see the Conditional Attachments under Advance Settings | ||
| 3. Create a new conditional attachment, and select the domain condition. | ||
|
|
||
| You can attach multiple files under the same condition. | ||
|
|
||
| Bug Tracker | ||
| =========== | ||
|
|
||
| Bugs are tracked on `GitHub Issues <https://github.com/OCA/mail/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/mail/issues/new?body=module:%20mail_template_conditional_attachment%0Aversion:%2018.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 | ||
| ------- | ||
|
|
||
| * La Louve | ||
| * Druidoo | ||
|
|
||
| Contributors | ||
| ------------ | ||
|
|
||
| - Iván Todorovich <ivan.todorovich@druidoo.io> (https://www.druidoo.io) | ||
| - `Trobz <https://www.trobz.com>`__ | ||
|
|
||
| - Phan Hong Phuc <phucph@trobz.com> | ||
|
|
||
| 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-ivantodorovich| image:: https://github.com/ivantodorovich.png?size=40px | ||
| :target: https://github.com/ivantodorovich | ||
| :alt: ivantodorovich | ||
|
|
||
| Current `maintainer <https://odoo-community.org/page/maintainer-role>`__: | ||
|
|
||
| |maintainer-ivantodorovich| | ||
|
|
||
| This module is part of the `OCA/mail <https://github.com/OCA/mail/tree/18.0/mail_template_conditional_attachment>`_ project on GitHub. | ||
|
|
||
| You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| from . import models |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| # Copyright 2016 La Louve | ||
| # Copyright 2019 Druidoo | ||
| # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
| { | ||
| "name": "Email Template Conditional Attachment", | ||
| "summary": "Allow to add conditional attachments to email templates", | ||
| "version": "18.0.1.0.0", | ||
| "category": "Uncategorized", | ||
| "website": "https://github.com/OCA/mail", | ||
| "author": "La Louve, Druidoo, Odoo Community Association (OCA)", | ||
| "maintainers": ["ivantodorovich"], | ||
| "license": "AGPL-3", | ||
| "depends": [ | ||
| "mail", | ||
| ], | ||
| "data": [ | ||
| "views/mail_template.xml", | ||
| "security/ir.model.access.csv", | ||
| "security/mail_template_condition_attachment_security.xml", | ||
| ], | ||
| } |
97 changes: 97 additions & 0 deletions
97
mail_template_conditional_attachment/i18n/mail_template_conditional_attachment.pot
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| # Translation of Odoo Server. | ||
| # This file contains the translation of the following modules: | ||
| # * mail_template_conditional_attachment | ||
| # | ||
| msgid "" | ||
| msgstr "" | ||
| "Project-Id-Version: Odoo Server 18.0\n" | ||
| "Report-Msgid-Bugs-To: \n" | ||
| "POT-Creation-Date: 2025-11-06 05:00+0000\n" | ||
| "PO-Revision-Date: 2025-11-06 05:00+0000\n" | ||
| "Last-Translator: \n" | ||
| "Language-Team: \n" | ||
| "MIME-Version: 1.0\n" | ||
| "Content-Type: text/plain; charset=UTF-8\n" | ||
| "Content-Transfer-Encoding: \n" | ||
| "Plural-Forms: \n" | ||
|
|
||
| #. module: mail_template_conditional_attachment | ||
| #: model:ir.model.fields,field_description:mail_template_conditional_attachment.field_mail_template_conditional_attachment__filter_domain | ||
| msgid "Apply on" | ||
| msgstr "" | ||
|
|
||
| #. module: mail_template_conditional_attachment | ||
| #: model:ir.model.fields,field_description:mail_template_conditional_attachment.field_mail_template_conditional_attachment__attachment_ids | ||
| msgid "Attachments" | ||
| msgstr "" | ||
|
|
||
| #. module: mail_template_conditional_attachment | ||
| #: model:ir.model.fields,field_description:mail_template_conditional_attachment.field_mail_template__conditional_attachment_ids | ||
| msgid "Conditional Attachment" | ||
| msgstr "" | ||
|
|
||
| #. module: mail_template_conditional_attachment | ||
| #: model_terms:ir.ui.view,arch_db:mail_template_conditional_attachment.email_template_form | ||
| msgid "Conditional Attachments" | ||
| msgstr "" | ||
|
|
||
| #. module: mail_template_conditional_attachment | ||
| #: model:ir.model.fields,field_description:mail_template_conditional_attachment.field_mail_template_conditional_attachment__create_uid | ||
| msgid "Created by" | ||
| msgstr "" | ||
|
|
||
| #. module: mail_template_conditional_attachment | ||
| #: model:ir.model.fields,field_description:mail_template_conditional_attachment.field_mail_template_conditional_attachment__create_date | ||
| msgid "Created on" | ||
| msgstr "" | ||
|
|
||
| #. module: mail_template_conditional_attachment | ||
| #: model:ir.model.fields,field_description:mail_template_conditional_attachment.field_mail_template_conditional_attachment__name | ||
| msgid "Description" | ||
| msgstr "" | ||
|
|
||
| #. module: mail_template_conditional_attachment | ||
| #: model:ir.model.fields,field_description:mail_template_conditional_attachment.field_mail_template_conditional_attachment__display_name | ||
| msgid "Display Name" | ||
| msgstr "" | ||
|
|
||
| #. module: mail_template_conditional_attachment | ||
| #: model:ir.model,name:mail_template_conditional_attachment.model_mail_template | ||
| msgid "Email Templates" | ||
| msgstr "" | ||
|
|
||
| #. module: mail_template_conditional_attachment | ||
| #: model:ir.model.fields,field_description:mail_template_conditional_attachment.field_mail_template_conditional_attachment__id | ||
| msgid "ID" | ||
| msgstr "" | ||
|
|
||
| #. module: mail_template_conditional_attachment | ||
| #: model:ir.model.fields,help:mail_template_conditional_attachment.field_mail_template_conditional_attachment__filter_domain | ||
| msgid "" | ||
| "If present, this condition must be satisfied to include the attachments." | ||
| msgstr "" | ||
|
|
||
| #. module: mail_template_conditional_attachment | ||
| #: model:ir.model.fields,field_description:mail_template_conditional_attachment.field_mail_template_conditional_attachment__write_uid | ||
| msgid "Last Updated by" | ||
| msgstr "" | ||
|
|
||
| #. module: mail_template_conditional_attachment | ||
| #: model:ir.model.fields,field_description:mail_template_conditional_attachment.field_mail_template_conditional_attachment__write_date | ||
| msgid "Last Updated on" | ||
| msgstr "" | ||
|
|
||
| #. module: mail_template_conditional_attachment | ||
| #: model:ir.model.fields,field_description:mail_template_conditional_attachment.field_mail_template_conditional_attachment__mail_template_id | ||
| msgid "Mail Template" | ||
| msgstr "" | ||
|
|
||
| #. module: mail_template_conditional_attachment | ||
| #: model:ir.model,name:mail_template_conditional_attachment.model_mail_template_conditional_attachment | ||
| msgid "Mail Template Conditional Attachment" | ||
| msgstr "" | ||
|
|
||
| #. module: mail_template_conditional_attachment | ||
| #: model:ir.model.fields,field_description:mail_template_conditional_attachment.field_mail_template_conditional_attachment__model_name | ||
| msgid "Model" | ||
| msgstr "" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| from . import mail_template | ||
| from . import mail_template_conditional_attachment |
25 changes: 25 additions & 0 deletions
25
mail_template_conditional_attachment/models/mail_template.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| from odoo import fields, models | ||
|
|
||
|
|
||
| class MailTemplate(models.Model): | ||
| _inherit = "mail.template" | ||
|
|
||
| conditional_attachment_ids = fields.One2many( | ||
| "mail.template.conditional.attachment", | ||
| "mail_template_id", | ||
| ) | ||
|
|
||
| def _generate_template_attachments( | ||
| self, res_ids, render_fields, render_results=None | ||
| ): | ||
| render_results = super()._generate_template_attachments( | ||
| res_ids, render_fields, render_results | ||
| ) | ||
|
|
||
| if self.conditional_attachment_ids: | ||
| for res_id in res_ids: | ||
| attachment_ids = self.conditional_attachment_ids.get_attachment_ids( | ||
| res_id | ||
| ) | ||
| render_results[res_id]["attachment_ids"] = attachment_ids.ids | ||
| return render_results |
54 changes: 54 additions & 0 deletions
54
mail_template_conditional_attachment/models/mail_template_conditional_attachment.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| from odoo import fields, models | ||
| from odoo.tools.safe_eval import datetime, dateutil, safe_eval, time | ||
|
|
||
|
|
||
| class MailTemplateConditionalAttachment(models.Model): | ||
| _name = "mail.template.conditional.attachment" | ||
| _description = "Mail Template Conditional Attachment" | ||
|
|
||
| name = fields.Char("Description", required=True) | ||
|
|
||
| mail_template_id = fields.Many2one( | ||
| "mail.template", | ||
| ondelete="cascade", | ||
| required=True, | ||
| index=True, | ||
| ) | ||
|
|
||
| attachment_ids = fields.Many2many( | ||
| "ir.attachment", | ||
| string="Attachments", | ||
| ) | ||
|
|
||
| model_name = fields.Char(related="mail_template_id.model_id.model") | ||
|
|
||
| filter_domain = fields.Char( | ||
| "Apply on", | ||
| help="If present, this condition must be satisfied " | ||
| "to include the attachments.", | ||
| ) | ||
|
|
||
| def _get_eval_context(self): | ||
| return { | ||
| "datetime": datetime, | ||
| "dateutil": dateutil, | ||
| "time": time, | ||
| "uid": self.env.uid, | ||
| "user": self.env.user, | ||
| } | ||
|
|
||
| def _check_condition(self, res_id): | ||
| self.ensure_one() | ||
| if self.filter_domain: | ||
| domain = [("id", "=", res_id)] | ||
| domain += safe_eval(self.filter_domain, self._get_eval_context()) | ||
| model = self.env[self.model_name] | ||
| return bool(model.search_count(domain)) | ||
| else: | ||
| return True | ||
|
|
||
| def get_attachment_ids(self, res_id): | ||
| self.mapped("mail_template_id").ensure_one() | ||
| return self.filtered(lambda r: r._check_condition(res_id)).mapped( | ||
| "attachment_ids" | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| [build-system] | ||
| requires = ["whool"] | ||
| build-backend = "whool.buildapi" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| - Iván Todorovich \<ivan.todorovich@druidoo.io\> | ||
| (<https://www.druidoo.io>) | ||
| - [Trobz](https://www.trobz.com) | ||
| - Phan Hong Phuc \<phucph@trobz.com\> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Allows to add conditional attachments to email templates. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| To use conditional attachments, you need to: | ||
|
|
||
| 1. Go to the corresponding Email Template record. | ||
| 2. You should see the Conditional Attachments under Advance Settings | ||
| 3. Create a new conditional attachment, and select the domain | ||
| condition. | ||
|
|
||
| You can attach multiple files under the same condition. |
2 changes: 2 additions & 0 deletions
2
mail_template_conditional_attachment/security/ir.model.access.csv
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink | ||
| access_mail_template_conditional_attachment_user,mail.template.conditional.attachment.user,model_mail_template_conditional_attachment,base.group_user,1,1,1,1 | ||
35 changes: 35 additions & 0 deletions
35
..._template_conditional_attachment/security/mail_template_condition_attachment_security.xml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| <?xml version="1.0" encoding="utf-8" ?> | ||
| <odoo noupdate="1"> | ||
| <record id="mail_template_condition_attachment_employee_rule" model="ir.rule"> | ||
| <field | ||
| name="name" | ||
| >Employees can only modify template condition attachment they have created</field> | ||
| <field name="model_id" ref="model_mail_template_conditional_attachment" /> | ||
| <field name="domain_force">[ | ||
| '|', | ||
| ('mail_template_id.create_uid', '=', user.id), | ||
| ('mail_template_id.user_id', '=', user.id) | ||
| ]</field> | ||
| <field name="groups" eval="[Command.link(ref('base.group_user'))]" /> | ||
| <field name="perm_create" eval="True" /> | ||
| <field name="perm_read" eval="False" /> | ||
| <field name="perm_write" eval="True" /> | ||
| <field name="perm_unlink" eval="True" /> | ||
| </record> | ||
|
|
||
| <record id="mail_template_editor_rule" model="ir.rule"> | ||
| <field | ||
| name="name" | ||
| >Mail Template Condition Attachment Editors - Edit All Templates Condition</field> | ||
| <field name="model_id" ref="model_mail_template_conditional_attachment" /> | ||
| <field name="domain_force">[(1, '=', 1)]</field> | ||
| <field | ||
| name="groups" | ||
| eval="[Command.link(ref('mail.group_mail_template_editor')), Command.link(ref('base.group_system'))]" | ||
| /> | ||
| <field name="perm_create" eval="True" /> | ||
| <field name="perm_read" eval="False" /> | ||
| <field name="perm_write" eval="True" /> | ||
| <field name="perm_unlink" eval="True" /> | ||
| </record> | ||
| </odoo> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.