@@ -58,7 +58,7 @@ def test_product_attribute_manual_creation(self):
5858 )
5959 self .assertTrue (self .product_template1 .has_pending_variants )
6060 variant_creation_wizard1 = self .wizard_variant_manual_creation .with_context (
61- active_id = self .product_template1 .id
61+ active_id = self .product_template1 .id , active_model = "product.template"
6262 ).create ({})
6363 variant_creation_wizard1 ._onchange_product_tmpl ()
6464 self .assertEqual (
@@ -79,7 +79,7 @@ def test_product_attribute_manual_creation(self):
7979 )
8080
8181 variant_creation_wizard2 = self .wizard_variant_manual_creation .with_context (
82- active_id = self .product_template1 .id
82+ active_id = self .product_template1 .id , active_model = "product.template"
8383 ).create ({})
8484 variant_creation_wizard2 ._onchange_product_tmpl ()
8585 self .assertEqual (
@@ -105,7 +105,7 @@ def test_product_attribute_manual_creation(self):
105105 snd_variant = variants [1 ]
106106 snd_variant .active = False
107107 variant_creation_wizard3 = self .wizard_variant_manual_creation .with_context (
108- active_id = self .product_template1 .id
108+ active_id = self .product_template1 .id , active_model = "product.template"
109109 ).create ({})
110110 variant_creation_wizard3 ._onchange_product_tmpl ()
111111 self .assertEqual (
@@ -121,6 +121,74 @@ def test_product_attribute_manual_creation(self):
121121 variant_creation_wizard2 .action_create_variants ()
122122 self .assertTrue (snd_variant .active )
123123
124+ def test_product_attribute_manual_creation_from_variant (self ):
125+ """
126+ Simulate the use of the wizard from a product.product
127+ """
128+ # create product with attribute and "Variant creation" option is
129+ # set on "Don't create automatically"
130+ self .product_template1 = self .product_template .create (
131+ {"name" : "Product template 1" , "no_create_variants" : "yes" }
132+ )
133+ self .attribute_line_model .with_context (check_variant_creation = True ).create (
134+ {
135+ "product_tmpl_id" : self .product_template1 .id ,
136+ "attribute_id" : self .attribute1 .id ,
137+ "value_ids" : [(6 , 0 , [self .value1 .id , self .value2 .id ])],
138+ }
139+ )
140+ self .assertEqual (self .product_template1 .product_variant_count , 1 )
141+ variants = self .product_template1 .product_variant_ids
142+ self .assertEqual (
143+ variants .product_template_attribute_value_ids .product_attribute_value_id .id ,
144+ False ,
145+ )
146+ self .assertTrue (self .product_template1 .has_pending_variants )
147+ variant_creation_wizard1 = self .wizard_variant_manual_creation .with_context (
148+ active_id = self .product_template1 .id , active_model = "product.template"
149+ ).create ({})
150+ variant_creation_wizard1 ._onchange_product_tmpl ()
151+ self .assertEqual (
152+ variant_creation_wizard1 .line_ids .attribute_id .id , self .attribute1 .id
153+ )
154+ variant_creation_wizard1 .line_ids .write (
155+ {
156+ "selected_value_ids" : [(6 , 0 , [self .value1 .id ])],
157+ "attribute_value_ids" : [(6 , 0 , [self .value1 .id ])],
158+ }
159+ )
160+ self .assertEqual (variant_creation_wizard1 .variants_to_create , 1 )
161+ variant_creation_wizard1 .action_create_variants ()
162+ self .assertEqual (self .product_template1 .product_variant_count , 1 )
163+ self .assertEqual (
164+ variants .product_template_attribute_value_ids .product_attribute_value_id .id ,
165+ self .value1 .id ,
166+ )
167+
168+ variant_creation_wizard2 = self .wizard_variant_manual_creation .with_context (
169+ active_id = self .product_template1 .product_variant_ids .id ,
170+ active_model = "product.product" ,
171+ ).create ({})
172+ variant_creation_wizard2 ._onchange_product_tmpl ()
173+ self .assertEqual (
174+ variant_creation_wizard2 .line_ids .attribute_id .id , self .attribute1 .id
175+ )
176+ variant_creation_wizard2 .line_ids .write (
177+ {
178+ "selected_value_ids" : [(6 , 0 , [self .value2 .id ])],
179+ "attribute_value_ids" : [(6 , 0 , [self .value2 .id ])],
180+ }
181+ )
182+ self .assertEqual (variant_creation_wizard1 .variants_to_create , 1 )
183+ variant_creation_wizard2 .action_create_variants ()
184+ self .assertEqual (self .product_template1 .product_variant_count , 2 )
185+ variants = self .product_template1 .product_variant_ids
186+ self .assertEqual (
187+ variants .product_template_attribute_value_ids .product_attribute_value_id .ids ,
188+ [self .value1 .id , self .value2 .id ],
189+ )
190+ self .assertFalse (self .product_template1 .has_pending_variants )
191+
124192 def test_product_attribute_manual_creation_invalid_combination (self ):
125193 """
126194 Try to create a variant for a forbidden combination
@@ -153,7 +221,7 @@ def test_product_attribute_manual_creation_invalid_combination(self):
153221
154222 # Create all the variants with the wizard
155223 variant_creation_wizard1 = self .wizard_variant_manual_creation .with_context (
156- active_id = self .product_template1 .id
224+ active_id = self .product_template1 .id , active_model = "product.template"
157225 ).create ({})
158226 variant_creation_wizard1 ._onchange_product_tmpl ()
159227 self .assertEqual (
@@ -202,7 +270,7 @@ def test_product_attribute_manual_creation_invalid_combination(self):
202270 self .assertEqual (self .product_template1 .product_variant_count , 3 )
203271 # Try to re-create it using the wizard
204272 variant_creation_wizard2 = self .wizard_variant_manual_creation .with_context (
205- active_id = self .product_template1 .id
273+ active_id = self .product_template1 .id , active_model = "product.template"
206274 ).create ({})
207275 variant_creation_wizard2 ._onchange_product_tmpl ()
208276 variant_creation_wizard2 .line_ids = [
0 commit comments