Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to print from odoo/openERP via XML-RPC

Has anybody used openERP/ odoo for printing invoices via XML-RPC. I've been trying to create an xml rpc method for printing with no success.

 function printInvoice($values,$model){

        $print = new xmlrpc_client($this->server."report");
        $print->return_type = 'phpvals';

        foreach($values as $k=>$v){
            $nval[$k] = new xmlrpcval( $v, xmlrpc_get_type($v) );
        }

        $msg = new xmlrpcmsg('report');

        $msg->addParam(new xmlrpcval($this->database, "string")); 
        $msg->addParam(new xmlrpcval($this->uid, "int")); 
        $msg->addParam(new xmlrpcval($this->password, "string"));
        $msg->addParam(new xmlrpcval($model, "string"));
        $msg->addParam(new xmlrpcval("report", "string"));
        $msg->addParam(new xmlrpcval(87, "int"));
        $msg->addParam(new xmlrpcval($nval,"struct"));

        $resp = $print->send($msg);



        if ($resp->faultCode())
            return $resp->faultString(); 
        else
            return $resp->value();  

    } 

this is the code that I have so far, first of all i want to generate a report and then print it.

like image 850
Rinor Dreshaj Avatar asked Nov 29 '25 23:11

Rinor Dreshaj


1 Answers

I figured it out a simple way to do it, you just pass the id of invoice or order in the links and this dynamically creates a pdf for the report, or instead of the pdf you can use 'html' which generates an html ready for print for the invoice like this:

http://serverurl:port/report/html/account.report_invoice/(id of invoice);

Here is the code if it helps someone.

function printInvoice($id,$type){


            if($type == 'invoice')
            {
                return "http://serverurl:port/report/pdf/account.report_invoice/".$id;
            }
            else if($type == 'order')
            {
                return "http://serverurl:port/report/pdf/sale.report_saleorder/".$id;
            }
            else
            {
                return false;
            }
        }
like image 66
Rinor Dreshaj Avatar answered Dec 02 '25 04:12

Rinor Dreshaj



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!