Přejít na obsah
Menu
You need to be registered to interact with the community.
This question has been flagged
5 Odpovědi
5978 Zobrazení

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
Zrušit
Nejlepší odpověď

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
Zrušit

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.

Nejlepší odpověď

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
Zrušit
Related Posts Odpovědi Zobrazení Aktivita
4
lis 20
7797
2
čvc 24
7770
1
led 22
18405
0
říj 19
2201
3
čvc 19
5362