@@ -12,38 +12,112 @@ def setUp(self):
1212
1313 self .so = self .env .ref ('sale.sale_order_5' )
1414
15- def get_wizard_write_dict (self , wizard , attr_val_ext_ids ):
15+ def get_attr_values (self , attr_val_ext_ids = None ):
16+ if not attr_val_ext_ids :
17+ attr_val_ext_ids = []
18+ ext_id_prefix = 'product_configurator.product_attribute_value_%s'
19+ attr_vals = self .env ['product.attribute.value' ]
20+
21+ for ext_id in attr_val_ext_ids :
22+ attr_vals += self .env .ref (ext_id_prefix % ext_id )
23+
24+ return attr_vals
25+
26+ def get_wizard_write_dict (self , wizard , attr_values ):
1627 """Turn a series of attribute.value objects to a dictionary meant for
1728 writing values to the product.configurator wizard"""
1829
1930 write_dict = {}
20- ext_id_prefix = 'product_configurator.product_attribute_value_%s'
2131
22- for ext_id in attr_val_ext_ids :
23- val = self .env .ref (ext_id_prefix % ext_id )
24- write_dict .update ({
25- wizard .field_prefix + str (val .attribute_id .id ): val .id
26- })
32+ multi_attr_ids = wizard .product_tmpl_id .attribute_line_ids .filtered (
33+ lambda x : x .multi ).mapped ('attribute_id' ).ids
34+
35+ for val in attr_values :
36+ field_name = wizard .field_prefix + str (val .attribute_id .id )
37+ if val .attribute_id .id in multi_attr_ids :
38+ write_dict .setdefault (field_name , [(6 , 0 , [])])
39+ write_dict [field_name ][0 ][2 ].append (val .id )
40+ continue
41+ write_dict .update ({field_name : val .id })
42+
2743 return write_dict
2844
29- def test_wizard (self ):
45+ def wizard_write_proceed (self , wizard , attr_vals , value_ids = None ):
46+ """Writes config data to the wizard then proceeds to the next step"""
47+ vals = self .get_wizard_write_dict (wizard , attr_vals )
48+ wizard .write (vals )
49+ wizard .action_next_step ()
50+ # Store the values since the wizard removes dynamic values from dict
51+ if type (value_ids ) == list :
52+ value_ids += attr_vals .ids
53+
54+ def test_wizard_configuration (self ):
3055 """Test product configurator wizard"""
3156
3257 # Start a new configuration wizard
33- wizard = self .env ['product.configurator' ].create ({
34- 'product_tmpl_id' : self .cfg_tmpl .id
58+ wizard_obj = self .env ['product.configurator' ].with_context ({
59+ 'active_model' : 'sale.order' ,
60+ 'active_id' : self .so .id
3561 })
3662
63+ wizard = wizard_obj .create ({'product_tmpl_id' : self .cfg_tmpl .id })
3764 wizard .action_next_step ()
3865
39- # Get write values the first configuration step
40- write_dict = self .get_wizard_write_dict (wizard , ['gasoline' , '228i' ])
66+ value_ids = []
67+
68+ attr_vals = self .get_attr_values (['gasoline' , '228i' ])
69+ self .wizard_write_proceed (wizard , attr_vals , value_ids )
70+
71+ attr_vals = self .get_attr_values (['silver' , 'rims_387' ])
72+ self .wizard_write_proceed (wizard , attr_vals , value_ids )
4173
42- # Store the values since the wizard removed dynamic values from dict
43- write_val_ids = write_dict . values ( )
74+ attr_vals = self . get_attr_values ([ 'model_sport_line' ])
75+ self . wizard_write_proceed ( wizard , attr_vals , value_ids )
4476
45- # Test wizard dynamic write
46- wizard . write ( write_dict )
77+ attr_vals = self . get_attr_values ([ 'tapistry_black' ])
78+ self . wizard_write_proceed ( wizard , attr_vals , value_ids )
4779
48- self .assertTrue (wizard .value_ids .ids == write_val_ids ,
80+ attr_vals = self .get_attr_values (['steptronic' , 'tow_hook' , 'sunroof' ])
81+ vals = self .get_wizard_write_dict (wizard , attr_vals )
82+ wizard .write (vals )
83+ value_ids += attr_vals .ids
84+
85+ self .assertTrue (set (wizard .value_ids .ids ) == set (value_ids ),
4986 "Wizard write did not update the config session" )
87+
88+ wizard .action_next_step ()
89+
90+ config_variants = self .env ['product.product' ].search ([
91+ ('config_ok' , '=' , True )
92+ ])
93+
94+ self .assertTrue (len (config_variants ) == 1 ,
95+ "Wizard did not create a configurable variant" )
96+
97+ def test_reconfiguration (self ):
98+ """Test reconfiguration functionality of the wizard"""
99+ self .test_wizard_configuration ()
100+
101+ order_line = self .so .order_line .filtered (
102+ lambda l : l .product_id .config_ok
103+ )
104+
105+ reconfig_action = order_line .reconfigure_product ()
106+
107+ wizard = self .env ['product.configurator' ].browse (
108+ reconfig_action .get ('res_id' )
109+ )
110+
111+ attr_vals = self .get_attr_values (['diesel' , '220d' ])
112+ self .wizard_write_proceed (wizard , attr_vals )
113+
114+ # Cycle through steps until wizard ends
115+ while wizard .action_next_step ():
116+ pass
117+
118+ config_variants = self .env ['product.product' ].search ([
119+ ('config_ok' , '=' , True )
120+ ])
121+
122+ self .assertTrue (len (config_variants ) == 2 ,
123+ "Wizard reconfiguration did not create a new variant" )
0 commit comments