3

I am trying to update some information on my odoo product with PHP and xmlrpc. This is my code for update product name.

$models->execute_kw($db, $uid, $password, 'product.product', 'write',
    array(array(5), array('name'=>"Newer product 3",'type'=>"consu")));

Now I want to change a "Quantity On Hand" field so I trying this code :

$models->execute_kw($db, $uid, $password, 'product.product', 'write',
    array(array(5), array('name'=>"Newer product 3",'type'=>"consu",'qty_available'=>'7')));

but it doesn't work, anyone got any ideas how to fix it? Thank you.

Adreato
  • 33
  • 1
  • 5

3 Answers3

7

The field qty_available is readonly. On odoo10 you can use the following operation, python:

product = models.execute_kw(db, uid, password, 'product.product', 'search', [[('default_code', '=', sku)]])
change_id = models.execute_kw(db, uid, password, 'stock.change.product.qty', 'create', [{
                'product_id': product[0],
                'location_id': 15,
                'new_quantity': 20,
                }])

models.execute_kw(db, uid, password, 'stock.change.product.qty', 'change_product_qty', [change_id])
Flowf
  • 71
  • 1
  • 2
1

Since the field qty_available is read only there is no way to update it. To update it you'll need to create a stock move

rekobeko
  • 89
  • 10
0

First make sure that the field qty_available really exists in the model. You can check the fields in the model from (via browser)

settings --> database structure --> models

If not make sure sale, stock, product modules are properly installed. By the way in my odoo repository (i.e odoo 9 stable) I even can't see qty_available field in the model product.product . But I can see it in the openerp v7. Probably this field is either removed or the field is inheriting some other modules e.g sale_stock etc.

Hope this will solve you problem.

Hammad Qureshi
  • 1,006
  • 1
  • 11
  • 20