This question has been flagged
2 Replies
7670 Views

Hi,

I am building a module and I need to setup a lot of product.product from product.template with attribute

I have an xml for attribute :

        <record id="attribute_type" model="product.attribute">
            <field name="name">Type</field>
            <field name="create_variant">1</field>
        </record>

        <record id="attribute_type_organic" model="product.attribute.value">
            <field name="name">Organic</field>
            <field name="attribute_id" ref="attribute_type"/>   
        </record>

        <record id="attribute_type_regular" model="product.attribute.value">
            <field name="name">Regular</field>
            <field name="attribute_id" ref="attribute_type"/>   
        </record>

        <record id="attribute_type_pending" model="product.attribute.value">
            <field name="name">Pending</field>
            <field name="attribute_id" ref="attribute_type"/>   
        </record>
          and so on

How to link them to a product.template, how do I pass them to attribute_line_ids to create my product.product.

I know it should look like

'attribute_line_ids': [(4,0,[y for y in product_attributes])],

but how to produce product_attibutes (list of all combination of attributes/values)

Thant you for you help

Avatar
Discard
Best Answer

with XML you can link product attributes with a product using below if you


<record id="my_product" model="product.product"> 
<field name="name">My New product</field>
<field name="standard_price">500.0</field>
<field name="list_price">750.0</field>
<field name="type">consu</field>
<field name="description_sale">My new product Desc</field>
<field name="default_code">NEWP001</field>
<field name="attribute_value_ids" eval="[(6,0,[ref('attribute_type_organic'),
ref('attribute_type_regular'), ref('attribute_type_pending')])]"/>
</record>


If you are doing the one-time data import to odoo, you can import products using the CSV or XML-RPC script, and if you really wanted the XML file for lots of product I would like to suggest you use base_module_record, this module will save your lots of time to create the XML.


hope this helps!

Avatar
Discard
Author Best Answer

<field name="attribute_value_ids" eval="[(6,0,[ref('attribute_type_organic'),
ref('attribute_type_regular'), ref('attribute_type_pending')])]"/>

It help and solve the problem but...

If I go in my product template I see nothing under variant but under product variant I saw them all

What do I have to inject in my xml for product.template get the variant too


Avatar
Discard