Quantcast
Channel: OpenERP Help - Individual question feed
Viewing all articles
Browse latest Browse all 6389

Sample code for Applying payment to Invoice via XML-RPC (PHP) ?

$
0
0
I am using PHP to communicate with the XML-RPC API. I have been able to successfully create and validate an invoice but I am running into a problem applying a payment to an invoice. Does anyone know how this can be done through the API? Or have a code sample I could reference? Thanks Here is the code I am using. It doesnt show the actual xml-rpc calls but it shows the fields. This is using a custom handler I wrote. echo "LOGIN

"; $conn = new openerp_client($user, $password, $dbname, $server_url); //search for company in partner model to get id echo "SEARCH

"; $data = array( 0 => array('field' => 'name', 'operator' => '=', 'value' => 'Antoni\'s Company 2', 'type' => 'string') ); $conn->search('res.partner', $data); $partner_id = $conn->response['last_record_id'][0]; //search for company in res.comapny model to get id echo "SEARCH

"; $data = array( 0 => array('field' => 'name', 'operator' => '=', 'value' => 'Antoni\'s Company 2', 'type' => 'string') ); $conn->search('res.company', $data); $company_id = $conn->response['last_record_id'][0]; //create the invoice echo "INVOICE

"; $data = array( 0 => array('field' => 'partner_id', 'value' => $partner_id, 'type' => 'int'), 1 => array('field' => 'date_invoice', 'value' => date('Y-m-d'), 'type' => 'string'), 2 => array('field' => 'date_due', 'value' => date('Y-m-d'), 'type' => 'string'), 3 => array('field' => 'account_id', 'value' => 40, 'type' => 'int'), 4 => array('field' => 'journal_id', 'value' => 11, 'type' => 'int'), 6 => array('field' => 'company_id', 'value' => $company_id, 'type' => 'int'), 7 => array('field' => 'period_id', 'value' => 4, 'type' => 'int') ); $conn->put('account.invoice', 'create', $data); $invoice_id = $conn->response['last_record_id']; //create the invoice lines echo "CREATE INVOICE LINES

"; $data = array( 0 => array('field' => 'invoice_id', 'value' => $invoice_id, 'type' => 'int'), 1 => array('field' => 'product_id', 'value' => 49, 'type' => 'int'), 2 => array('field' => 'name', 'value' => '[ADPT] USB Adapter', 'type' => 'string'), 3 => array('field' => 'price_unit', 'value' => 18.0, 'type' => 'double'), 4 => array('field' => 'quantity', 'value' => 2.0, 'type' => 'double'), 5 => array('field' => 'account_id', 'value' => 51, 'type' => 'int') ); $conn->put('account.invoice.line', 'create', $data); //validate the invoice echo "VALIDATE

"; $conn->workflow('account.invoice', 'invoice_open', $invoice_id); //get move_id from invoice echo "SEARCH INVOICE

"; $data = array( 0 => array('field' =>'id', 'operator' => '=', 'value' => $invoice_id, 'type' => 'int') ); $conn->search('account.invoice', $data); echo "GET INVOICE

"; $fields = array(); $conn->get('account.invoice', $fields); echo $move_id = $conn->response['last_record_id'][0]['move_id']->me['array'][0]->me['int']; //create voucher echo "Create

"; $data = array( 0 => array('field' => 'partner_id', 'value' => 166, 'type' => 'int'), 1 => array('field' => 'company_id', 'value' => 1, 'type' => 'int'), 2 => array('field' => 'type', 'value' => 'receipt', 'type' => 'string'), 3 => array('field' => 'account_id', 'value' => 57, 'type' => 'int'), 4 => array('field' => 'period_id', 'value' => 5, 'type' => 'int'), 5 => array('field' => 'journal_id', 'value' => 17, 'type' => 'int'), 6 => array('field' => 'amount', 'value' => 12.0, 'type' => 'double'), 7 => array('field' => 'move_id', 'value' => $move_id, 'type' => 'int'), 8 => array('field' => 'currency_id', 'value' => 1, 'type' => 'int'), 9 => array('field' => 'date', 'value' => date('Y-m-d'), 'type' => 'string') ); $conn->put('account.voucher', 'create', $data); $voucher_id = $conn->response['last_record_id']; //get move_line_id $data = array( 0 => array('field' => 'move_id', 'operator' => '=', 'value' => $move_id, 'type' => 'int'), 1 => array('field' => 'name', 'operator' => '=', 'value' => '/', 'type' => 'string') ); $conn->search('account.move.line', $data); $fields = array(); $conn->get('account.move.line', $fields); $move_line_id = $conn->response['last_record_id'][0]['id']->me['int']; $invoice_name = $conn->response['last_record_id'][0]['invoice']->me['array'][1]->me['string']; //create voucher line echo "Create Voucher Line

"; $data = array( 0 => array('field' => 'partner_id', 'value' => 166, 'type' => 'int'), 1 => array('field' => 'company_id', 'value' => 1, 'type' => 'int'), 2 => array('field' => 'voucher_id', 'value' => $voucher_id, 'type' => 'int'), 3 => array('field' => 'amount', 'value' => 12.0, 'type' => 'double'), 4 => array('field' => 'type', 'value' => 'cr', 'type' => 'string'), 5 => array('field' => 'name', 'value' => $invoice_name, 'type' => 'string'), 6 => array('field' => 'account_id', 'value' => 40, 'type' => 'int'), 7 => array('field' => 'move_line_id', 'value' => $move_line_id, 'type' => 'int') ); $conn->put('account.voucher.line','create',$data); //Post voucher echo "Post Voucher

"; $conn->workflow('account.voucher', 'proforma_voucher', $voucher_id);

Viewing all articles
Browse latest Browse all 6389

Trending Articles