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?
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- 客户关系管理
- e-Commerce
- 会计
- 库存
- PoS
- Project
- MRP
此问题已终结
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!