[NEW] event_mail_attachment
This commit is contained in:
1
event_mail_attachment/__init__.py
Normal file
1
event_mail_attachment/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from . import models
|
24
event_mail_attachment/__manifest__.py
Normal file
24
event_mail_attachment/__manifest__.py
Normal file
@@ -0,0 +1,24 @@
|
||||
# Copyright 2016-2020 Akretion France (<https://www.akretion.com>)
|
||||
# @author: Alexis de Lattre <alexis.delattre@akretion.com>
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
|
||||
|
||||
{
|
||||
"name": "Event mail attachments",
|
||||
"version": "16.0.0.0.0",
|
||||
"license": "AGPL-3",
|
||||
"author": "Elabore",
|
||||
"website": "https://www.elabore.coop",
|
||||
'summary': 'Event mail attachments',
|
||||
'description': """
|
||||
Event mail attachments
|
||||
----------------------------------------------------
|
||||
|
||||
""",
|
||||
"category": "",
|
||||
"depends": ["ctl_training_customization"],
|
||||
"data": [
|
||||
'views/mail_template_views.xml'
|
||||
],
|
||||
"installable": True,
|
||||
|
||||
}
|
1
event_mail_attachment/models/__init__.py
Normal file
1
event_mail_attachment/models/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from . import mail_template
|
48
event_mail_attachment/models/mail_template.py
Normal file
48
event_mail_attachment/models/mail_template.py
Normal file
@@ -0,0 +1,48 @@
|
||||
from odoo import _, api, Command, fields, models
|
||||
from lxml import etree, html
|
||||
|
||||
class MailTemplate(models.Model):
|
||||
_inherit = "mail.template"
|
||||
|
||||
event_attachment_name_prefix = fields.Char('Attachment name prefix', help="If there is an attachment in event registration, or in event, with a name that starts with this name, it will be attached to the mail.")
|
||||
|
||||
|
||||
def generate_email(self, res_ids, fields):
|
||||
res = super(MailTemplate, self).generate_email(res_ids, fields)
|
||||
|
||||
self.ensure_one()
|
||||
multi_mode = True
|
||||
if isinstance(res_ids, int):
|
||||
res_ids = [res_ids]
|
||||
multi_mode = False
|
||||
|
||||
for lang, (template, template_res_ids) in self._classify_per_lang(res_ids).items():
|
||||
#add reports attached to event.registration or event.event from attachment name
|
||||
if template.event_attachment_name_prefix:
|
||||
for res_id in template_res_ids:
|
||||
event_registration = self.env['event.registration'].browse(res_id)
|
||||
attachments = self.env['ir.attachment'].search([
|
||||
('res_model','=','event.registration'),
|
||||
('res_id','=',res_id),
|
||||
('name','like',template.event_attachment_name_prefix)])
|
||||
attachments |= self.env['ir.attachment'].search([
|
||||
('res_model','=','event.event'),
|
||||
('res_id','=',event_registration.event_id.id),
|
||||
('name','like',template.event_attachment_name_prefix)])
|
||||
|
||||
attachments_res = [(attachment.name, attachment.datas) for attachment in attachments]
|
||||
|
||||
if multi_mode:
|
||||
if res_id in res:
|
||||
if not 'attachments' in res[res_id]:
|
||||
res[res_id]['attachments'] = attachments_res
|
||||
else:
|
||||
res[res_id]['attachments'].extend(attachments_res)
|
||||
else:
|
||||
if not 'attachments' in res:
|
||||
res['attachments'] = attachments_res
|
||||
else:
|
||||
res['attachments'].extend(attachments_res)
|
||||
|
||||
|
||||
return res
|
27
event_mail_attachment/views/mail_template_views.xml
Normal file
27
event_mail_attachment/views/mail_template_views.xml
Normal file
@@ -0,0 +1,27 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<odoo>
|
||||
<data>
|
||||
<record model="ir.ui.view" id="email_template_form_event_mail_attachment">
|
||||
<field name="name">email.template.form.event.mail.attachment</field>
|
||||
<field name="inherit_id" ref="mail.email_template_form" />
|
||||
<field name="model">mail.template</field>
|
||||
<field name="arch" type="xml">
|
||||
<field name="report_template" position="after">
|
||||
<field name="event_attachment_name_prefix" />
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record model="ir.ui.view" id="email_template_tree_event_mail_attachment">
|
||||
<field name="name">email.template.tree.event.mail.attachment</field>
|
||||
<field name="inherit_id" ref="mail.email_template_tree" />
|
||||
<field name="model">mail.template</field>
|
||||
<field name="arch" type="xml">
|
||||
<field name="report_name" position="after">
|
||||
<field name="event_attachment_name_prefix" />
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
</data>
|
||||
</odoo>
|
Reference in New Issue
Block a user