2
votes

I will create State Names and I will also create few cities and assign to state Like Karnatak-Bangalore Karnatak-Mangalore
Karnatak-Mysore

Gujarat-Ahemadabad, Gujarat-Gandhinagar

when I select Karntaka in 'pin_catg' class in tree view i.e 'pin_name' ,'city_n' should get only Karnataka cities like Mangalore ,Bangalore,Mysore how to add domain filter for this .I have XML file but its lot of data I want something like this so written this classes .Domain filter

class state_catg(osv.Model): 
    _name="state.catg" 

    _columns={
        'state_name':fields.char('State Names',size=64,required=True),
    }


class city_name(osv.Model): 
    _name="city.name" 
    _rec_name='city_name'
    _description="Define asset name" 

    _columns={
        'city_name':fields.char('City Name',size=64,required=True),
        'state_name12':fields.many2one('state.catg','State',size=64,required=True),
    }

class pin_catg(osv.Model): 
    _name="pin.catg" 

    _columns={
        'state_name':fields.many2one('state.catg','State'),
        'list123':fields.one2many('pin.name','list12'),
    }




class pin_name(osv.Model): 
    _name="pin.name" 

    _columns={
        'city_n':fields.many2one('City Name',size=64,required=True),
        'pin_code' : fields.char('Pin Code'),
        'list12':fields.many2one('pin.catg','list123'),
    }
1

1 Answers

0
votes

In a easy way you just take one master

class res_city(models.Model):
_name = 'res.city'

name = fields.Char('Name')
state_id = fields.Many2one('res.country.state', 'State')


#and put onchange where you use state and city like:

@api.onchange('state_id')
def _onchange_state_id(self):
    if self.state_id:
        res = {'domain': {'city_id': [('state_id', '=', self.state_id.id)]}}