Skip to Content
Menu
This question has been flagged
5 Replies
6053 Views

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
Discard
Best Answer

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
Discard

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 ?

Author

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.

Best Answer

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
Discard
Related Posts Replies Views Activity
4
Nov 20
7876
2
Jul 24
7838
1
Jan 22
18498
0
Oct 19
2238
3
Jul 19
5403