Skip to Content
Menu
This question has been flagged
3 Replies
4891 Views

Hai everyone  i want to auto fill the dropdown when i select from another dropdown list (based on dropdown choices)

i have a faculty field .when i select faculty name from the dropdown automatically fill the department and subject fields. but a faculty will teach 2 subjects i want to display 2 subjects in subjecct field then i will choose one subject how i will do please suggest me 

py file:

name = fields.Many2one('faculty_id.profile', string="Faculty Name",required= True)
    Date=fields.Date('Date of Attendance',default=fields.Date.today,readonly=True)
    subject=fields.Many2one('subjects.list',required=True)
    department_id=fields.Many2one('jntukstudent.department','Department',required=True)
  @api.onchange('name')
    def _onchange_name(self):
      if self.name:
        self.subject = self.name.subject
        self.department_id = self.name.department_id
    
   
  





Avatar
Discard
Best Answer

Hello

try below code

@api.onchange('name')
def _onchange_name(self):
    subject_lst = []
    if self.name:
        self.department_id = self.name.department_id
        subject_lst = [('id', 'in', list of subject ids)]  # for eg. subject_lst = [('id', 'in', [1])]
    return {'domain': {'subject': subject_lst}}
Avatar
Discard
Author Best Answer

Its not working subbarao

Avatar
Discard
Best Answer

Hello Varada,

please try this

@api.multi
@api.onchange('name')
 def _onchange_name(self):
      if self.name:
        self.subject = self.name.subject
        self.department_id = self.name.department_id

Avatar
Discard
Related Posts Replies Views Activity
2
Nov 24
25096
2
May 24
5519
3
Mar 24
4964
0
Mar 24
262
3
Feb 24
11421