Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
2 Trả lời
464 Lượt xem

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?

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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.

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

Hi,

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

Regards!

Ảnh đại diện
Huỷ bỏ