Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
2 ตอบกลับ
435 มุมมอง

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?

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

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.

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

Hi,

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

Regards!

อวตาร
ละทิ้ง