If you use the onchange method to host the domain, you do not need to put any domain in a field in xml.
You can do something like this:
@api.onchange('lecturer_id') def _onchange_lecturer(self): res = {} if self.lecturer_id: sub_id =[] a = [] lecturer = self.lecturer_id.id query = """select op_subject_id from lecturer_subject_rel where op_lecturer_id='%s'""" % lecturer self.env.cr.execute(query) a = self.env.cr.fetchall() d = 0 for i in a: e = i[0] sub_id.append(e) d += 1 res['domain] = {'subject_id': [('id', 'in', sub_id)]} else: res['domain] = {'subject_id': []} return res
Or you can simply create a function field that will calculate the identifier of your item, and then you use it directly in the domain.
PS but your code looking for an identifier looks really strange, I donβt know why you are doing this.
source share