Hi,
To add product attributes and variants using the Odoo
XML-RPC API, you need to understand the structure of the product
attributes and variants in Odoo.
Here's how you can build the query to add a product with attributes and variants:
1.
First, you need to create product attributes and attribute values if
they don't exist. Then, you can link them to the product.
2. Create a product template and link the product attributes to it.
3. Create product variants based on the product template.
Here's a step-by-step guide on how to achieve this:# Define your product attributes and their values
attribute_values = [(0, 0, {'name': 'White'})] # Adjust this according to your attribute values
# Create product attributes if they don't exist
attribute_id = models.execute_kw(db, uid, password, 'product.attribute', 'create', [{'name': 'Color'}])
# Create attribute values if they don't exist
attribute_value_ids = models.execute_kw(db, uid, password, 'product.attribute.value', 'create', attribute_values)
# Create a product template and link the product attributes to it
product_template_id = models.execute_kw(db, uid, password, 'product.template', 'create', [{
'name': 'Green Ball',
'attribute_line_ids': [(0, 0, {'attribute_id': attribute_id, 'value_ids': [(6, 0, attribute_value_ids)]})]
}])
# Create product variants based on the product template
product_variant_id = models.execute_kw(db, uid, password, 'product.product', 'create', [{
'name': 'Green Ball - White',
'product_tmpl_id': product_template_id,
'attribute_value_ids': [(6, 0, attribute_value_ids)]
}])
Hope it helps
Did you ever get an answer or figure this out because the documentation regarding this is nonexistent or wrong everywhere I look
It's difficult to understand underlying architecture of oddo External API. I found documentation insufficient.