Browse Source

Restore direct rendering for native ODT output formats

--HG--
branch : odoo8
pull/80/head
Jérémie Gavrel 9 years ago
parent
commit
49defabe88
  1. 13
      models/py3o_template.py
  2. 14
      py3o_parser.py
  3. 2
      views/py3o_template.xml

13
models/py3o_template.py

@ -8,7 +8,20 @@ class py3o_template(osv.Model):
'name': fields.char( 'name': fields.char(
u"Name", u"Name",
), ),
'py3o_template_data': fields.binary( 'py3o_template_data': fields.binary(
u"LibreOffice template", u"LibreOffice template",
), ),
'filetype': fields.selection(
[
('odt', u"ODF Text Document"),
('ods', u"ODF Spreadsheet"),
],
u"LibreOffice Template File Type",
),
}
_defaults = {
'filetype': 'odt'
} }

14
py3o_parser.py

@ -154,8 +154,14 @@ class Py3oParser(report_sxw):
datadict = parser_instance.localcontext datadict = parser_instance.localcontext
res = data_struct.render(datadict)
parsed_datadict = data_struct.render(datadict)
if filetype.fusion_ext == report_xml.py3o_template_id.filetype:
# No format conversion is needed, render the template directly
template.render(parsed_datadict)
res = out_stream.getvalue()
else: # Call py3o.server to render the template in the desired format
fusion_server_obj = pool.get('py3o.server') fusion_server_obj = pool.get('py3o.server')
fusion_server_ids = fusion_server_obj.search( fusion_server_ids = fusion_server_obj.search(
cr, uid, [], context=context cr, uid, [], context=context
@ -175,7 +181,7 @@ class Py3oParser(report_sxw):
} }
fields = { fields = {
"targetformat": filetype.fusion_ext, "targetformat": filetype.fusion_ext,
"datadict": json.dumps(res),
"datadict": json.dumps(parsed_datadict),
"image_mapping": "{}", "image_mapping": "{}",
} }
r = requests.post(fusion_server.url, data=fields, files=files) r = requests.post(fusion_server.url, data=fields, files=files)
@ -197,7 +203,9 @@ class Py3oParser(report_sxw):
fd.write(chunk) fd.write(chunk)
fd.seek(0) fd.seek(0)
# ... but odoo wants the whole data in memory anyways :) # ... but odoo wants the whole data in memory anyways :)
return fd.read(), filetype.human_ext
res = fd.read()
return res, filetype.human_ext
def create(self, cr, uid, ids, data, context=None): def create(self, cr, uid, ids, data, context=None):
""" Override this function to handle our py3o report """ Override this function to handle our py3o report

2
views/py3o_template.xml

@ -9,6 +9,7 @@
<sheet> <sheet>
<group> <group>
<field name="name" /> <field name="name" />
<field name="filetype" />
<field name="py3o_template_data" /> <field name="py3o_template_data" />
</group> </group>
</sheet> </sheet>
@ -22,6 +23,7 @@
<field name="arch" type="xml"> <field name="arch" type="xml">
<tree string="Py3o Templates Configuration" version="7.0"> <tree string="Py3o Templates Configuration" version="7.0">
<field name="name" /> <field name="name" />
<field name="filetype" />
</tree> </tree>
</field> </field>
</record> </record>

Loading…
Cancel
Save