Skip to content

Commit 435c3cc

Browse files
committed
[MIG] mail_template_conditional_attachment: Migration to 18.0
1 parent 4d61fb3 commit 435c3cc

13 files changed

Lines changed: 155 additions & 59 deletions

mail_template_conditional_attachment/README.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ Contributors
6969
------------
7070

7171
- Iván Todorovich <ivan.todorovich@druidoo.io> (https://www.druidoo.io)
72+
- `Trobz <https://www.trobz.com>`__
73+
74+
- Phan Hong Phuc <phucph@trobz.com>
7275

7376
Maintainers
7477
-----------

mail_template_conditional_attachment/__manifest__.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
{
55
"name": "Email Template Conditional Attachment",
66
"summary": "Allow to add conditional attachments to email templates",
7-
"version": "12.0.1.0.0",
7+
"version": "18.0.1.0.0",
88
"category": "Uncategorized",
99
"website": "https://github.com/OCA/mail",
1010
"author": "La Louve, Druidoo, Odoo Community Association (OCA)",
@@ -16,8 +16,6 @@
1616
"data": [
1717
"views/mail_template.xml",
1818
"security/ir.model.access.csv",
19-
],
20-
"demo": [
21-
"demo/mail_template.xml",
19+
"security/mail_template_condition_attachment_security.xml",
2220
],
2321
}

mail_template_conditional_attachment/demo/mail_template.xml

Lines changed: 0 additions & 2 deletions
This file was deleted.

mail_template_conditional_attachment/i18n/mail_template_conditional_attachment.pot

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
# Translation of Odoo Server.
22
# This file contains the translation of the following modules:
3-
# * mail_template_conditional_attachment
3+
# * mail_template_conditional_attachment
44
#
55
msgid ""
66
msgstr ""
7-
"Project-Id-Version: Odoo Server 12.0\n"
7+
"Project-Id-Version: Odoo Server 18.0\n"
88
"Report-Msgid-Bugs-To: \n"
9-
"Last-Translator: <>\n"
9+
"POT-Creation-Date: 2025-11-06 05:00+0000\n"
10+
"PO-Revision-Date: 2025-11-06 05:00+0000\n"
11+
"Last-Translator: \n"
1012
"Language-Team: \n"
1113
"MIME-Version: 1.0\n"
1214
"Content-Type: text/plain; charset=UTF-8\n"
@@ -24,8 +26,11 @@ msgid "Attachments"
2426
msgstr ""
2527

2628
#. module: mail_template_conditional_attachment
27-
#: model:ir.model.fields,field_description:mail_template_conditional_attachment.field_email_template_preview__conditional_attachment_ids
2829
#: model:ir.model.fields,field_description:mail_template_conditional_attachment.field_mail_template__conditional_attachment_ids
30+
msgid "Conditional Attachment"
31+
msgstr ""
32+
33+
#. module: mail_template_conditional_attachment
2934
#: model_terms:ir.ui.view,arch_db:mail_template_conditional_attachment.email_template_form
3035
msgid "Conditional Attachments"
3136
msgstr ""
@@ -62,12 +67,8 @@ msgstr ""
6267

6368
#. module: mail_template_conditional_attachment
6469
#: model:ir.model.fields,help:mail_template_conditional_attachment.field_mail_template_conditional_attachment__filter_domain
65-
msgid "If present, this condition must be satisfied to include the attachments."
66-
msgstr ""
67-
68-
#. module: mail_template_conditional_attachment
69-
#: model:ir.model.fields,field_description:mail_template_conditional_attachment.field_mail_template_conditional_attachment____last_update
70-
msgid "Last Modified on"
70+
msgid ""
71+
"If present, this condition must be satisfied to include the attachments."
7172
msgstr ""
7273

7374
#. module: mail_template_conditional_attachment
@@ -94,4 +95,3 @@ msgstr ""
9495
#: model:ir.model.fields,field_description:mail_template_conditional_attachment.field_mail_template_conditional_attachment__model_name
9596
msgid "Model"
9697
msgstr ""
97-
Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
from odoo import api, fields, models
2-
from odoo.tools import pycompat
1+
from odoo import fields, models
32

43

54
class MailTemplate(models.Model):
@@ -8,29 +7,19 @@ class MailTemplate(models.Model):
87
conditional_attachment_ids = fields.One2many(
98
"mail.template.conditional.attachment",
109
"mail_template_id",
11-
string="Conditional Attachments",
1210
)
1311

14-
@api.multi
15-
def generate_email(self, res_ids, **kwargs):
16-
"""Overload this method to attach conditional attachments"""
17-
self.ensure_one()
12+
def _generate_template_attachments(
13+
self, res_ids, render_fields, render_results=None
14+
):
15+
render_results = super()._generate_template_attachments(
16+
res_ids, render_fields, render_results
17+
)
1818

19-
# Odoo way of handling different result for multi/one res_ids
20-
# Placed before super(), so we force multi_mode=True there
21-
multi_mode = True
22-
if isinstance(res_ids, pycompat.integer_types):
23-
res_ids = [res_ids]
24-
multi_mode = False
25-
26-
results = super().generate_email(res_ids, **kwargs)
27-
28-
# Add conditional attachments
2919
if self.conditional_attachment_ids:
3020
for res_id in res_ids:
3121
attachment_ids = self.conditional_attachment_ids.get_attachment_ids(
3222
res_id
3323
)
34-
results[res_id]["attachment_ids"] = attachment_ids.ids
35-
36-
return multi_mode and results or results[res_ids[0]]
24+
render_results[res_id]["attachment_ids"] = attachment_ids.ids
25+
return render_results

mail_template_conditional_attachment/models/mail_template_conditional_attachment.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
1-
import datetime
2-
import time
3-
4-
import dateutil
5-
6-
from odoo import api, fields, models
7-
from odoo.tools import safe_eval
1+
from odoo import fields, models
2+
from odoo.tools.safe_eval import datetime, dateutil, safe_eval, time
83

94

105
class MailTemplateConditionalAttachment(models.Model):
@@ -52,7 +47,6 @@ def _check_condition(self, res_id):
5247
else:
5348
return True
5449

55-
@api.multi
5650
def get_attachment_ids(self, res_id):
5751
self.mapped("mail_template_id").ensure_one()
5852
return self.filtered(lambda r: r._check_condition(res_id)).mapped(
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
- Iván Todorovich \<ivan.todorovich@druidoo.io\>
22
(<https://www.druidoo.io>)
3+
- [Trobz](https://www.trobz.com)
4+
- Phan Hong Phuc \<phucph@trobz.com\>
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<odoo noupdate="1">
3+
<record id="mail_template_condition_attachment_employee_rule" model="ir.rule">
4+
<field
5+
name="name"
6+
>Employees can only modify template condition attachment they have created or been assigned</field>
7+
<field name="model_id" ref="model_mail_template_conditional_attachment" />
8+
<field
9+
name="domain_force"
10+
>['|', ('create_uid', '=', user.id), ('user_id', '=', user.id)]</field>
11+
<field name="groups" eval="[Command.link(ref('base.group_user'))]" />
12+
<field name="perm_create" eval="True" />
13+
<field name="perm_read" eval="False" />
14+
<field name="perm_write" eval="True" />
15+
<field name="perm_unlink" eval="True" />
16+
</record>
17+
18+
<record id="mail_template_editor_rule" model="ir.rule">
19+
<field
20+
name="name"
21+
>Mail Template Condition Attachment Editors - Edit All Templates Condition</field>
22+
<field name="model_id" ref="model_mail_template_conditional_attachment" />
23+
<field name="domain_force">[(1, '=', 1)]</field>
24+
<field
25+
name="groups"
26+
eval="[Command.link(ref('group_mail_template_editor')), Command.link(ref('base.group_system'))]"
27+
/>
28+
<field name="perm_create" eval="True" />
29+
<field name="perm_read" eval="False" />
30+
<field name="perm_write" eval="True" />
31+
<field name="perm_unlink" eval="True" />
32+
</record>
33+
</odoo>

mail_template_conditional_attachment/static/description/index.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,10 @@ <h2><a class="toc-backref" href="#toc-entry-4">Authors</a></h2>
415415
<h2><a class="toc-backref" href="#toc-entry-5">Contributors</a></h2>
416416
<ul class="simple">
417417
<li>Iván Todorovich &lt;<a class="reference external" href="mailto:ivan.todorovich&#64;druidoo.io">ivan.todorovich&#64;druidoo.io</a>&gt; (<a class="reference external" href="https://www.druidoo.io">https://www.druidoo.io</a>)</li>
418+
<li><a class="reference external" href="https://www.trobz.com">Trobz</a><ul>
419+
<li>Phan Hong Phuc &lt;<a class="reference external" href="mailto:phucph&#64;trobz.com">phucph&#64;trobz.com</a>&gt;</li>
420+
</ul>
421+
</li>
418422
</ul>
419423
</div>
420424
<div class="section" id="maintainers">
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import test_mail_template_conditional_attachment

0 commit comments

Comments
 (0)