Search code examples
postgresqlodooxml-rpcopenerp-8

How to update the values of `route_ids` through Web API in the `product.template` in Odoo/OpenERP 8?


After connecting to the server using xmlrpc and following the instructions from here, I try to change the value of the route_ids (Procurement -> Supply Chain Information -> Routes) so none of the three options (Manufacture, Buy, Make To Order) is selected.

First I take the current values:

>>> models.execute_kw(db, uid, password,
...     'product.template', 'read',
...     [125], {'fields': ['route_ids']})
{'route_ids': [5, 6, 1], 'id': 125}

Then I attempt to update the values:

>>> models.execute_kw(db, uid, password, 'product.template', 'write', 
...     [[125], {'route_ids': []}])    
True

And finally I check whether the values have been updated or not:

>>> models.execute_kw(db, uid, password,
...     'product.template', 'read',
...     [125], {'fields': ['route_ids']})
{'route_ids': [5, 6, 1], 'id': 125}

Any idea why this does not work? I got the same results, i.e. no change, when I tried to change the display_name but when I tried to change the weight_net everything works fine. Any ideas?


Solution

  • If you had a look at the documentation about the write method here, you would understand why it is not working. Actually the page you gave does reference it explicitly, there.

    So I think that the problem you're having is that you are trying to empty the route_ids, assigning to it an empty list.

    The documentation states:

    One2many and Many2many use a special “commands” format to manipulate the set of records stored in/associated with the field.

    This format is a list of triplets executed sequentially, where each triplet is a command to execute on the set of records. Not all commands apply in all situations.

    The one we are interested in to delete the records:

    (5, _, _)

    removes all records from the set, equivalent to using the command 3 on every record explicitly. Can not be used on One2many. Can not be used in create().

    So I think you should write instead:

    >>> models.execute_kw(db, uid, password, 'product.template', 
                            'write', [[125], {'route_ids': [[5, 0, 0]]}])    
    True
    

    Hope it helped.