Browse Source

[MIG] mail_template_multi_report: Migrated to 10.0

pull/264/head
BALDE 7 years ago
parent
commit
b1371451d3
  1. 77
      mail_template_multi_report/README.rst
  2. 5
      mail_template_multi_report/__init__.py
  3. 23
      mail_template_multi_report/__manifest__.py
  4. 100
      mail_template_multi_report/i18n/fr.po
  5. 6
      mail_template_multi_report/models/__init__.py
  6. 62
      mail_template_multi_report/models/mail_template.py
  7. 40
      mail_template_multi_report/models/mail_template_report_line.py
  8. 3
      mail_template_multi_report/security/ir.model.access.csv
  9. 4
      mail_template_multi_report/tests/__init__.py
  10. 91
      mail_template_multi_report/tests/test_mail_template.py
  11. 21
      mail_template_multi_report/views/mail_template.xml

77
mail_template_multi_report/README.rst

@ -0,0 +1,77 @@
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
============================
Mail Template Multi Reports
============================
This module adds the option to generate more than one report in an email template.
Also, this module adds the options to attach a report to the email depending on a condition.
Configuration
=============
To configure this module, you need to:
1. Go to Settings -> Technical -> Email -> Templates
2. In the mail template form view, go to the Advanced Settings tab.
3. Add extra reports in the Other Reports field.
If the field Condition is filled, then the report will attached depending on
the evaluation of the condition.
Usage
=====
Open a email template wizard and select your template. Your extra reports are added automatically.
.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
:alt: Try me on Runbot
:target: https://runbot.odoo-community.org/runbot/social/10.0
Known issues / Roadmap
======================
The other reports added to the template do not support legacy reports such as rml.
Only qweb reports are available for now.
Only french translation is added in this module.
Bug Tracker
===========
Bugs are tracked on `GitHub Issues
<https://github.com/OCA/social/issues>`_. In case of trouble, please
check there if your issue has already been reported. If you spotted it first,
help us smashing it by providing a detailed and welcomed feedback.
Credits
=======
Images
------
* Odoo Community Association: `Icon <https://github.com/OCA/maintainer-tools/blob/master/template/module/static/description/icon.svg>`_.
Contributors
------------
* David Dufresne <david.dufresne@savoirfairelinux.com>
* Oury Balde <oury.balde@xcg-consulting.fr>
Maintainer
----------
.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org
This module is maintained by the OCA.
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.
To contribute to this module, please visit https://odoo-community.org.

5
mail_template_multi_report/__init__.py

@ -0,0 +1,5 @@
# -*- coding: utf-8 -*-
# © 2016 Savoir-faire Linux
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from . import models

23
mail_template_multi_report/__manifest__.py

@ -0,0 +1,23 @@
# -*- coding: utf-8 -*-
# © 2016 Savoir-faire Linux
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{
'name': 'Mail Template Multi Report',
'version': '10.0.1.0.0',
'category': 'Marketing',
'summary': 'Multiple Reports in Mail Templates',
'author': 'Savoir-faire Linux,Odoo Community Association (OCA)',
'website': 'http://www.savoirfairelinux.com',
'license': 'AGPL-3',
'depends': [
'mail',
],
'data': [
'security/ir.model.access.csv',
'views/mail_template.xml',
],
'installable': True,
'application': False,
'auto_install': False,
}

100
mail_template_multi_report/i18n/fr.po

@ -0,0 +1,100 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * mail_template_multi_report
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 10.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2018-04-25 10:21+0000\n"
"PO-Revision-Date: 2018-04-25 10:21+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_multi_report
#: model:ir.model.fields,help:mail_template_multi_report.field_mail_template_report_line_condition
msgid "An expression evaluated to determine if the report is to be attached to the email. If blank, the report will always be attached."
msgstr "An expression evaluated to determine if the report is to be attached to the email. If blank, the report will always be attached."
#. module: mail_template_multi_report
#: model:ir.model.fields,field_description:mail_template_multi_report.field_mail_template_report_line_condition
msgid "Condition"
msgstr "Condition"
#. module: mail_template_multi_report
#: model:ir.model.fields,field_description:mail_template_multi_report.field_mail_template_report_line_create_uid
msgid "Created by"
msgstr "Créé par "
#. module: mail_template_multi_report
#: model:ir.model.fields,field_description:mail_template_multi_report.field_mail_template_report_line_create_date
msgid "Created on"
msgstr "Créé le"
#. module: mail_template_multi_report
#: model:ir.model.fields,field_description:mail_template_multi_report.field_mail_template_report_line_display_name
msgid "Display Name"
msgstr "Nom affiché"
#. module: mail_template_multi_report
#: model:ir.model.fields,field_description:mail_template_multi_report.field_mail_template_report_line_template_id
msgid "Email Template"
msgstr "Modèle de courriel"
#. module: mail_template_multi_report
#: model:ir.model,name:mail_template_multi_report.model_mail_template
msgid "Email Templates"
msgstr "Modèles de courriel"
#. module: mail_template_multi_report
#: model:ir.model.fields,field_description:mail_template_multi_report.field_mail_template_report_line_id
msgid "ID"
msgstr "ID"
#. module: mail_template_multi_report
#: model:ir.model.fields,field_description:mail_template_multi_report.field_mail_template_report_line___last_update
msgid "Last Modified on"
msgstr "Modifié le"
#. module: mail_template_multi_report
#: model:ir.model.fields,field_description:mail_template_multi_report.field_mail_template_report_line_write_uid
msgid "Last Updated by"
msgstr "Dernière mise à jour par"
#. module: mail_template_multi_report
#: model:ir.model.fields,field_description:mail_template_multi_report.field_mail_template_report_line_write_date
msgid "Last Updated on"
msgstr "Dernière mise à jour le"
#. module: mail_template_multi_report
#: model:ir.model,name:mail_template_multi_report.model_mail_template_report_line
msgid "Mail Template Report Line"
msgstr "Ligne de rapport de modèle de courriel"
#. module: mail_template_multi_report
#: model:ir.model.fields,help:mail_template_multi_report.field_mail_template_report_line_report_name
msgid "Name to use for the generated report file (may contain placeholders)\n"
"The extension can be omitted and will then come from the report type."
msgstr "Nom à utiliser pour le fichier de rapport généré (peut contenir des variables)\n"
"L'extension peut être omise: celle du rapport sera utilisée."
#. module: mail_template_multi_report
#: model:ir.model.fields,field_description:mail_template_multi_report.field_mail_template_report_line_report_template_id
msgid "Optional report to print and attach"
msgstr "Rapport facultatif à imprimer et à joindre"
#. module: mail_template_multi_report
#: model:ir.model.fields,field_description:mail_template_multi_report.field_email_template_preview_report_line_ids
#: model:ir.model.fields,field_description:mail_template_multi_report.field_mail_template_report_line_ids
msgid "Other Reports"
msgstr "Autres rapports"
#. module: mail_template_multi_report
#: model:ir.model.fields,field_description:mail_template_multi_report.field_mail_template_report_line_report_name
msgid "Report Filename"
msgstr "Nom du fichier du rapport"

6
mail_template_multi_report/models/__init__.py

@ -0,0 +1,6 @@
# -*- coding: utf-8 -*-
# © 2016 Savoir-faire Linux
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from . import mail_template
from . import mail_template_report_line

62
mail_template_multi_report/models/mail_template.py

@ -0,0 +1,62 @@
# -*- coding: utf-8 -*-
# © 2016 Savoir-faire Linux
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
import base64
from odoo import api, fields, models
from odoo.tools.safe_eval import safe_eval
class MailTemplate(models.Model):
_inherit = 'mail.template'
report_line_ids = fields.One2many(
comodel_name='mail.template.report.line',
inverse_name='template_id',
string='Other Reports'
)
@api.multi
def generate_email(self, res_ids, fields=None):
self.ensure_one()
results = super(MailTemplate, self).generate_email(
res_ids, fields=fields)
report_ext = '.pdf'
for report_line in self.report_line_ids:
records = self.env[self.model_id.model].browse(res_ids)
for rec in records:
condition = report_line.condition
if condition and condition.strip():
condition_result = self.render_template(
condition, self.model, rec.id)
if not condition_result or not safe_eval(condition_result):
continue
report_name = self.render_template(
report_line.report_name, self.model, rec.id)
report = report_line.report_template_id
report_service = report.report_name
result = self.env['report'].get_pdf(rec, report_service)
result = base64.b64encode(result)
if not report_name:
report_name = 'report.' + report_service
if not report_name.endswith(report_ext):
report_name += report_ext
results[rec.id].setdefault('attachments', [])
results[rec.id]['attachments'].append((report_name, result))
return results

40
mail_template_multi_report/models/mail_template_report_line.py

@ -0,0 +1,40 @@
# -*- coding: utf-8 -*-
# © 2016 Savoir-faire Linux
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import fields, models
class MailTemplateReportLine(models.Model):
"""Mail Template Report Line"""
_name = 'mail.template.report.line'
_description = __doc__
template_id = fields.Many2one(
comodel_name='mail.template',
string='Email Template'
)
report_name = fields.Char(
string='Report Filename',
translate=True,
help='Name to use for the generated report '
'file (may contain placeholders)\n'
'The extension can be omitted and will then come from the report type.'
)
condition = fields.Char(
string='Condition',
help='An expression evaluated to determine if the report is '
'to be attached to the email. If blank, the report will always be '
'attached.'
)
report_template_id = fields.Many2one(
comodel_name='ir.actions.report.xml',
string='Optional report to print and attach',
domain=[
('report_type', 'in', ['qweb-html', 'qweb-pdf'])
],
)

3
mail_template_multi_report/security/ir.model.access.csv

@ -0,0 +1,3 @@
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
access_mail_template_report_line,mail.template,model_mail_template_report_line,base.group_user,1,1,1,0
access_mail_template_report_line_system,mail.template system,model_mail_template_report_line,base.group_system,1,1,1,1

4
mail_template_multi_report/tests/__init__.py

@ -0,0 +1,4 @@
# -*- coding: utf-8 -*-
# © 2016 Savoir-faire Linux
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from . import test_mail_template

91
mail_template_multi_report/tests/test_mail_template.py

@ -0,0 +1,91 @@
# -*- coding: utf-8 -*-
# © 2016 Savoir-faire Linux
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo.tests import common
class TestMailTemplate(common.TransactionCase):
def setUp(self):
super(TestMailTemplate, self).setUp()
self.report_view = self.env['ir.ui.view'].create({
'name': 'test_report_template',
'mode': 'primary',
'type': 'qweb',
'arch': """\
<?xml version="1.0"?>
<t t-name="mail_template_multi_report.test_report_template">
<t t-call="report.html_container">
<t t-call="report.internal_layout">
<div class="page">
</div>
</t>
</t>
</t>
"""
})
model_data = self.env['ir.model.data'].create({
'module': 'mail_template_multi_report',
'model': 'ir.ui.view',
'name': 'test_report_template',
'res_id': self.report_view.id,
})
model_data.clear_caches()
self.report = self.env['ir.actions.report.xml'].create({
'name': 'Test Report 1',
'model': 'res.partner',
'report_type': 'qweb-html',
'report_name': 'mail_template_multi_report.test_report_template',
})
self.template = self.env['mail.template'].create({
'name': 'Test Email Template',
'model_id': self.env.ref('base.model_res_partner').id,
'report_line_ids': [(0, 0, {
'report_name': '${object.name}',
'report_template_id': self.report.id,
})]
})
self.partner = self.env['res.partner'].create({
'name': 'Test Partner',
'customer': True,
})
def test_01_generate_email(self):
res = self.template.generate_email([self.partner.id])
self.assertEquals(len(res[self.partner.id]['attachments']), 1)
def test_02_generate_email_with_standard_report(self):
self.template.write({
'report_name': '${object.name}',
'report_template': self.report.id,
})
res = self.template.generate_email([self.partner.id])
self.assertEquals(len(res[self.partner.id]['attachments']), 2)
def test_03_report_condition_true(self):
self.template.report_line_ids[0].write({
'condition': "${object.customer}",
})
res = self.template.generate_email([self.partner.id])
self.assertEquals(len(res[self.partner.id]['attachments']), 1)
def test_04_report_condition_false(self):
self.template.report_line_ids[0].write({
'condition': "${object.supplier}",
})
res = self.template.generate_email([self.partner.id])
res[self.partner.id].setdefault('attachments', [])
self.assertEquals(len(res[self.partner.id]['attachments']), 0)

21
mail_template_multi_report/views/mail_template.xml

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<odoo>
<data>
<record id="email_template_form" model="ir.ui.view">
<field name="name">email.template.form</field>
<field name="model">mail.template</field>
<field name="inherit_id" ref="mail.email_template_form"/>
<field name="arch" type="xml">
<field name="report_name" position="after">
<field name="report_line_ids">
<tree editable="bottom">
<field name="report_name"/>
<field name="report_template_id"/>
<field name="condition"/>
</tree>
</field>
</field>
</field>
</record>
</data>
</odoo>
Loading…
Cancel
Save