Перейти к содержимому
Меню
Чтобы взаимодействовать с сообществом, необходимо зарегистрироваться.
Этот вопрос был отмечен
2 Ответы
3368 Представления

Hello,


I am trying to create products in Odoo using the API (XML-RPC). While I am able to successfully create a product and its various parameters in Odoo, I am still not able to map a product attribute-value pair to a product.


I am writing the code in Python language. 


Below is the code:


import xmlrpc.client
from itertools import product

url = "************"
db = "************"
username = '***************'
password = "***************"

common = xmlrpc.client.ServerProxy('{}/xmlrpc/2/common'.format(url))

print(common.version())

uid = common.authenticate(db, username, password, {})

models = xmlrpc.client.ServerProxy('{}/xmlrpc/2/object'.format(url))

id = models.execute_kw(db, uid, password, 'product.template', 'create', [{
'name': "Attribute Testing123",
'default_code': "Attribute Test 123",
'active': "TRUE",
'display_name': 'My New Product Testing',
'detailed_type': 'product',
'list_price': '89962',
'image_1920':'https://adamimages.sbdinc.com/GEM/Dewalt/1000x1000_72r/DCD785M2_1.jpg'
'categ_id': "25",
'attribute_id': "29939"
'value_ids': [(6,0,[])]
}])

Please can someone provide with the correct solution?

Аватар
Отменить
Лучший ответ

Look at the Odoo Log File while creating via the User Interface and you will see each of the API calls.

See https://www.odoo.com/forum/help-1/how-can-i-see-which-api-calls-are-made-to-learn-what-odoo-is-doing-at-specific-times-183911

Аватар
Отменить
Лучший ответ

Hello ,Prashant Prakash

Here map of a product attribute-value pair to a product.

Find Code in Comment. 

Thanks & Regards,
Email: odoo@aktivsoftware.com
Skype: kalpeshmaheshwari

Аватар
Отменить

models.execute_kw(db, uid, password, 'product.template.attribute.line', 'create', [{
'attribute_id' : 1, #here pass the static product attribute id
'value_ids' : [(6, 0, [1,2])], # here pass on the list of product attribute value ids
'product_tmpl_id' : id, # here pass on the created product id
}])

Hello Jainesh Shah,
Can you please explain 'value_ids' ? How to figure out values of product attributes for a specific product?