Browse Source

Init - Print the odt template without modification (empty values)

pull/80/head
Houzefa Abbasbhay 11 years ago
commit
f768863a2e
  1. 19
      .hgignore
  2. 2
      __init__.py
  3. 22
      __openerp__.py
  4. 44
      py3o_report.py

19
.hgignore

@ -0,0 +1,19 @@
syntax: glob
**/*.pyc
*.pyc
*.swp
.tmp*
*.egg-info
dist/*
build/*
lib/*
*.orig
*.log
.settings/*
data/*
storage/*
.project
.idea
.pydevproject
*.db
.ropeproject/*

2
__init__.py

@ -0,0 +1,2 @@
import py3o_report
# import wizard

22
__openerp__.py

@ -0,0 +1,22 @@
# -*- coding: utf-8 -*-
{
'name': 'LibreOffice Report Engine',
'description': '''
Generation of LibreOffice/OpenOffice reports using LibreOffice/OpenOffice
templates.
py3o.template is used internally; install it with:
pip install py3o.template
pip install pyjon.utils
''',
'version': '0.1',
'category': 'Reporting',
'author': 'XCG Consulting',
'website': 'http://www.openerp-experts.com/',
'depends': [
'base'
],
'data': [
],
'installable': True,
}

44
py3o_report.py

@ -0,0 +1,44 @@
from tempfile import NamedTemporaryFile
from openerp import addons, pooler
from openerp.report.report_sxw import *
from openerp.tools.translate import _
from openerp.osv.osv import except_osv
from py3o.template import Template
class py3o_report(report_sxw):
# def __init__(self, name, table):
# super(py3o_report, self).__init__(name, table)
def create(self, cr, uid, ids, data, context=None):
# Find the report definition to get its settings.
pool = pooler.get_pool(cr.dbname)
report_xml_obj = pool.get('ir.actions.report.xml')
report_xml_ids = report_xml_obj.search(cr, uid,
[('report_name', '=', self.name[7:])], # Ignore "report."
context=context)
if not report_xml_ids:
return super(py3o_report, self).create(cr, uid, ids, data,
context=context)
report_xml = report_xml_obj.browse(cr, uid,
report_xml_ids[0],
context=context)
# Get the template file.
template_path = addons.get_module_resource(
*report_xml.report_file.split('/'))
# py3o.template operates on filenames so create a temporary file.
with NamedTemporaryFile(suffix='.odt', prefix='py3o-report-') as \
temp_file:
template = Template(template_path, temp_file.name)
template.render({})
temp_file.seek(0)
return temp_file.read(), 'odt'
return (False, False)
Loading…
Cancel
Save