parent
0836addc1d
commit
5c2e71839c
|
@ -8,6 +8,7 @@ import logging
|
||||||
import os
|
import os
|
||||||
import requests
|
import requests
|
||||||
import tempfile
|
import tempfile
|
||||||
|
from datetime import datetime
|
||||||
from contextlib import closing
|
from contextlib import closing
|
||||||
from openerp import _, api, models
|
from openerp import _, api, models
|
||||||
from openerp.exceptions import UserError
|
from openerp.exceptions import UserError
|
||||||
|
@ -75,16 +76,22 @@ class Py3oReport(models.TransientModel):
|
||||||
}
|
}
|
||||||
if report_xml.py3o_is_local_fusion:
|
if report_xml.py3o_is_local_fusion:
|
||||||
fields['skipfusion'] = '1'
|
fields['skipfusion'] = '1'
|
||||||
|
url = report_xml.py3o_server_id.url
|
||||||
|
logger.info(
|
||||||
|
'Connecting to %s to convert report %s to %s',
|
||||||
|
url, report_xml.report_name, filetype)
|
||||||
if filetype == 'pdf':
|
if filetype == 'pdf':
|
||||||
options = report_xml.pdf_options_id or\
|
options = report_xml.pdf_options_id or\
|
||||||
report_xml.py3o_server_id.pdf_options_id
|
report_xml.py3o_server_id.pdf_options_id
|
||||||
if options:
|
if options:
|
||||||
pdf_options_dict = options.odoo2libreoffice_options()
|
pdf_options_dict = options.odoo2libreoffice_options()
|
||||||
fields['pdf_options'] = json.dumps(pdf_options_dict)
|
fields['pdf_options'] = json.dumps(pdf_options_dict)
|
||||||
r = requests.post(
|
logger.debug('PDF Export options: %s', pdf_options_dict)
|
||||||
report_xml.py3o_server_id.url, data=fields, files=files)
|
start_chrono = datetime.now()
|
||||||
|
r = requests.post(url, data=fields, files=files)
|
||||||
if r.status_code != 200:
|
if r.status_code != 200:
|
||||||
# server says we have an issue... let's tell that to enduser
|
# server says we have an issue... let's tell that to enduser
|
||||||
|
logger.error('Py3o fusion server error: %s', r.text)
|
||||||
raise UserError(
|
raise UserError(
|
||||||
_('Fusion server error %s') % r.text,
|
_('Fusion server error %s') % r.text,
|
||||||
)
|
)
|
||||||
|
@ -93,6 +100,11 @@ class Py3oReport(models.TransientModel):
|
||||||
with open(result_path, 'w+') as fd:
|
with open(result_path, 'w+') as fd:
|
||||||
for chunk in r.iter_content(chunk_size):
|
for chunk in r.iter_content(chunk_size):
|
||||||
fd.write(chunk)
|
fd.write(chunk)
|
||||||
|
end_chrono = datetime.now()
|
||||||
|
convert_seconds = (end_chrono - start_chrono).total_seconds()
|
||||||
|
logger.info(
|
||||||
|
'Report %s converted to %s in %s seconds',
|
||||||
|
report_xml.report_name, filetype, convert_seconds)
|
||||||
if len(model_instance) == 1:
|
if len(model_instance) == 1:
|
||||||
self._postprocess_report(
|
self._postprocess_report(
|
||||||
result_path, model_instance.id, save_in_attachment)
|
result_path, model_instance.id, save_in_attachment)
|
||||||
|
|
Loading…
Reference in New Issue