I am trying to create an invoice on Odoo using Odoo Web Service API (via PHP) which is based on XML-RPC using the code example in the official API documentation. I have succeeded to create a customer using the code provided in the documentation :
$id = $models->execute_kw($db, $uid, $password,
'res.partner', 'create',
array(array('name'=>"New Partner"))
);
But I can't create an invoice using the code sample provided:
$client = $models->execute_kw(
$db, $uid, $password,
'res.partner', 'search_read',
array(array(array('customer', '=', true))),
array(
'limit' => 1,
'fields' => array(
'property_account_receivable_id',
'property_payment_term_id',
'property_account_position_id'
)))[0];
$invoice_id = $models->execute_kw(
$db, $uid, $password,
'account.invoice', 'create', array(array(
'partner_id' => $client['id'],
'account_id' => $client['property_account_receivable_id'][0],
'invoice_line_ids' => array(array(0, false, array('name' => "AAA")))
)));
when I run the code I get an error response:
array(2) {
["faultCode"]=>
int(1)
["faultString"]=>
string(989) "Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/odoo/service/wsgi_server.py", line 56, in xmlrpc_return
result = odoo.http.dispatch_rpc(service, method, params)
File "/usr/lib/python2.7/dist-packages/odoo/http.py", line 118, in dispatch_rpc
result = dispatch(method, params)
File "/usr/lib/python2.7/dist-packages/odoo/service/model.py", line 38, in dispatch
res = fn(db, uid, *params)
File "/usr/lib/python2.7/dist-packages/odoo/service/model.py", line 157, in execute_kw
return execute(db, uid, obj, method, *args, **kw or {})
File "/usr/lib/python2.7/dist-packages/odoo/service/model.py", line 143, in wrapper
raise ValidationError(msg)
ValidationError: ('The operation cannot be completed, probably due to the following:\n- deletion: you may be trying to delete a record while other records still reference it\n- creation/update: a mandatory field is not correctly set\n\n[object with reference: price_unit - price.unit]', None)
"
}
Though it creates the invoice if I change this line into an empty array:
'invoice_line_ids' => array(array(0, false, array('name' => "AAA")))
But then I don't know how to add the invoice lines.
For invoice lines(account.invoice.line) there are many required fields like name(description), qty etc.In your example you have passed only name.
Try passing all required fields.