跳至内容
菜单
此问题已终结
7 回复
5994 查看

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).

形象
丢弃
最佳答案

Hi,

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

 

形象
丢弃

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

编写者

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?

最佳答案

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

 


形象
丢弃

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!

最佳答案

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 


形象
丢弃
最佳答案

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

形象
丢弃
最佳答案

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

形象
丢弃
相关帖文 回复 查看 活动
1
2月 24
2671
1
9月 19
7332
1
5月 25
1035
1
4月 25
1891
0
3月 25
1274