Zum Inhalt springen
Menü
Sie müssen registriert sein, um mit der Community zu interagieren.
Diese Frage wurde gekennzeichnet
2 Antworten
354 Ansichten

In default Odoo, when we archived the Product variants and then when we create a new variant then automatic archived variants are visible in product. Have any one have idea to resolve this?

Avatar
Verwerfen
Beste Antwort

Hi,


There are two approaches:


1. Use a computed domain on product variants


Override the product template view to show only active variants in dropdowns.


Example:


<field name="product_variant_ids" domain="[('active','=',True)]"/>



This doesn’t prevent creation, but it hides archived variants from selection.


2. Prevent automatic unarchiving via code


Override _create_variant_ids in product.template:


from odoo import models


class ProductTemplate(models.Model):

    _inherit = 'product.template'


    def _create_variant_ids(self):

        # Prevent archived variants from being reactivated

        existing_variants = self.product_variant_ids.filtered(lambda v: not v.active)

        super(ProductTemplate, self)._create_variant_ids()

        # Re-archive any variants that were previously archived

        existing_variants.write({'active': False})


Hope it helps.

Avatar
Verwerfen
Beste Antwort

Hi,

You should removed this archived variant from the product template before created the new one.

Regards!

Avatar
Verwerfen