Skip ke Konten
Menu
Pertanyaan ini telah diberikan tanda
5 Replies
5959 Tampilan

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
Buang
Jawaban Terbai

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
Buang

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 ?

Penulis

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.

Jawaban Terbai

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
Buang
Post Terkait Replies Tampilan Aktivitas
4
Nov 20
7775
2
Jul 24
7746
1
Jan 22
18381
0
Okt 19
2188
3
Jul 19
5343