Overslaan naar inhoud
Menu
Je moet geregistreerd zijn om te kunnen communiceren met de community.
Deze vraag is gerapporteerd
1 Beantwoorden
809 Weergaven

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
Annuleer
Beste antwoord

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
Annuleer
Auteur

Thanks, I will try this

Gerelateerde posts Antwoorden Weergaven Activiteit
2
aug. 23
4182
0
okt. 21
1742
1
sep. 19
5166
0
aug. 24
1285
5
okt. 21
17305