Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Report cannot be generated in Odoo 16 #88

Open
NateLeeg96 opened this issue Jun 21, 2023 · 8 comments
Open

Report cannot be generated in Odoo 16 #88

NateLeeg96 opened this issue Jun 21, 2023 · 8 comments
Labels

Comments

@NateLeeg96
Copy link

With Odoo Version 16 reports cannot be downloaded.

Steps to reproduce the behavior:

  1. report = odoo.report.download('TEMPLATE_NAME', ID)

Traceback (most recent call last):
File "main.py", line 10, in
report = odoo.report.download('lg_reports.rechnung_qr_report_template', 1650)
File "/home/pi/.local/lib/python3.5/site-packages/odoorpc/report.py", line 133, in download
response = report.with_context(context).render(ids, data=datas)
File "/home/pi/.local/lib/python3.5/site-packages/odoorpc/models.py", line 405, in rpc_method
self._name, method, args, kwargs)
File "/home/pi/.local/lib/python3.5/site-packages/odoorpc/odoo.py", line 486, in execute_kw
'args': args_to_send})
File "/home/pi/.local/lib/python3.5/site-packages/odoorpc/odoo.py", line 285, in json
data['error'])
odoorpc.error.RPCError: type object 'ir.actions.report' has no attribute 'render'

@NateLeeg96 NateLeeg96 added the bug label Jun 21, 2023
@flotho
Copy link
Member

flotho commented Aug 11, 2023

maybe this cold be the beginning of an explanation : odoo-java/odoo-java-api#17

@sebalix
Copy link
Collaborator

sebalix commented Aug 16, 2023

In fact it's not possible anymore since Odoo 14.0.

Things are:

  • for some reasons we needed to switch on /jsonrpc endpoint (instead of /web/session/authenticate) after Odoo 10.0 to authenticate, this allows users to use API key for instance which is an important feature
  • sadly /jsonrpc endpoint doesn't generate a user's session like the web client does, so that a GET HTTP request on the homepage with OdooRPC would allow to retrieve the CSRF token
  • this CSRF token is now mandatory since Odoo >= 10.0 to print reports

So we will probably need to still call /web/session/authenticate (to get this CSRF token) to workaround this, but it's just an idea, I really don't know if we could face other caveats.

@flotho
Copy link
Member

flotho commented Aug 21, 2023

maybe we could work with access_token provided by potal_mixin : https://github.com/odoo/odoo/blob/16.0/addons/portal/models/portal_mixin.py#L15
yet this will not be applied on models not available in portal

@flotho
Copy link
Member

flotho commented Nov 2, 2023

#65

@pfranck
Copy link

pfranck commented Dec 28, 2023

Would it make sense to implement the call to the following URL /report/pdf/<report_name>/
as explained in the documentation (https://www.odoo.com/documentation/15.0/developer/reference/backend/reports.html#reports-are-web-pages)
One of the draw back would be that we need to call the API for each IDs

@flotho
Copy link
Member

flotho commented Dec 29, 2023

sure @pfranck but we still stucked on getting a proper connexion to avoid crsf issues ;-)

@em230418
Copy link

import odoorpc

# Prepare the connection to the server
odoo = odoorpc.ODOO('myserver.odoo.com', port=443, protocol='jsonrpc+ssl')

db = "dbname"
username = "admin"
password = "admin"

# Login
odoo.json("/web/session/authenticate", {"db": db, "login": username, "password": password})

r = odoo.http("/report/pdf/account.report_invoice/15781")
assert r.status == 200
with open("report.pdf", "wb") as f:
    f.write(r.read())

@flotho
Copy link
Member

flotho commented Jan 24, 2024

Great thanks to you @em230418 I'll test this ASAP

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants