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

Hi, 

I have two new models I added :


    class Model1(models.Model):
    _name = 'model1'
    
_description = 'model1'

    
name = fields.Char(string='Nom')
    
category = fields.Many2many('model2', string='model2')


    class Model2(models.Model):
    _name = 'model2'
    
_description = 'model2'
    
name = fields.Char(string='Nom')


Model1 can contain many model2, and model2 can be contained in different model1. On my hr.employee model, I would like my user to select a model1, then display a list of model2 according to the model1, in order to make him select one of these model2. How can I achieve that ? I already tried domains, but it does not seem to work with domain.

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

see how to return dynamic domains from python side: https://www.youtube.com/watch?v=dq5Vtj_pwuI&t=197s

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

Hi,

Please try the below:

from odoo import fields, models,api

class HrEmployee(models.Model):
_inherit = 'hr.employee'

model1_id = fields.Many2one('model1')
model2_id = fields.Many2one('model2')

@api.onchange('model1_id')
def onchange_model1_id(self):
for rec in self:
return {'domain': {'model2_id': [('model1_id', '=', rec.model1_id.id)]}}

Regards

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 10 22
3876
1
thg 1 22
3490
8
thg 2 17
8420
0
thg 1 17
5935
0
thg 12 15
5380