@@ -26,27 +26,30 @@ class AttributeOptionWizard(models.TransientModel):
2626 def validate (self ):
2727 return True
2828
29- @api .model
30- def create (self , vals ):
29+ @api .model_create_multi
30+ def create (self , vals_list ):
3131 attr_obj = self .env ["attribute.attribute" ]
32- attr = attr_obj .browse (vals ["attribute_id" ])
33-
34- opt_obj = self .env ["attribute.option" ]
35-
36- for op_id in vals .get ("option_ids" ) and vals ["option_ids" ][0 ][2 ] or []:
37- model = attr .relation_model_id .model
38-
39- name = self .env [model ].browse (op_id ).name_get ()[0 ][1 ]
40- opt_obj .create (
41- {
42- "attribute_id" : vals ["attribute_id" ],
43- "name" : name ,
44- "value_ref" : "{},{}" .format (attr .relation_model_id .model , op_id ),
45- }
46- )
47- if vals .get ("option_ids" ):
48- del vals ["option_ids" ]
49- return super ().create (vals )
32+ for vals in vals_list :
33+ attr = attr_obj .browse (vals ["attribute_id" ])
34+
35+ opt_obj = self .env ["attribute.option" ]
36+
37+ for op_id in vals .get ("option_ids" ) and vals ["option_ids" ][0 ][2 ] or []:
38+ model = attr .relation_model_id .model
39+
40+ name = self .env [model ].browse (op_id ).name_get ()[0 ][1 ]
41+ opt_obj .create (
42+ {
43+ "attribute_id" : vals ["attribute_id" ],
44+ "name" : name ,
45+ "value_ref" : "{},{}" .format (
46+ attr .relation_model_id .model , op_id
47+ ),
48+ }
49+ )
50+ if vals .get ("option_ids" ):
51+ del vals ["option_ids" ]
52+ return super ().create (vals_list )
5053
5154 # Hack to circumvent the fact that option_ids never actually exists in the DB,
5255 # thus crashing when read is called after create
@@ -56,26 +59,23 @@ def read(self, fields=None, load="_classic_read"):
5659 return super ().read (fields , load )
5760
5861 @api .model
59- def fields_view_get (
60- self , view_id = None , view_type = "form" , toolbar = False , submenu = False
61- ):
62+ def get_views (self , views , options = None ):
6263 context = self .env .context
63- res = super ().fields_view_get (
64- view_id = view_id ,
65- view_type = view_type ,
66- toolbar = toolbar ,
67- submenu = submenu ,
68- )
69-
70- if view_type == "form" and context and context .get ("attribute_id" ):
64+ res = super ().get_views (views , options = options )
65+ if (
66+ "views" in res
67+ and "form" in res ["views" ]
68+ and context
69+ and context .get ("attribute_id" )
70+ ):
7171 attr_obj = self .env ["attribute.attribute" ]
7272 attr = attr_obj .browse (context .get ("attribute_id" ))
7373 model = attr .relation_model_id
7474
7575 relation = model .model
7676 domain_ids = [op .value_ref .id for op in attr .option_ids if op .value_ref ]
7777
78- res ["fields" ].update (
78+ res ["models" ][ self . _name ].update (
7979 {
8080 "option_ids" : {
8181 "domain" : [("id" , "not in" , domain_ids )],
@@ -87,10 +87,10 @@ def fields_view_get(
8787 }
8888 )
8989
90- eview = etree .fromstring (res ["arch" ])
90+ eview = etree .fromstring (res ["views" ][ "form" ][ " arch" ])
9191 options = etree .Element ("field" , name = "option_ids" , nolabel = "1" )
9292 placeholder = eview .xpath ("//separator[@string='options_placeholder']" )[0 ]
9393 placeholder .getparent ().replace (placeholder , options )
94- res ["arch" ] = etree .tostring (eview , pretty_print = True )
94+ res ["views" ][ "form" ][ " arch" ] = etree .tostring (eview , pretty_print = True )
9595
9696 return res
0 commit comments