Download report PDF ODO 13 API External

Viewed 349

I've been hitting my head against a wall since a week ago. I am working with Odoo 13 and with the external API that it offers for java using XMLRPC client, as they teach in their documentation.

My goal is to obtain a report PDF for an invoice. Researching in the documentation and in other forums, I have found that I have to use the "render_qweb_pdf" function of the ir.actions.report model. This function returns me what the PDF data would be once obtained, and then I would parse them with this data and obtain the PDF, or I could also create an attachment and access it.

This is an example of my goal in python and the code

pdf = self.env.ref('account.account_invoices').sudo().render_qweb_pdf([self.id])[0]
self.env['ir.attachment'].create({
    'name': self.number + ".pdf",
    'type': 'binary',
    'res_id': self.id,
    'res_model': 'account.invoice',
    'datas': base64.b64encode(pdf),
    'mimetype': 'application/x-pdf',
    'datas_fname': self.number + ".pdf"
})

My first problem comes when I execute that function in java, following the models that I need and the data to pass the function, which is the following:

models.execute("execute_kw", Arrays.asList(
                db, uid, password,
                "ir.actions.report", "render_qweb_pdf",
                Arrays.asList(id, res_ids)
            ));

Integer idAttach = (Integer)models.execute("execute_kw", Arrays.asList(
                   db, uid, password, "ir.attachment", "create",
                    Arrays.asList(new HashMap() {{
                            put("name", saved_invoice.get("display_name"));
                            put("type", "binary");
                            put("datas", "/*Response of the function render_qweb_pdf*/");
                            put("store_fname", saved_invoice.get("display_name"));
                            put("res_model", "account.move");
                            put("res_id", saved_invoice.get("id"));
                            put("mimetype", "application/x-pdf");
                    }})
        ));

And the response of "render_qweb_pdf" is :

Failed to parse server's response: An invalid XML character (Unicode: 0x10) was found in the element content of the document

I don't know why it is because it is more a problem with the Odoo Server or XMLRPClient in java that does not accept the encoding of the response.

        final XmlRpcClient models = new XmlRpcClient() {{
            setConfig(new XmlRpcClientConfigImpl() {{
                setServerURL(new URL(String.format("%sxmlrpc/2/object", url)));
                setBasicEncoding(Charsets.UTF_8.name());
                setEncoding(Charsets.UTF_8.name());
                setEnabledForExceptions(true);
                setEnabledForExtensions(true);
            }});
        }};

I have tried to change the encoding when creating the client and there has been no way to solve it. It's possible that I am doing something wrong when making the request, but I no longer know what to do. I have also tried to make the request directly against the server, but I need a token that the user does not provide me.

Could someone tell me what to do? Greetings and thank you.

0 Answers
Related