Passa al contenuto
Menu
È necessario essere registrati per interagire con la community.
La domanda è stata contrassegnata
1 Rispondi
7783 Visualizzazioni

Hello everybody, I would like to make my form fields readonly in my model based on a condition, I'm trying it with fields_view_get for not add "attrs readonly" in each field in my xml file, I have the following code:


@api.model 

 def fields_view_get(self, view_id=None, view_type='form', toolbar=False, submenu=False):

 doc = etree.XML(res['arch']) 

 for field in res['fields']: 

 for node in doc.xpath("//field[@name='%s']" % field): 

node.set("readonly", "1") 

setup_modifiers(node, res['fields'][field]) 

res['arch'] = etree.tostring(doc) 

return res


But it doesn't work, what could be my problem? Thank you so much!

Avatar
Abbandona
Risposta migliore

Where, in your code, is set variable res?

Probably you need as first line:

 res = super(YOUR_CLASS_NAME, self).fields_view_get(view_id=view_id, view_type=view_type, toolbar=toolbar, submenu=submenu)

Avatar
Abbandona
Autore

Thank You so much!! That was the error :)

Post correlati Risposte Visualizzazioni Attività
1
dic 23
23096
3
dic 23
91332
3
set 21
5289
2
set 18
6030
1
apr 18
3450