Ir al contenido
Menú
Se marcó esta pregunta
5 Respuestas
5952 Vistas

I have two models A has a One2many relationship to B in which there is a selection

class A();
_name = 'class.a'

class_b_ids = One2many('class.b', class_a_id)

class B()
_name = 'class.b'
class_a_id = Many2one('class.a')
selection_type = selection(....)

Is it possible to use a domain on the xml that concerns the One2Many field with the selection?

like this

<field name="class_b_ids" domain="[('selection_type', '=',  some_selection)]"/>

EDIT:

My error:

File "/usr/lib/python3/dist-packages/odoo/fields.py", line 1776, in <listcomp>
    return [(value, translate(label) if label else label) for value, label in selection]
ValueError: too many values to unpack (expected 2)


Avatar
Descartar
Mejor respuesta

Yes, you can do so but not on XML. Because on o2m field, domain does not work on XML but it does work if you set a domain on the field in py file.

You can check the example in MRP module.

Avatar
Descartar

I think adding it in Xml or python is the same thing.

I think he can write the domain as he showed us. Syntactically, he 'll get no error. It's just a matter of What does he want to do with it that would cause a problem. ( I guess he wants to only add records of Class A which have a specific state.. AND in this case he can add a related field)

Don't you agree ?

Autor

I have got an error

No my friend Ibrahim, its way different. Just give it a try and you will get to know if it is similar of different.

Mejor respuesta

Hi,

I resolve that using onchange methode : 

@api.onchange('class_b_ids')
def onchange_class_b_ids(self):
domain = {}
domain= { 'domain':[('selection_type', '=',  some_selection)],}
return domain

Please if you find my answer usefull vote positive.

Avatar
Descartar
Publicaciones relacionadas Respuestas Vistas Actividad
4
nov 20
7748
2
jul 24
7727
1
ene 22
18372
0
oct 19
2171
3
jul 19
5330