Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

How to update the values of "route_ids" through Web API in the "product.template"?

By
George Kyriakou
on 2/17/15, 5:52 PM 1,016 views

After connecting to the server using "xmlrpc" and following the instructions from here (https://www.odoo.com/documentation/8.0/api_integration.html), 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?

0
George Kyriakou
On 4/13/15, 6:32 PM

Ok, so the answer is actually heavily dependent on the documentation and has to do with the special way the many2many relationships are managed: https://www.odoo.com/documentation/8.0/reference/orm.html#openerp.models.Model.write

So in order to delete all the routes you have to do:

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

And in order to add a route (e.g. with route id '1'):

models.execute_kw(db, uid, password, 'product.template', 'write', [[id], {'route_ids': [(4, 1, 0)]}])

0

Pascal Tremblay

--Pascal Tremblay--
1312
| 5 2 7
Alma, Canada
--Pascal Tremblay--


Pascal Tremblay
On 4/8/15, 1:06 PM

With a XML file :


<record id="stock_lapagept.warehouse_pt" model="stock.warehouse">

<field name="name">La Page PT - PT2warehouse</field>

<field name="code">WHPT</field>

<field name="partner_id" ref="partners_lapagept.partner_pt" />

<field name="company_id" ref="partners_lapagept.company_pt" />

<field name="view_location_id" ref="stock_lapagept.warehouse_loc_pt" />

<field name="wh_input_stock_loc_id" ref="stock_lapagept.input_loc_pt" />

<field name="wh_output_stock_loc_id" ref="stock_lapagept.output_loc_pt" />

<field name="lot_stock_id" ref="stock_lapagept.etagere_sous_sol_pt" />

<field name="route_ids" eval="[ (6, 0, [ref('stock_lapagept.make_to_order_route_pt'), ref('stock_lapagept.drop_shipping_route_pt') , ref('stock_lapagept.buy_from_supplier_route_pt'), ref('stock_lapagept.receipt_in_1_step_route_pt'), ref('stock_lapagept.ship_to_customer_route_pt') ] ) ]" />

</record>

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

2 follower(s)

Stats

Asked: 2/17/15, 5:52 PM
Seen: 1016 times
Last updated: 4/13/15, 6:33 PM