Using Odoo v8 local installation
I'm brand new to Odoo and XMLRP. I want to update the quantity on hand of stock using XMLRPC and PHP code, just as if I had clicked the "Apply" button on the "Update Product Quantity" dialog that is reached via, e.g. Warehouse -> Products /<Select Product>/ Inventory tab -> (Quantity on Hand)Update
After much searching, based on the view found by clicking through Settings -> User Interface -> Views -> stock.change.product.qty
as well as the example in the following post:
http://thierry-godin.developpez.com/openerp/openerp-xmlrpc-php-en/
I tried the following PHP:
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<?php
set_include_path(get_include_path() . PATH_SEPARATOR . '/home/odootst/xmlrpc/lib/');
require_once( 'xmlrpc.inc' );
require_once( 'xmlrpcs.inc' );
require_once( 'xmlrpc_wrappers.inc' );
$GLOBALS['xmlrpc_internalencoding']='UTF-8';
$user = 'admin';
$password = 'acmePass123';
$dbname = 'acme123';
$server_url = 'http://192.168.4.2:8069';
$conn = new xmlrpc_client($server_url . "/xmlrpc/common");
$conn->setSSLVerifyPeer(0);
$c_msg = new xmlrpcmsg('login');
$c_msg->addParam(new xmlrpcval($dbname, "string"));
$c_msg->addParam(new xmlrpcval($user, "string"));
$c_msg->addParam(new xmlrpcval($password, "string"));
$c_response = $conn->send($c_msg);
if ($c_response->errno != 0){
echo '<p>error : ' . $c_response->faultString() . '</p>';
}
else{
$uid = $c_response->value()->scalarval();
$values = array (
'product_id'=>new xmlrpcval(8,"int"),
'new_quantity'=>new xmlrpcval(7.0, "float"),
'location_id'=>new xmlrpcval(12,"int")
);
$client = new xmlrpc_client($server_url . "/xmlrpc/object");
$client->setSSLVerifyPeer(0);
$msg = new xmlrpcmsg('execute');
$msg->addParam(new xmlrpcval($dbname, "string"));
$msg->addParam(new xmlrpcval($uid, "int"));
$msg->addParam(new xmlrpcval($password, "string"));
$msg->addParam(new xmlrpcval("stock.change.product.qty", "string"));
$msg->addParam(new xmlrpcval("change_product_qty", "string"));
$msg->addParam(new xmlrpcval($values, "struct"));
$response = $client->send($msg);
if ($response->faultCode()){
echo $response->faultString();
} else {
echo '<h2>Update Completed Successfully</h2>';
}
}
?>
I am able to connect to the system with the above code, but I get an error trying to access the database (full traceback not shown for brevity):
ERROR acme123 openerp.sql_db: bad query: SELECT "stock_change_product_qty"."write_uid","stock_change_product_qty"."new_quantity","stock_change_product_qty"."id","stock_change_product_qty"."product_id","stock_change_product_qty"."write_date","stock_change_product_qty"."create_date","stock_change_product_qty"."create_uid","stock_change_product_qty"."location_id","stock_change_product_qty"."lot_id" FROM "stock_change_product_qty"
WHERE "stock_change_product_qty".id IN ('new_quantity', 'location_id', 'product_id') ORDER BY "stock_change_product_qty"."id"
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/openerp/sql_db.py", line 234, in execute
res = self._obj.execute(query, params)
DataError: invalid input syntax for integer: "new_quantity"
LINE 2: ... WHERE "stock_change_product_qty".id IN ('new_quant...
The error message itself is clear, but does not give me any idea where to go next. As I am only guessing at the proper calls to make in the code, I clearly have called something incorrectly. I am unsure of the following:
1) What is the correct method to call
2) What is the correct model to specify (I don't know how to find the model that is associated with a method)
3) The correct parameter list for the call
If anyone can even just point me in the right direction, that would be much appreciated. Thanks for any help you can give.
Thien, Did you ever figure this out? I'm working on a similar situation, but using straight python to import new products into a system. I'd like to bring the qty in as well, but it doesn't work when trying to update Product.product or product.template directly. I think the answer is to do a stock move, but i'm not sure.
--
Thien Nguyen