Skip to Content
Meniu
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
Această întrebare a fost marcată
1 Răspunde
9592 Vizualizări

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 ??

Imagine profil
Abandonează
Cel mai bun răspuns

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. 

Imagine profil
Abandonează
Related Posts Răspunsuri Vizualizări Activitate
2
iul. 24
7864
4
nov. 20
7897
0
aug. 19
3394
3
iul. 25
4123
0
mai 25
828