From 1188715313563c177cf0a7a37cf503022848a82b Mon Sep 17 00:00:00 2001 From: Thierry Ducrest Date: Tue, 24 May 2022 10:09:25 +0200 Subject: [PATCH] fixup! Imp p_main_supplierinfo default sellers for variant --- .../tests/test_product_main_supplier.py | 67 +++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/product_main_supplierinfo/tests/test_product_main_supplier.py b/product_main_supplierinfo/tests/test_product_main_supplier.py index 1c5649af4a9d..24e594c91a8a 100644 --- a/product_main_supplierinfo/tests/test_product_main_supplier.py +++ b/product_main_supplierinfo/tests/test_product_main_supplier.py @@ -18,6 +18,68 @@ def setUpClass(cls): cls.seller_2bis = cls.env.ref("product.product_supplierinfo_2bis") cls.seller_2bis.sequence = 3 cls.company_2 = cls.env.company.create({"name": "Company2"}) + # For the test case 4 + cls.attribute = cls.env["product.attribute"].create({"name": "Size"}) + cls.attribute_value_1 = cls.env["product.attribute.value"].create( + {"name": "L", "attribute_id": cls.attribute.id} + ) + cls.attribute_value_2 = cls.env["product.attribute.value"].create( + {"name": "XL", "attribute_id": cls.attribute.id} + ) + cls.template1 = cls.env["product.template"].create( + { + "name": "Hat", + "attribute_line_ids": [ + ( + 0, + 0, + { + "attribute_id": cls.attribute.id, + "value_ids": [ + ( + 6, + 0, + [ + cls.attribute_value_1.id, + cls.attribute_value_2.id, + ], + ) + ], + }, + ), + ], + } + ) + cls.product_1 = cls.template1.product_variant_ids[0] + cls.product_2 = cls.template1.product_variant_ids[1] + cls.date_old = "2000-01-01" + cls.date_older = "2000-12-31" + cls.product_template_supply = cls.seller_2.copy( + { + "product_tmpl_id": cls.product_2.product_tmpl_id.id, + "sequence": 1, + "date_start": cls.date_older, + "date_end": cls.date_old, + } + ) + cls.product_1_supply = cls.seller_1.copy( + { + "product_tmpl_id": cls.product_1.product_tmpl_id.id, + "product_id": cls.product_1.id, + "sequence": 2, + "date_start": cls.date_older, + "date_end": cls.date_old, + } + ) + cls.product_2_supply = cls.seller_2.copy( + { + "product_tmpl_id": cls.product_2.product_tmpl_id.id, + "product_id": cls.product_2.id, + "sequence": 3, + "date_start": cls.date_older, + "date_end": cls.date_old, + } + ) def test_main_seller_1(self): """"Case 1: all the sellers share the same company.""" @@ -45,3 +107,8 @@ def test_main_seller_3(self): self.seller_1.date_start = tomorrow self.seller_2.date_end = yesterday self.assertEqual(self.product.main_seller_id, self.seller_2bis) + + def test_main_seller_4(self): + """Case 4: No valid supplier so select one related to the variant.""" + self.assertEqual(self.product_1.main_seller_id, self.product_1_supply) + self.assertEqual(self.product_2.main_seller_id, self.product_2_supply)