Skip ke Konten
Menu
Pertanyaan ini telah diberikan tanda

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
Buang
Jawaban Terbai

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
Buang
Penulis

Thanks, I will try this

Post Terkait Replies Tampilan Aktivitas
2
Agu 23
4132
0
Okt 21
1721
1
Sep 19
5146
0
Agu 24
1260
5
Okt 21
17255