Browse Source

Migration to 10.0

pull/220/head
Ronny Houben 7 years ago
parent
commit
e51c4e9044
  1. 6
      mail_template_multi_report/__manifest__.py
  2. 62
      mail_template_multi_report/models/email_template.py
  3. 18
      mail_template_multi_report/models/email_template_report_line.py
  4. 4
      mail_template_multi_report/security/ir.model.access.csv
  5. 17
      mail_template_multi_report/tests/test_email_template.py
  6. 34
      mail_template_multi_report/views/email_template.xml

6
mail_template_multi_report/__openerp__.py → mail_template_multi_report/__manifest__.py

@ -4,14 +4,14 @@
{
'name': 'Email Template Multi Report',
'version': '8.0.1.0.0',
'version': '10.0.1.0.0',
'category': 'Marketing',
'summary': 'Multiple Reports in Email Templates',
'author': 'Savoir-faire Linux,Odoo Community Association (OCA)',
'author': 'Savoir-faire Linux,Apertoso NV,Odoo Community Association (OCA)',
'website': 'http://www.savoirfairelinux.com',
'license': 'AGPL-3',
'depends': [
'email_template',
'mail',
],
'data': [
'security/ir.model.access.csv',

62
mail_template_multi_report/models/email_template.py

@ -4,54 +4,70 @@
import base64
from openerp import api, fields, models
from openerp.tools.safe_eval import safe_eval
from odoo import api, fields, models
from odoo import report as odoo_report
from odoo.tools.safe_eval import safe_eval
class EmailTemplate(models.Model):
_inherit = 'email.template'
class MailTemplate(models.Model):
_inherit = 'mail.template'
report_line_ids = fields.One2many(
'email.template.report.line', 'template_id', string='Other Reports')
'mail.template.report.line', 'template_id', string='Other Reports')
@api.model
def generate_email_batch(self, template_id, res_ids, fields=None):
results = super(EmailTemplate, self).generate_email_batch(
template_id, res_ids, fields=fields)
def generate_email(self, res_ids, fields=None):
results = super(MailTemplate, self).generate_email(
res_ids, fields=fields
)
template = self.browse(template_id)
report_ext = '.pdf'
multi_mode = True
if isinstance(res_ids, (int, long)):
res_ids = [res_ids]
multi_mode = False
for report_line in template.report_line_ids:
records = self.env[template.model_id.model].browse(res_ids)
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, template.model, rec.id)
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, template.model, rec.id)
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)
if report.report_type in ['qweb-html', 'qweb-pdf']:
result, format = self.env['report'].get_pdf(
rec.ids,
report_service), 'pdf'
else:
result, format = odoo_report.render_report(
self._cr,
self._uid,
rec.ids,
report_service,
{
'model': self.model},
self._context)
# TODO in trunk, change return format to binary to match message_post expected format
result = base64.b64encode(result)
if not report_name:
report_name = 'report.' + report_service
if not report_name.endswith(report_ext):
report_name += report_ext
ext = "." + format
if not report_name.endswith(ext):
report_name += ext
results[rec.id].setdefault('attachments', [])
results[rec.id]['attachments'].append((report_name, result))
return results
return multi_mode and results or result[res_ids[0]]

18
mail_template_multi_report/models/email_template_report_line.py

@ -2,35 +2,37 @@
# © 2016 Savoir-faire Linux
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from openerp import fields, models
from odoo import fields, models
class EmailTemplateReportLine(models.Model):
class MailTemplateReportLine(models.Model):
"""Email Template Report Line"""
_name = 'email.template.report.line'
_name = 'mail.template.report.line'
_description = __doc__
template_id = fields.Many2one(
'email.template', string='Email Template'
comodel_name='mail.template',
string='Email Template'
)
report_name = fields.Char(
'Report Filename', translate=True,
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(
'Condition',
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(
'ir.actions.report.xml',
'Optional report to print and attach',
comodel_name='ir.actions.report.xml',
string='Optional report to print and attach',
domain=[('report_type', 'in', ['qweb-html', 'qweb-pdf'])],
)

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

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

17
mail_template_multi_report/tests/test_email_template.py

@ -2,7 +2,7 @@
# © 2016 Savoir-faire Linux
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from openerp.tests import common
from odoo.tests import common
class TestEmailTemplate(common.TransactionCase):
@ -43,7 +43,7 @@ class TestEmailTemplate(common.TransactionCase):
'report_name': 'mail_template_multi_report.test_report_template',
})
self.template = self.env['email.template'].create({
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, {
@ -58,9 +58,7 @@ class TestEmailTemplate(common.TransactionCase):
})
def test_01_generate_email_batch(self):
res = self.env['email.template'].generate_email_batch(
self.template.id, [self.partner.id])
res = self.template.generate_email([self.partner.id])
self.assertEquals(len(res[self.partner.id]['attachments']), 1)
def test_02_generate_email_batch_with_standard_report(self):
@ -69,8 +67,7 @@ class TestEmailTemplate(common.TransactionCase):
'report_template': self.report.id,
})
res = self.env['email.template'].generate_email_batch(
self.template.id, [self.partner.id])
res = self.template.generate_email([self.partner.id])
self.assertEquals(len(res[self.partner.id]['attachments']), 2)
@ -79,8 +76,7 @@ class TestEmailTemplate(common.TransactionCase):
'condition': "${object.customer}",
})
res = self.env['email.template'].generate_email_batch(
self.template.id, [self.partner.id])
res = self.template.generate_email([self.partner.id])
self.assertEquals(len(res[self.partner.id]['attachments']), 1)
@ -89,8 +85,7 @@ class TestEmailTemplate(common.TransactionCase):
'condition': "${object.supplier}",
})
res = self.env['email.template'].generate_email_batch(
self.template.id, [self.partner.id])
res = self.template.generate_email([self.partner.id])
res[self.partner.id].setdefault('attachments', [])
self.assertEquals(len(res[self.partner.id]['attachments']), 0)

34
mail_template_multi_report/views/email_template.xml

@ -1,21 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<openerp>
<data>
<record id="email_template_form" model="ir.ui.view">
<field name="name">email.template.form</field>
<field name="model">email.template</field>
<field name="inherit_id" ref="email_template.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>
<odoo>
<record id="email_template_form" model="ir.ui.view">
<field name="name">mail.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>
</record>
</data>
</openerp>
</field>
</record>
</odoo>
Loading…
Cancel
Save