Ir al contenido
Menú
Se marcó esta pregunta
2 Respuestas
5705 Vistas

Hello all


What is the best way to get a pdf report with XML RPC from Odoo Version 16? Before Version 11 it was possible with the /report endpoint. How should this be done with the newer versions?

Thank you! Best regards

Avatar
Descartar
Autor

Dear Shubham

Thanks for your answer. Unfortunately this does not work, I get the following error:


Traceback (most recent call last):

  File "test3.py", line 19, in

    report_data = report.render_report(db, uid, password, report_name, doc_ids, context)

  File "/usr/lib/python3.5/xmlrpc/client.py", line 1092, in __call__

    return self.__send(self.__name, args)

  File "/usr/lib/python3.5/xmlrpc/client.py", line 1432, in __request

    verbose=self.__verbose

  File "/usr/lib/python3.5/xmlrpc/client.py", line 1134, in request

    return self.single_request(host, handler, request_body, verbose)

  File "/usr/lib/python3.5/xmlrpc/client.py", line 1167, in single_request

    dict(resp.getheaders())

xmlrpc.client.ProtocolError: ProtocolError for URL/RPC2: 404 NOT FOUND




Mejor respuesta

Here's how you can generate a PDF report using XML-RPC in Odoo version 16:

  1. Connect to your Odoo instance using an XML-RPC client library in your preferred programming language (e.g., Python with the xmlrpc.client module).

  2. Call the render_report method on the report object. This method takes the following parameters:

    • database: The name of the target database.
    • uid: The ID of the user in Odoo (typically the admin user).
    • password: The password of the user.
    • report_name: The technical name of the report to generate.
    • doc_ids: The list of document IDs to include in the report.
    • context: Additional context to provide for report generation.

    The render_report method returns a dictionary containing the report data.

  3. Use the received report data to save the PDF report file locally or process it further according to your requirements.

Example:

import xmlrpc.client

# Connect to Odoo instance
url = 'http://your_odoo_instance_url/xmlrpc/2/object'
db = 'your_database'
username = 'your_username'
password = 'your_password'
common = xmlrpc.client.ServerProxy('{}/common'.format(url))
uid = common.authenticate(db, username, password, {})

# Generate PDF report
report = xmlrpc.client.ServerProxy(url)
report_name = 'module_name.report_name' # Technical name of the report
doc_ids = [1, 2, 3] # IDs of the documents to include in the report
context = {} # Additional context for report generation
report_data = report.render_report(db, uid, password, report_name, doc_ids, context)

# Save the PDF report locally
with open('report.pdf', 'wb') as f:
f.write(report_data['result'])

Make sure to replace 'your_odoo_instance_url', 'your_database', 'your_username', 'your_password', 'module_name.report_name', and [1, 2, 3] with the appropriate values for your Odoo instance and report.

Avatar
Descartar

getting error

xmlrpc.client.Fault: <Fault 1: 'Traceback (most recent call last):\n File "/mnt/c/Others/odoo16/odoo/addons/base/controllers/rpc.py", line 150, in xmlrpc_2\n response = self._xmlrpc(service)\n File "/mnt/c/Others/odoo16/odoo/addons/base/controllers/rpc.py", line 130, in _xmlrpc\n result = dispatch_rpc(service, method, params)\n File "/mnt/c/Others/odoo16/odoo/http.py", line 366, in dispatch_rpc\n return dispatch(method, params)\n File "/mnt/c/Others/odoo16/odoo/service/model.py", line 39, in dispatch\n raise NameError("Method not available %s" % method)\nNameError: Method not available render_report\n'>