Below code is asset inherited class . Here i will add \'place\' field with \'Karn/Bang/Kengeri\' and \'karn/bang/malleshwaram\'
First your domain is wrong in a principle. Domain is what is "inside" a field, in other words in its model (for example field name
or id
in asset.catg
model). So you should fix that one first.
If domain depends on another field, you can use onchange method to return domain (used placeholder place_id
). Like this:
@api.onchange('place')
def onchange_place(self):
res = {}
if self.place:
res['domain'] = {'asset_catg_id': [('place_id', '=', self.place.id)]}
return res
P.S. This is example with new v8 api, but same principle applies to old api (you then don't nee to use decorator, also add cr, uid, ids
on method and call it through your view. All of this not needed for new api). As it looks like you are still developing on old api.
Update For old api:
def onchange_place(self,cr, uid, ids, place, context=None):
res = {}
if self.place: #on old api it will return id, instead of record
res['domain'] = {'asset_catg_id': [('place_id', '=', self.place)]}
return res
And then in your view (don't know what kind of view you are using):
Still you need to define some field in asset.catg
so it would be used to match place
field. For example:
'place_id': fields.many2one('asset.parentlocation', 'Place')
And then when you define asset category, you set which Place it should belong to. Then when you choose place calendar.event
, onchange method will set domain on asset_catg_id
field correctly.