Skip to Content
Menú
This question has been flagged

Hi odooers


I have several products which all have variants. I wish to convert these product.product variants into standalone products (product.template).

What is the best practice for this process, whilst retaining the values of the original product.template into each new standalone product and retain their product.product variant data ?


regards

Eliot

Avatar
Descartar
Best Answer

Backup your database

Always first! This is a destructive operation if done wrong.

Identify products to convert

Only proceed if the template has more than one variant.
templates_to_convert = env['product.template'].search([('product_variant_count', '>', 1)])

Iterate over each variant

Write a script to process each product.product variant and create a standalone product.template.
Example Logic (Python or Server Action):

for product in templates_to_convert.mapped('product_variant_ids'):

    old_template = product.product_tmpl_id


    # Copy fields from the template

    new_template_vals = {

        'name': f"{old_template.name} - {product.display_name}",  # or custom naming

        'type': old_template.type,

        'categ_id': old_template.uom_po_id.id,

        'taxes_id': [(6, 0, old_template.taxes_id.ids)],

        'supplier_taxes_id': [(6, 0, old_template.supplier_taxes_id.ids)],

        'description': product.description or old_template.description,

        'default_code': product.default_code,

        'barcode': product.barcode,

        'image_1920': product.image_1920,

        # add other fields you want to preserve

    }


    # Create new template

    new_template = env['product.template'].create(new_template_vals)


    # You can also update the product.product record if needed

    new_product = new_template.product_variant_id


    # Optional: Copy stock quantities, routes, BOMs, etc.

    # Optional: deactivate old product or mark it for review

Copy extra info if needed

  • Stock Quantities: Transfer from old variant to new product.
  • BOMs: Reassign to the new product.template.
  • Sales/Purchase history: Keep using the old product if traceability is important.
  • Custom Fields: If you've added custom fields, map them accordingly.



Avatar
Descartar
Autor

Thanks, I will try this

Related Posts Respostes Vistes Activitat
2
d’ag. 23
4130
0
d’oct. 21
1716
1
de set. 19
5144
0
d’ag. 24
1258
5
d’oct. 21
17254