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

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
Abbandona
Risposta migliore

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
Abbandona

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 ?

Autore

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.

Risposta migliore

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
Abbandona
Post correlati Risposte Visualizzazioni Attività
4
nov 20
7820
2
lug 24
7792
1
gen 22
18434
0
ott 19
2219
3
lug 19
5368