summaryrefslogtreecommitdiff
path: root/addons/product
diff options
context:
space:
mode:
authorWilliam Henrotin <whe@odoo.com>2019-12-20 08:46:58 +0000
committerSimon Lejeune <sle@openerp.com>2020-03-10 13:57:07 +0000
commitf36d0ce584686b7c50452fe6a824f630974acea0 (patch)
tree6b279513bf599dc9e71f1b68664e9f7663761a89 /addons/product
parent42e6396d4a62340540a14f6252032f64d315be86 (diff)
[FIX] product: unarchive variant archive template
Steps to reproduce: * Create a template with 2 variants * Archive one variant * Unarchive this same variant --> the template is archived This is due to commit 6a13b565cbbad89ff1c4177b171b01f30c83edf9. If the variant is the only one, toggle_active on the variant should be reflected on the template. The issue is that toggle active do not count archived variant. One active variant and one archived variant are counted as 1. This commit make toggle_active count all variants closes odoo/odoo#34769 Signed-off-by: Simon Lejeune (sle) <sle@openerp.com>
Diffstat (limited to 'addons/product')
-rw-r--r--addons/product/models/product.py2
-rw-r--r--addons/product/tests/test_variants.py27
2 files changed, 28 insertions, 1 deletions
diff --git a/addons/product/models/product.py b/addons/product/models/product.py
index 20e8c4fbb74..b868751b0d9 100644
--- a/addons/product/models/product.py
+++ b/addons/product/models/product.py
@@ -684,7 +684,7 @@ class ProductProduct(models.Model):
def toggle_active(self):
""" Archiving related product.template if there is only one active product.product """
- with_one_active = self.filtered(lambda product: len(product.product_tmpl_id.product_variant_ids) == 1)
+ with_one_active = self.filtered(lambda product: len(product.product_tmpl_id.with_context(active_test=False).product_variant_ids) == 1)
for product in with_one_active:
product.product_tmpl_id.toggle_active()
return super(ProductProduct, self - with_one_active).toggle_active()
diff --git a/addons/product/tests/test_variants.py b/addons/product/tests/test_variants.py
index 89009f113e6..d1ee1107a91 100644
--- a/addons/product/tests/test_variants.py
+++ b/addons/product/tests/test_variants.py
@@ -233,6 +233,33 @@ class TestVariants(common.TestProductCommon):
one_variant_template.with_company(company_b).standard_price
)
+ def test_archive_variant(self):
+ template = self.env['product.template'].create({
+ 'name': 'template'
+ })
+ self.assertEqual(len(template.product_variant_ids), 1)
+
+ template.write({
+ 'attribute_line_ids': [(0, False, {
+ 'attribute_id': self.size_attr.id,
+ 'value_ids': [
+ (4, self.size_attr.value_ids[0].id, self.size_attr_value_s),
+ (4, self.size_attr.value_ids[1].id, self.size_attr_value_m)
+ ],
+ })]
+ })
+ self.assertEqual(len(template.product_variant_ids), 2)
+ variant_1 = template.product_variant_ids[0]
+ variant_1.toggle_active()
+ self.assertFalse(variant_1.active)
+ self.assertEqual(len(template.product_variant_ids), 1)
+ self.assertEqual(len(template.with_context(
+ active_test=False).product_variant_ids), 2)
+ variant_1.toggle_active()
+ self.assertTrue(variant_1.active)
+ self.assertTrue(template.active)
+
+
class TestVariantsNoCreate(common.TestProductCommon):
def setUp(self):