Passa al contenuto
Menu
È necessario essere registrati per interagire con la community.
La domanda è stata contrassegnata
2 Risposte
5379 Visualizzazioni

I have a Many2one field that has a domain filter with 2 conditions that it needs to meet. There should only be one value to select in that Many2one field that meets those 2 conditions. Since there is only one value to select from, I would like that Many2one field to automatically select that specific value or default to that value. Is there a way to do this?

Avatar
Abbandona
Risposta migliore

Hi,

Either you can set the value from an onchange function or from the default get function or by making a computed field.

I think here it is better to set the value using the default get method.

Reference: https://www.youtube.com/watch?v=OBw0PFhOAnM

Thanks

Avatar
Abbandona

@api.model

def default_get(self, fields):

res = super(ClassName, self).default_get(fields)

#if conditions are met

res['field_name'] = id_of_many2one_field

return res

Risposta migliore

@api.model
def default_get(self, default_fields):
res = super(Classname, self).default_get(default_fields)
res['m2o_field'] = (4, ID) # (4, ID of m2o field)
return res



Avatar
Abbandona
Post correlati Risposte Visualizzazioni Attività
1
dic 21
2265
3
mar 24
7249
3
ago 25
2052
2
feb 24
2457
2
nov 22
4929