Skip to Content
Menu
This question has been flagged
1 Reply
5925 Views

So I have Odoo module where I want to retrieve a PDF report. I already figured out how to download the report the easy way with the following. Mind you I'm already using that for something is a POS module.

var link = document.createElement('a');
link.href = "http://" + window.location.host + "/report/pdf/account.report_invoice/" + res;
link.download = 'file.pdf';
link.dispatchEvent(new MouseEvent('click'));


But what I need it to get the PDF data, in base64 would be fine too. I tried a fetch request to the report url like the following:

fetch('http://10.5.1.49:8070/report/pdf/nrg_labels.report_reorder/1', {
mode: "no-cors",
redirect: "follow",
method: 'GET',
headers: {
  "Content-Type": "application/pdf",
},
}).then(function(response){
console.log("Response from fetch: ", response);
return response.blob();
}).then(function(blob){
getBase64(blob).then(function(base64){
console.log("getBase64 Response: ", base64);
startConnection({ retries: 5, delay: 1 }, base64);
});
});
The above doesn't properly return the PDF data. The response comes back with a status of zero.
I've looked around in the source code to see how they do it.

function getReport(){
rpc.query({
model: 'nrg_labels.nrg_labels',
method: 'get_report',
args: [1]
}).then(function(data){
console.log('NRG Labels PDF: ', data);
startConnection({ retries: 5, delay: 1 }, data);
});
}


I tried the above based on something I saw in the source code. I can't get it to work.

So the questions is, how can I retrieve the report PDF data, preferably in a way I can get any report?
Any help is appreciated. Thanks

Avatar
Discard
Best Answer

Hi,


You can refer this code:










_print_pdf: function(e) {
            e.preventDefault();
            var self = this;
            var action_title = self._title;
            self._rpc({
model: 'http://model.name" target="_blank">model.name',
                method: 'function_name',
                args: [
//                    [self.wizard_id]
                ],
            }).then(function(data) {
var parent = $('#o_parent_employee')[0].innerHTML
             //You can add your content, i just added some html values here
                var action = {
                    'type': 'ir.actions.report',
 
                  'report_type': 'qweb-pdf',
                    'report_name': 'modul_name.report_name',
                    'data': {'report_data': data,'parent': parent},
'context': {'active_model': 'http://model.name" target="_blank">model.name', 'landscape': 'True'},
                    'display_name': 'Display Name',
                };
                return self.do_action(action);
            });

        },



Hope it helps



Avatar
Discard
Related Posts Replies Views Activity
4
Jun 24
1404
2
Mar 24
1814
0
Mar 23
1475
0
Nov 22
2172
0
Sep 17
4578