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:The above doesn't properly return the PDF data. The response comes back with a status of zero.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);
});
});
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