Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
7 Trả lời
6029 Lượt xem

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

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

Hi,

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

 

Ảnh đại diện
Huỷ bỏ

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

Tác giả

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?

Câu trả lời hay nhất

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

 


Ảnh đại diện
Huỷ bỏ

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!

Câu trả lời hay nhất

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 


Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 2 24
2702
1
thg 9 19
7347
1
thg 5 25
1089
1
thg 4 25
1920
0
thg 3 25
1314