Skip to Content
Menu
This question has been flagged
1 Reply
970 Views

I am trying to create some custom demo data for testing in Odoo v17 in xml

currently i am struggling with the creation of product.product while inheriting from product.template

this is the code that i currently have:

<record id="sales_test_1_product_template" model="product.template">
<field name="name">The better table</field>
<field name="detailed_type">product</field>
<field name="invoice_policy">delivery</field>
<field name="tracking">serial</field>
<field name="categ_id" ref="product.product_category_5"/>
<field name="uom_id" ref="uom.product_uom_unit"/>
<field name="uom_po_id" ref="uom.product_uom_unit"/>
<field name="description">Solid wood table.</field>
<field name="standard_price">200</field>
<field name="list_price">500</field>
<field name="image_1920" type="base64" file="mrp/static/img/table.png"/>
</record>

<record id="sales_test_1_product_template_product1" model="product.product">
<field name="product_tmpl_id" ref="sales_test_1_product_template"/>
<field name="default_code">FURN_009</field>
<field name="standard_price">299</field>
<field name="list_price">520</field>
</record>

the error that i get when trying to run this is this:

psycopg2.errors.UniqueViolation: duplicate key value violates unique constraint "product_product_combination_unique"
DETAIL:  Key (product_tmpl_id, combination_indices)=(74, ) already exists.

i assume this is because the product.template creates a default product with the Key (74, ), and then when i try to create a product.product, i am trying to create a product with the same Key. I cant figure out how to change this "Key"


My goal is to get 3 pieces of the product to be "on hand", 3 different Serial Numbers, while being visible for a certain company

Avatar
Discard
Best Answer

Hi,

Please refer to the code below:

For Product:


<record id="sales_test_1_product_template" model="product.template">

    <field name="name">The better table</field>

    <field name="detailed_type">product</field>

    <field name="invoice_policy">delivery</field>

    <field name="tracking">serial</field>

    <field name="categ_id" ref="product.product_category_5"/>

    <field name="uom_id" ref="uom.product_uom_unit"/>

    <field name="uom_po_id" ref="uom.product_uom_unit"/>

    <field name="description">Solid wood table.</field>

    <field name="standard_price">200</field>

    <field name="list_price">500</field>

    <field name="image_1920" type="base64"

           file="my_module/static/img/table.png"/>

    <field name="company_id" ref="base.main_company"/>

</record>


No need to create a separate product.product. Odoo creates it automatically.


For serial:


  <record id="serial_001" model="stock.lot">

    <field name="name">SERIAL001</field>

    <field name="product_id" ref="sales_test_1_product_template"/>

    <field name="company_id" ref="base.main_company"/>

</record>


<record id="serial_002" model="stock.lot">

    <field name="name">SERIAL002</field>

    <field name="product_id" ref="sales_test_1_product_template"/>

    <field name="company_id" ref="base.main_company"/>

</record>


<record id="serial_003" model="stock.lot">

    <field name="name">SERIAL003</field>

    <field name="product_id" ref="sales_test_1_product_template"/>

    <field name="company_id" ref="base.main_company"/>

</record>


Hope it helps.

Avatar
Discard
Related Posts Replies Views Activity
3
Jul 25
1215
0
May 21
3346
1
May 21
6742
5
Aug 16
5663
1
Jul 15
7862