Skip to Content
Menu
This question has been flagged
1 Reply
8632 Views

I am using Odoo11 community version.

I do have a selection field in stock picking (DO), initially its value will be False.

I do have a many2one field in the stock move. 

Is it possible to update the domain of many2one field on change of selection field in picking ??

Avatar
Discard
Best Answer

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. 

Avatar
Discard
Related Posts Replies Views Activity
2
Jul 24
6648
4
Nov 20
6578
0
Aug 19
2385
2
Jul 24
942
1
Jun 24
3563