Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

How do I get a PDF of an Invoice via PHP?

By
Yaidel Ferrales
on 5/18/16, 5:18 PM 504 views

I'm trying to get an invoice in it's pdf version , but the example en the docs only guide me to this result:

array (size=2)
  'faultCode' => int 2
  'faultString' => string 'None' (length=4)

I've been trying to find what the faultCode 2 means but no luck at all. Can you provide me any working example or documentation? I'm using this source code:

<?php

require_once('ripcord.php');

$url = "http://xxx.viennaresidence.com";

$db = "odoo.yaidel";

$username = "development@worldwideresidence.com";

$password = "xxx";

$common = ripcord::client("$url/xmlrpc/2/common");

$uid = $common->authenticate($db, $username, $password, array());

$models = ripcord::client("$url/xmlrpc/2/object");

$invoice_ids = $models->execute_kw(

$db, $uid, $password,

'account.invoice', 'search',

array(

array(

array(

'type',

'=',

'out_invoice'

),

array(

'state',

'=',

'open'

)

)

)

);

/*

var_dump($models->execute_kw(

$db, $uid, $password,

'ir.actions.report.xml', 'fields_get',

array(),

array('attributes' => array('string', 'help', 'type'))

));

*/

echo "<b>Invoices Opened</b>";

var_dump($invoice_ids);

$report = ripcord::client("$url/xmlrpc/2/report");

/*

echo "<b>Report XMLRPC Object</b>";

var_dump ($report);

*/

$result = $report->render_report(

$db, $uid, $password,

'account.report_invoice', 8);

/*

echo "<b>Report XMLRPC Object after Call</b>";

var_dump ($report);

*/

echo "<b>Result of calling the Render Report</b>";

if (isset($result['faultCode'])) {

var_dump($result);

} else {

$report_data = base64_decode($result['result']);

}

?>

Thanks in advance.

1

Jérémy Kersten (jke)

--Jérémy Kersten (jke)--
2993
| 3 2 5
Jodoigne, Belgium
--Jérémy Kersten (jke)--

Jérémy is a member of the core R&D team since september 2013. He developed several projects for OpenERP version 8 including the eCommerce, the Google Calendar synchronization and the new product variants/configurator. Now, he manages Odoo website and themes for saas.

Jérémy Kersten (jke)
On 5/20/16, 5:49 AM

Hello, I have just tested on 9.0 and master and it works without any problem.


Could you check your log to see the tracebackthat is raised... ?


Here my test on runbot.


<?php
    // V9
$url = "http://148681-9-0-7f9942-all.runbot8.odoo.com";
$db = "148681-9-0-7f9942-all";

// master
$url = "http://148647-master-6a4306-all.runbot9.odoo.com";
$db = "148647-master-6a4306-all";

$username = "admin";
$password = "admin";

require_once('ripcord.php');
$common = ripcord::client("$url/xmlrpc/2/common");
$uid = $common->authenticate($db, $username, $password, array());
$models = ripcord::client("$url/xmlrpc/2/object");
$invoice_ids = $models->execute_kw($db, $uid, $password, 'account.invoice', 'search', array(
array(
array('type', '=', 'out_invoice'),
array('state', '=', 'open')
)
));
$report = ripcord::client("$url/xmlrpc/2/report");
$result = $report->render_report($db, $uid, $password, 'account.report_invoice', array($invoice_ids[0]));
$report_data = base64_decode($result['result']);
header('Content-Type: application/pdf');
echo $report_data;
?> 

UPDATE MY PREVIOUS ANSWER

After some investigations in your database, it appears that you customize the report invoice and delete the default one. So 'account.report_invoice' doesn't exists anymore and has been replaced by report 'customized_invoice.invoice_report'.

You probably have some tracebacks in your log with msg like "ValueError: "Required report does not exist: account.report_invoice" "  :)

So just replace:

$result = $report->render_report($db, $uid, $password, 'account.report_invoice', array($invoice_ids[0]));

by

$result = $report->render_report($db, $uid, $password, 'customized_invoice.invoice_report', array($invoice_ids[0]));

And it should work... like a charm


0
Yaidel Ferrales
On 5/21/16, 12:57 AM

Thanks, for the reply. Just as you said, the problem was the template. I changed the account.invoice and I got my first PDF. So once again thank you.

Hello Seems that I forgot to post my last answer :( But after some investigations, I found the error ... You have renamed the default report 'account.report_invoice' by customized_invoice.xxx! So the error was because it doesn't find the report name !

Jérémy Kersten (jke)
on 5/21/16, 2:20 AM

I find it... So I have uptaded the previous answer. Have fun with Odoo !

Jérémy Kersten (jke)
on 5/21/16, 2:58 AM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

2 follower(s)

Stats

Asked: 5/18/16, 5:18 PM
Seen: 504 times
Last updated: 5/21/16, 12:57 AM