diff --git a/addons/product/models/product_attribute.py b/addons/product/models/product_attribute.py index e976e49843e..a9fe26cf255 100644 --- a/addons/product/models/product_attribute.py +++ b/addons/product/models/product_attribute.py @@ -46,7 +46,7 @@ class ProductAttribute(models.Model): @api.depends('attribute_line_ids.active', 'attribute_line_ids.product_tmpl_id') def _compute_products(self): for pa in self: - pa.product_tmpl_ids = pa.attribute_line_ids.product_tmpl_id + pa.with_context(active_test=False).product_tmpl_ids = pa.attribute_line_ids.product_tmpl_id def _without_no_variant_attributes(self): return self.filtered(lambda pa: pa.create_variant != 'no_variant') diff --git a/addons/product/tests/test_product_attribute_value_config.py b/addons/product/tests/test_product_attribute_value_config.py index 7048a080acb..584a1f63c0c 100644 --- a/addons/product/tests/test_product_attribute_value_config.py +++ b/addons/product/tests/test_product_attribute_value_config.py @@ -665,3 +665,34 @@ class TestProductAttributeValueConfig(TestProductAttributeValueCommon): 'name': '32 GB', 'attribute_id': self.ram_attribute.id, }) + + def test_inactive_related_product_update(self): + """ + Create a product and give it a product attribute then archive it, delete the product attribute, + unarchive the product and check that the product is not related to the product attribute. + """ + product_attribut = self.env['product.attribute'].create({ + 'name': 'PA', + 'sequence': 1, + 'create_variant': 'no_variant', + }) + a1 = self.env['product.attribute.value'].create({ + 'name': 'pa_value', + 'attribute_id': product_attribut.id, + 'sequence': 1, + }) + product = self.env['product.template'].create({ + 'name': 'P1', + 'type': 'product', + 'attribute_line_ids': [(0, 0, { + 'attribute_id': product_attribut.id, + 'value_ids': [(6, 0, [a1.id])], + })] + }) + self.assertEqual(product_attribut.number_related_products, 1, 'The product attribute must have an associated product') + product.action_archive() + self.assertFalse(product.active, 'The product should be archived.') + product.write({'attribute_line_ids': [[5, 0, 0]]}) + product.action_unarchive() + self.assertTrue(product.active, 'The product should be unarchived.') + self.assertEqual(product_attribut.number_related_products, 0, 'The product attribute must not have an associated product')