Commits

Raimon Esteve (Zikzakmedia) committed 111f223

Report filename. File name expresion available in each report

Comments (0)

Files changed (6)

+* Report filename. File name expresion available in each report
 * Mimetype from filename+extension
 * Add extension report file
 * Attach file report. Default Tryton report file is base64
 from .template import *
 from .electronic_mail import *
 from .trigger import *
+from .report import *
     'xml': [
         'template.xml',
         'trigger.xml',
+        'report.xml',
     ],
     'translation': [
     ],
+#This file is part electronic_mail_template module for Tryton.
+#The COPYRIGHT file at the top level of this repository contains 
+#the full copyright notices and license terms.
+from trytond.model import ModelView, ModelSQL, fields
+
+
+class ActionReport(ModelSQL, ModelView):
+    "Action report"
+    _name = 'ir.action.report'
+
+    file_name = fields.Char('File Name Pattern', 
+        help='File name e-mail attachment without extension. eg. 2012_SO003')
+
+ActionReport()
+<?xml version="1.0"?>
+<!-- This file is part electronic_mail_template module for Tryton.
+The COPYRIGHT file at the top level of this repository contains the full copyright notices and license terms. -->
+<tryton>
+    <data>
+        <record model="ir.ui.view" id="action_report_view_form">
+            <field name="model">ir.action.report</field>
+            <field name="inherit" ref="ir.action_report_view_form"/>
+            <field name="arch" type="xml">
+                <![CDATA[
+                <data>
+                    <xpath
+                        expr="/form/notebook/page[@string=&quot;General&quot;]/field[@name=&quot;email&quot;]"
+                        position="after">
+                        <newline/>
+                        <label name="file_name"/>
+                        <field name="file_name"/>
+                    </xpath>
+                </data>
+                ]]>
+            </field>
+        </record>
+    </data>
+</tryton>
     def __init__(self):
         super(Template, self).__init__()
         self._error_messages.update({
-            'smtp_error': 'Wrong connection SMTP server. Not send email',
+            'smtp_error': 'Wrong connection to SMTP server. Email have not sent',
             })
 
     def default_engine(self):
                     template, record
                     )
                 for report in reports:
-                    ext, data, filename = report[0:4]
+                    ext, data, filename, file_name = report[0:5]
+                    if file_name:
+                        filename = self.eval(template, file_name, record)
                     filename = ext and '%s.%s' % (filename, ext) or filename
                     content_type, _ = mimetypes.guess_type(filename)
                     maintype, subtype = (
             report_type
             data
             the report name
+            the report file name (optional)
         '''
         reports = [ ]
         for report_action in template.reports:
             report = Pool().get(report_action.report_name, type='report')
-            reports.append(report.execute([record.id], {'id': record.id}))
+            reports.append([report.execute([record.id], {'id': record.id}), report_action.file_name])
 
         # The boolean for direct print in the tuple is useless for emails
-        return [(r[0], r[1], r[3]) for r in reports]
+        return [(r[0][0], r[0][1], r[0][3], r[1]) for r in reports]
 
     def render_and_send(self, template_id, record_ids):
         """