Hi,
1- try this :
@api.onchange('picking_id', 'picking_id.selection_field')
def _onchange_many2one(self):
if self.picking_id.selection_field == ' ':
domain = [('', '=', )]
return {'domain': {'many2one_field': domain}}
Now i'm not sure if 'picking_id.selection_field' would work in Onchange as in depends. but give it a try.
2- If 1 is not working, you ll need to override _search function of the model you mentioned in M2O declaration:
A- add context in M2O (xml) : context="{'filter_field':True, 'active_id':active_id}"
B- Override Function _search of the model you mentioned in M2O declaration:
@api.model
def _search(self, args, offset=0, limit=None, order=None, count=False, access_rights_uid=None):
if self._context.get('filter_field', False):
active_id = self._context.get('active_id')
obj_record= self.env['YourObject'].browse(active_id)
if obj_record.picking_id.Your_Selection_field == ' ' :
args += [('', 'in', )] // Add your domain
return super(YourModel, self)._search(args, offset=offset, limit=limit, order=order,count=count, access_rights_uid=access_rights_uid)
Hope this helps. If it does, tell me which one works. If not, tell me what's wrong.
hope this will helps you: http://learnopenerp.blogspot.com/2016/10/onchange-many2one-filed-in-odoo.html