Skip ke Konten
Menu
Pertanyaan ini telah diberikan tanda
1 Balas
382 Tampilan

I have a multi-level organisational structure (Branches, Regions, Districts,  Formations) and I'd like to filter the available organisations based on its parent.


For each of the orgs with a parent (regions, districts, formations), their source model includes the relationship to the parent, i.e. 

Regions - includes a Branches field.

Districts - includes a Regions field.

Formations - includes a Districts fields.


So what I'd like to do is filter the list of available Regions based on the selected Branch. filter the list of available Districts based on the selected Region and filter the list of available Formations based on the selected District.


I'm using Odoo cloud and the studio portal, so I can't use custom code. Id assume I need to use the domain option, but I just can't figure out the syntax.

Avatar
Buang
Jawaban Terbai

You need to create function and add the result as the domain

the function should be similar like this

def _get_district_domain(self):
​region_id = self.region.id
​return [('parent_id', '=', region_id)]

districts = fields.Many2one(... domain=_get_district_domain)

Keep in mind that you have to define the field after the method. User same pattern for formation field

Avatar
Buang