Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 99 additions & 0 deletions mail_template_conditional_attachment/README.rst
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.
1 change: 1 addition & 0 deletions mail_template_conditional_attachment/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
21 changes: 21 additions & 0 deletions mail_template_conditional_attachment/__manifest__.py
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",
],
}
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 ""
2 changes: 2 additions & 0 deletions mail_template_conditional_attachment/models/__init__.py
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 mail_template_conditional_attachment/models/mail_template.py
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
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"
)
3 changes: 3 additions & 0 deletions mail_template_conditional_attachment/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["whool"]
build-backend = "whool.buildapi"
4 changes: 4 additions & 0 deletions mail_template_conditional_attachment/readme/CONTRIBUTORS.md
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\>
1 change: 1 addition & 0 deletions mail_template_conditional_attachment/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Allows to add conditional attachments to email templates.
8 changes: 8 additions & 0 deletions mail_template_conditional_attachment/readme/USAGE.md
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.
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
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.
Loading