Skip to Content
Menu
This question has been flagged
7 Replies
5352 Views

I have a custom module that does some stuff including generating some reports in PDF. I've created a cron job to run this periodically. If I select "Run Manually", everything works as expected and my reports look great. If however the job executes via schedule, the PDF loses it's header, footer and styling.

I've done a lot of searching, but other people that are having problems are having problems regardless of how the report is executed. My problem is only when the report is executed via a cron job.

Is there something I'm missing on permissions perhaps? What could be different between the execution methods, manually through the UI versus scheduled?

I'm on Odoo 9 and wkhtmltopdf 12.3.2 (with patched qt) on Windows 8.1 as my dev machine. The problem also occurs on Ubuntu 14.04, Odoo 9, wkhtmltopdf 12.2.1 (with patched qt).

Avatar
Discard
Best Answer

Hi,

As first suggestion try to downgrade the wkhtmltopdf to 12.1 and try again, and let us see if there any changes ?

 

Avatar
Discard

This is most likely the issue. Wkhtmltopdf 12.2.x is not officially supported for Odoo.

Author

I've now tried 12.1.2 and the problem persists. Any other ideas? It's strange that it's only when scheduled. Could current directory or permissions be an issue?

Best Answer

Although reported as Resolved, I believe it's not.

I'm suffering the same error while debugging I found inside function _run_wkhtmltopdf in file report.py there's a try - catch statement which checks for request and passes the session id as cookie argument for wkhtmltopdf with this value wkhtmltopdf has access to the CSS files which otherwise are behind Odoo.

I wonder if there's a way to generated the html file with the CSS files inside it so wkhtmltopdf doesn't need a session in order to read these files.

Code in report.py:

try:
if request:
command_args.extend(['--cookie', 'session_id', request.session.sid])
except AttributeError:
pass

 


Avatar
Discard

I did finally get it working. It would appear that the process calling wkhtmltopdf isn't given the context it needs; ie; it doesn't know which database to use.

This is further complicated by the face that db-filter doesn't appear to work in the config file.

I ended up getting it working by calling python using the parameter; --db-filter=^database_name$

The ^ and $ ensure that the regex doesn't return anything other than the exact string.

I hope this fixes it for you.

Thank you, that worked!

Best Answer

I have a similar issue and i have tried all the suggestion without success. I am working with v-10. please let me know any other possible solutions thanks 


Avatar
Discard
Best Answer

is this problem fixed? i have same problem too. change wkhtmltopdf version to 12.1 is not solve the problem.

Avatar
Discard
Best Answer

Hi Michael

Follow these steps

- install wkhtmltopdf (0.12.1)

- define the system parameter report.url with the value http://0.0.0.0:[port] (the port here is the xmlrpc_port of your odoo instance)

- restart odoo

This should work

Avatar
Discard
Related Posts Replies Views Activity
1
Feb 24
1813
1
Sep 19
6358
0
Oct 24
117
2
Jul 24
2925
1
May 24
733