Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
1 Trả lời
9586 Lượt xem

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

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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. 

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
2
thg 7 24
7860
4
thg 11 20
7891
0
thg 8 19
3389
naked domain set up Đã xử lý
3
thg 7 25
4119
0
thg 5 25
817