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

i want filter levels based on stage i use onchange:

    models mk.stage:

#any stage have multi level

class mk_stage(models.Model):
    _name = 'mk.stage'
    _description = 'Student Stage'

    name = fields.Char(string='Stage')
    max_number = fields.Integer(string='Max number of Stages')
    level_ids = fields.Many2many(
        'mk.levels','stage_level_rel','stage_id',
        'level_id', string='Levels'
    )

models level:

class mk_levels(models.Model):
    _name = 'mk.levels'
    _description = 'Student Level'

    name = fields.Char(srting = 'Student Level')


model mk.link.student

in this model i want when select stage filter level base any stage have levels in class mk_stage

class mk_link_student(models.Model):
    _name = 'mk.link.student'
    _description = 'Link Student With Stage'
    _rec_name = 'name_stage_id'

    name_stage_id = fields.Many2one(
        'mk.stage',string='Name Stage',
    )

    level_id = fields.Many2one(
        'mk.levels',
        string='Levels'
    )

@api.onchange('name_stage_id')
    def onchange_domain_on_days(self):
        res = {}
        ids = []
        level_model = self.env['mk.link.student']
        all_stage = self.search([])
        print all_stage, 'OOOOOOOOOOOOOOOOOOOOOOO'
        for level_rec in all_stage:
            print level_rec, '?????????????????'
      
            if level_rec.level_id == self.name_stage_id.level_ids:
                ids.append(level_rec.id)
        res['domain'] = {
            'level_id': [('id', 'in', ids)],
        }
        return res

Avatar
Discard
Author

yes solved thank you Dhaval

Best Answer

Hi

It seems that onchange is improper. Please try following code.

@api.onchange('name_stage_id')
def onchange_domain_on_days(self):
    res = {'domain': {
          'level_id': [('id', 'in', self.name_stage_id.level_ids.ids)]
          }}
    return res


Hope it will solve your issue.

Avatar
Discard
Author

yes solved Dhaval thank you