İçereği Atla
Menü
Bu soru işaretlendi
1 Cevapla
801 Görünümler

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
Vazgeç
En İyi Yanıt

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
Vazgeç
Üretici

Thanks, I will try this

İlgili Gönderiler Cevaplar Görünümler Aktivite
2
Ağu 23
4169
0
Eki 21
1738
1
Eyl 19
5160
0
Ağu 24
1282
5
Eki 21
17283