Hello,
I upgraded my Odoo v11's python version 2.7 to 3.6. After then I fixed broken addons but I stucked that point.
Odoo showing this report in the log file:
"Generating PDF on Windows platform require DPI >= 96. Using 96 instead."
Odoo showing this report:
Traceback (most recent call last):
File "D:\Odoo 11.0\server\odoo\http.py", line 650, in _handle_exception
return super(JsonRequest, self)._handle_exception(exception)
File "D:\Odoo 11.0\server\odoo\http.py", line 310, in _handle_exception
raise pycompat.reraise(type(exception), exception, sys.exc_info()[2])
File "D:\Odoo 11.0\server\odoo\tools\pycompat.py", line 87, in reraise
raise value
File "D:\Odoo 11.0\server\odoo\http.py", line 692, in dispatch
result = self._call_function(**self.params)
File "D:\Odoo 11.0\server\odoo\http.py", line 342, in _call_function
return checked_call(self.db, *args, **kwargs)
File "D:\Odoo 11.0\server\odoo\service\model.py", line 97, in wrapper
return f(dbname, *args, **kwargs)
File "D:\Odoo 11.0\server\odoo\http.py", line 335, in checked_call
result = self.endpoint(*a, **kw)
File "D:\Odoo 11.0\server\odoo\http.py", line 936, in __call__
return self.method(*args, **kw)
File "D:\Odoo 11.0\server\odoo\http.py", line 515, in response_wrap
response = f(*args, **kw)
File "D:\Odoo 11.0\server\odoo\addons\web\controllers\main.py", line 938, in call_button
action = self._call_kw(model, method, args, {})
File "D:\Odoo 11.0\server\odoo\addons\web\controllers\main.py", line 926, in _call_kw
return call_kw(request.env[model], method, args, kwargs)
File "D:\Odoo 11.0\server\odoo\api.py", line 689, in call_kw
return call_kw_multi(method, model, args, kwargs)
File "D:\Odoo 11.0\server\odoo\api.py", line 680, in call_kw_multi
result = method(recs, *args, **kwargs)
File "D:\Odoo 11.0\server\odoo\addons\account\models\account_invoice.py", line 780, in action_invoice_open
return to_open_invoices.invoice_validate()
File "D:\Odoo 11.0\server\addons\addons-trbase\l10n_tr_account_einvoice\models\account_invoice.py", line 259, in invoice_validate
[inv.id], 'account.report_invoice', {})
File "D:\Odoo 11.0\server\addons\addons-trbase\report_router\models\ir_actions_report.py", line 77, in render_report
res_ids, route.report_id.report_name, data)
File "D:\Odoo 11.0\server\addons\addons-trbase\report_router\models\ir_actions_report.py", line 61, in render_report
res_ids, name, data)
File "D:\Odoo 11.0\server\addons\addons-trbase\report_xslt\models\ir_actions_report_xml.py", line 48, in render_report
return self.create_xslt_report(report, res_ids, data)
File "D:\Odoo 11.0\server\addons\addons-trbase\report_xslt\models\ir_actions_report_xml.py", line 147, in create_xslt_report
pdf = self._run_wkhtmltopdf(htmls)
File "D:\Odoo 11.0\server\odoo\addons\base\ir\ir_actions_report.py", line 378, in _run_wkhtmltopdf
body_file.write(body)
TypeError: a bytes-like object is required, not 'str'
When I want to send e-invoice, it's sending but it couldn't create PDF file of that e-invoice and giving error for this.
Environment Informations:
Odoo v11
Python 3.6
an invoice provider (localized)
Here is create_xslt_report function:
def create_xslt_report(self, report, res_ids, data=None):
if data is None:
data = {}
resources = self.env[report.model].browse(
res_ids)
htmls = []
for resource in resources:
xslt = data.get('xslt', False)
if xslt:
xslt = etree.fromstring(xslt)
else:
xslt = etree.fromstring(base64.decodebytes(report.xslt))
transform = etree.XSLT(xslt)
res_xml = data.get('xml', False)
if res_xml:
parser = etree.XMLParser(recover=True)
res_etree = etree.fromstring(res_xml, parser)
else:
if getattr(resource, '_get_xml_etree', None):
res_etree = resource._get_xml_etree()
res_xml = etree.tostring(res_etree, encoding='utf8',
method='xml', pretty_print=False)
elif getattr(resource, '_get_xml_string', None):
parser = etree.XMLParser(recover=True)
res_xml = resource._get_xml_string()
res_etree = etree.fromstring(res_xml, parser)
else:
raise ValidationError(_(
'This model does not support XSLT reports'))
htmls.append(str(transform(res_etree)))
if data.get('return_htmls', False):
return htmls
# pdf = self._run_wkhtmltopdf([], [], htmls, None, paperformat,
# {}, save_in_attachment)
pdf = self._run_wkhtmltopdf(htmls)
save_in_attachment, res_ids = self.xslt_get_attachment(report, res_ids)
reportResult = report.with_context({})._post_pdf(save_in_attachment, pdf, res_ids)
save_in_attachment, res_ids = self.xslt_get_attachment(report, res_ids)
# save_in_attachments has always data in odoo v8
# in v11, it has data only when we already have attachment
if report.attach_xml and len(resources) == 1:
resource_id = resource[0].id
filename = save_in_attachment.get(resource_id)
filename = filename and filename.datas_fname or ''
if filename:
xml_filename = os.path.splitext(filename)[0] + '.xml'
pdf = self.attach_file_to_pdf(pdf, res_xml, xml_filename)
att = self.env['ir.attachment'].search(
[('res_model', '=', report.model),
('res_id', '=', resource_id),
('datas_fname', '=', filename), ], limit=1)
if att:
att.write({
'datas': base64.b64encode(pdf),
})
else:
self.env['ir.attachment'].with_context({}).create({
'res_model': report.model,
'res_id': resource_id,
'name': filename,
'datas_fname': filename,
'datas': base64.b64encode(pdf),
})
return pdf, 'pdf'
By the way these codes are working with python 2.7. I only changed decodebytes() instead of decodestring()
I hope, you'll find way to solve this problem.
yes, i solved the problem. The main error is base64 encode-decode relations. That's the reason why it's giving error. Check your decode method.