我正在尝试使用基于XML-RPC的Odoo Web Service API(通过PHP)在Odoo上创建发票,使用official API documentation中的代码示例。我已成功使用documentation中提供的代码创建客户:
$id = $models->execute_kw($db, $uid, $password,
'res.partner', 'create',
array(array('name'=>"New Partner"))
);
但我无法使用提供的代码示例创建发票:
$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")))
)));
当我运行代码时,我收到错误响应:
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)
"
}
虽然如果我将此行更改为空数组,它会创建发票:
'invoice_line_ids' => array(array(0, false, array('name' => "AAA")))
但后来我不知道如何添加发票行。
答案 0 :(得分:1)
对于发票行(account.invoice.line),有许多必填字段,如姓名(描述),数量等。在您的示例中,您只传递了名称。
尝试传递所有必填字段。