How can I update the product Route_ids
routes in Odoo 12 with a query?
The selection of products I can do with the answer from this link. Odoo Make to Order Configuration for all products
Thanks Maybe with these :
models.execute_kw(db, uid, password, 'product.template', 'write', [[id], {'route_ids': [(1, a, b)]}])
What is a and b? I think that 1 it's for the update, is right?
I think that the answer is that but i'm not sure :
models.execute_kw(db, uid, password, 'product.template', 'write', [[id], {'route_ids': [(1, 915, 17)]}])
1
is for the update, 915
is the product id, and 17
is the route_id
.
The question is how can I do a list of products to update the routes? According with the answer of CZoellner maybe is
models.execute_kw(db, uid, pw, 'product.template', 'write', [[17], {'route_ids': [(6, 0, [915,916])]}])
It's Right?
Ok Ive do :
import sys
import xmlrpclib
import ssl
url = "http://localhost:8069"
db = "*******"
username = "*******"
pw = "*******"
gcontext = ssl._create_unverified_context()
# Get the uid
sock_common = xmlrpclib.ServerProxy(
"http://localhost:8069/xmlrpc/common", context=gcontext)
uid = sock_common.login(db, username, pw)
models = xmlrpclib.ServerProxy("http://localhost:8069/xmlrpc/object", context=gcontext)
models.execute_kw(
db, uid, pw, "product.template", "write", [[916], {"route_ids": [(6, 0, [17])]}]
)
It thasn't work, where is my mistake?
It's these code work with odoo 12?
There are a lot of answers about how the magic triplets for many2many fields in Odoo have to be used already. My advice for this basic question: look into the docstring of BaseModel.write()
because the answer to that is there for ages.
But for your special question: If you want to set a product route to only one route, just use the "override" triplet (6, 0, <list_of_ids_to_set>)
. If you just want to add another route to all current set routes use the "add" triplet (4, <id_of_route_to_add>, 0)
(you could leave the 0 at the end).
So if your Make2order route is for example ID 3:
models.execute_kw(db, uid, pw, 'product.template',
'write', [[template_id], {'route_ids': [(6, 0, [3])]}])
or
models.execute_kw(db, uid, pw, 'product.template',
'write', [[template_id], {'route_ids': [(4, 3,)]}])