|
|
@ -9,6 +9,8 @@ from openerp.osv.osv import except_osv |
|
|
|
from py3o.template import Template |
|
|
|
|
|
|
|
import requests |
|
|
|
from collections import defaultdict |
|
|
|
import json |
|
|
|
|
|
|
|
|
|
|
|
class py3o_report(report_sxw): |
|
|
@ -16,8 +18,8 @@ class py3o_report(report_sxw): |
|
|
|
# super(py3o_report, self).__init__(name, table) |
|
|
|
|
|
|
|
def get_values(self, cr, uid, ids, data, context): |
|
|
|
''' Override this function to customize the dictionary given to the |
|
|
|
py3o.template renderer. ''' |
|
|
|
""" Override this function to customize the dictionary given to the |
|
|
|
py3o.template renderer. """ |
|
|
|
|
|
|
|
return { |
|
|
|
'lang': self.get_lang(cr, uid, context), |
|
|
@ -36,8 +38,8 @@ class py3o_report(report_sxw): |
|
|
|
return lang_obj.browse(cr, uid, lang, context=context) |
|
|
|
|
|
|
|
def format_date(self, date, values): |
|
|
|
''' Return a date formatted according to the language extracted from |
|
|
|
the "values" argument (which should be the result of get_values). ''' |
|
|
|
""" Return a date formatted according to the language extracted from |
|
|
|
the "values" argument (which should be the result of get_values). """ |
|
|
|
return date.strftime(values['lang'].date_format) |
|
|
|
|
|
|
|
def create(self, cr, uid, ids, data, context=None): |
|
|
@ -58,22 +60,19 @@ class py3o_report(report_sxw): |
|
|
|
filetype = report_xml.py3o_fusion_filetype |
|
|
|
|
|
|
|
# py3o.template operates on filenames so create temporary files. |
|
|
|
with NamedTemporaryFile(suffix='.odt', prefix='py3o-template-') as \ |
|
|
|
in_temp, \ |
|
|
|
NamedTemporaryFile(suffix='.odt', prefix='py3o-report-') as \ |
|
|
|
out_temp: |
|
|
|
with NamedTemporaryFile(suffix='.odt', prefix='py3o-template-') as in_temp: |
|
|
|
|
|
|
|
in_temp.write(b64decode(template.py3o_template_data)) |
|
|
|
in_temp.flush() |
|
|
|
in_temp.seek(0) |
|
|
|
|
|
|
|
template = Template(in_temp.name, out_temp.name) |
|
|
|
template = Template(in_temp.name, None) |
|
|
|
|
|
|
|
template.render(self.get_values(cr, uid, ids, data, context)) |
|
|
|
|
|
|
|
out_temp.seek(0) |
|
|
|
user_instruction_mapping = template.get_user_instructions_mapping() |
|
|
|
values = user_instruction_mapping.jsonify( |
|
|
|
self.get_values(cr, uid, ids, data, context) |
|
|
|
) |
|
|
|
|
|
|
|
if filetype.human_ext != 'odt': |
|
|
|
# Now we ask fusion server to convert our template |
|
|
|
fusion_server_obj = pool['py3o.server'] |
|
|
|
fusion_server_id = fusion_server_obj.search( |
|
|
|
cr, uid, [], context=context |
|
|
@ -82,13 +81,12 @@ class py3o_report(report_sxw): |
|
|
|
cr, uid, fusion_server_id, context=context |
|
|
|
) |
|
|
|
files = { |
|
|
|
'tmpl_file': out_temp, |
|
|
|
'tmpl_file': in_temp, |
|
|
|
} |
|
|
|
fields = { |
|
|
|
"targetformat": filetype.fusion_ext, |
|
|
|
"datadict": "{}", |
|
|
|
"datadict": values, |
|
|
|
"image_mapping": "{}", |
|
|
|
"skipfusion": True, |
|
|
|
} |
|
|
|
r = requests.post(fusion_server.url, data=fields, files=files) |
|
|
|
chunk_size = 1024 |
|
|
@ -99,7 +97,3 @@ class py3o_report(report_sxw): |
|
|
|
fd.write(chunk) |
|
|
|
fd.seek(0) |
|
|
|
return fd.read(), filetype.human_ext |
|
|
|
|
|
|
|
return out_temp.read(), 'odt' |
|
|
|
|
|
|
|
return False, False |