Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
2 ตอบกลับ
4809 มุมมอง

I am trying to create a Product in Inventory

id = models.execute_kw(db, uid, password, 'product.product', 'create', [{'name': "Green Ball"}])

I am looking for help to add product Attribute and Variants using external api.How the query would be build?

Like: 

Attribute:Color and Values:White



อวตาร
ละทิ้ง

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.

คำตอบที่ดีที่สุด

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

อวตาร
ละทิ้ง

I think there is a mistake as for the last step, he should update (and not create) the product variants based on the product template (product variants are automatically created from product template)

คำตอบที่ดีที่สุด

You must use the model product.template.attribute.line, with relation to producs on the field product_id.


The problem you'll face, could be get the Attribute Id, cause the records are created by id, not by name. I created a method thats gets the ID from the name using the odoorpc package in python.

อวตาร
ละทิ้ง
ผู้เขียน

I am able to find support
https://www.odoo.com/forum/help-1/map-product-attribute-value-pair-using-odoo-api-201652
But 'value_ids':[(6,0,[2,4)] key-value pair is not comprehensible. Is there any support available?

Related Posts ตอบกลับ มุมมอง กิจกรรม
1
ส.ค. 25
400
1
ส.ค. 25
659
2
ก.ค. 25
3145
API xmlrpc - upload pdf bills to account แก้ไขแล้ว
3
ก.ค. 25
796
1
มิ.ย. 25
2317