Permalink
Browse files

Apply OCA coding guidelines

  • Loading branch information...
BT-kaberer committed Mar 14, 2016
1 parent f997767 commit 140a61a952e076536903ecaee1ca6866198c3ff5
@@ -18,6 +18,8 @@ class IrActionsReportXmlExt(osv.Model):
_columns = {
'is_archive': fields.boolean('Archive the File'),
'archive_attachment': fields.char('Save as File Prefix',
help='This is the filename of the report. '
'You can use a python expression with the object and time variables.')
help='This is the filename of the '
'report. You can use a python '
'expression with the object'
' and time variables.')
}
@@ -1,33 +1,36 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record id="act_report_xml_view_tree_ext" model="ir.ui.view">
<record id="act_report_xml_view_tree_ext" model="ir.ui.view">
<field name="name">ir.actions.report.xml.tree.archiving</field>
<field name="model">ir.actions.report.xml</field>
<field name="inherit_id" ref="base.act_report_xml_view_tree"/>
<field name="arch" type="xml">
<field name="attachment" position="after">
<field name="is_archive"/>
<field name="archive_attachment"/>
</field>
<field name="attachment" position="after">
<field name="is_archive"/>
<field name="archive_attachment"/>
</field>
</field>
</record>
<record id="act_report_xml_view_form_ext" model="ir.ui.view">
</record>
<record id="act_report_xml_view_form_ext" model="ir.ui.view">
<field name="name">ir.actions.report.xml.form.archiving</field>
<field name="model">ir.actions.report.xml</field>
<field name="inherit_id" ref="base.act_report_xml_view"/>
<field name="arch" type="xml">
<xpath expr="//form/notebook/page[@string='Other Configuration']/group/group[@string='Attachments']" position="after">
<group name="archive_to_file" string="Archive to File" attrs="{'invisible':[('report_type','!=','webkit')]}">
<field name="is_archive"/>
<field name="archive_attachment"/>
</group>
<xpath expr="//group[@string='Attachments']" position="after">
<group name="archive_to_file"
string="Archive to File"
attrs="{'invisible':[('report_type','!=','webkit')]}"
>
<field name="is_archive"/>
<field name="archive_attachment"/>
</group>
</xpath>
</field>
</record>
</record>
</data>
</openerp>
@@ -23,34 +23,48 @@ def __create_pdf(self, cr, uid, ids, data, context=None):
@author: brain-tec AG
"""
# creating the PDF
pdf_binary, type_of_file = old_func(self, cr, uid, ids, data, context=None)
pdf_binary, type_of_file = old_func(self, cr, uid, ids, data,
context=None)
# getting the report
report_obj = self.pool.get('ir.actions.report.xml')
report_xml_ids = report_obj.search(cr, uid, [('report_name', '=', self.name[7:])], context=context)
report_xml_ids = report_obj.search(cr, uid, [
('report_name', '=', self.name[7:])], context=context)
if report_xml_ids:
report_xml = report_obj.browse(cr, uid, report_xml_ids[0], context=context)
if report_xml.report_type == 'webkit' and report_xml.is_archive and report_xml.archive_attachment:
report_xml = report_obj.browse(cr, uid, report_xml_ids[0],
context=context)
if report_xml.report_type == 'webkit' and report_xml.is_archive \
and report_xml.archive_attachment:
# get the object to be saved
obj = self.getObjects(cr, uid, ids, context)[0]
attachment_name = safe_eval(report_xml.archive_attachment, {'object': obj, 'time': time})
attachment_name = safe_eval(report_xml.archive_attachment,
{'object': obj, 'time': time})
# get path to save the file
archive_reports_path = self.pool.get('ir.config_parameter').get_param(cr, uid,'archive_reports_path')
full_archive_pdf_path = '{path}{name}'.format(path=archive_reports_path, name=attachment_name)
archive_reports_path = self.pool.get(
'ir.config_parameter').get_param(cr, uid,
'archive_reports_path')
full_archive_pdf_path = '{path}{name}'.format(
path=archive_reports_path, name=attachment_name)
if full_archive_pdf_path:
try:
with open(full_archive_pdf_path, 'w+b') as pdf_file:
pdf_file.write(pdf_binary)
_logger.info(_('Success, saved report PDF "%s" in "%s/%s"'
% (report_xml.name, archive_reports_path, attachment_name)))
_logger.info(
_('Success, saved report PDF "%s" in "%s/%s"'
% (report_xml.name, archive_reports_path,
attachment_name)))
except Exception as e:
_logger.error(_('Failed, saving report PDF "%s" in "%s/%s": %s'
% (report_xml.name, archive_reports_path, attachment_name, e.strerror)))
_logger.error(
_('Failed, saving report PDF "%s" in "%s/%s": %s'
% (report_xml.name, archive_reports_path,
attachment_name, e.strerror)))
else:
_logger.debug(_('No path configured for report: %s' % report_xml.name))
_logger.debug(_(
'No path configured for report: %s' % report_xml.name))
return pdf_binary, type_of_file
return __create_pdf
WebKitParser.create = __new_create(WebKitParser.create)

0 comments on commit 140a61a

Please sign in to comment.