如何向odoo中的选择字段添加过滤器

How to add a filter to selection field in odoo

我需要在 odoo 的选择字段中添加过滤器..

roomuser = fields.Selection([('stpi', 'Belongs to Park'),('Incubation', 'Belongs to Incubation companies'),('both', 'Belongs to Park& Incubation companies')],'Room Assignment',required=True)
roomType = fields.Selection([('meeting','Meeting Room'),('discussion','Discussion Room'),('auditorium','Auditorium'),('board','Board Room')],required=True)

这里我需要根据roomuser的值过滤roomType的值。假设 roomuser 值只有 auditorium 和 board 应该在 roomType

中可见

我已经发表了我的评论如下,恳请您在下面找到它,它可能对您的情况有所帮助:

class HotelManagement(models.Model):

    _name='hotel.management'
@api.model      
def _get_room_type_list(self):
    # [('meeting','Meeting Room'),('discussion','Discussion Room'),('auditorium','Auditorium'),('board','Board Room')]
    vals=[]
    for record in self.env['hotel.management'].search([]):
        if record.roomuser in ['stpi','Incubation']  :
            vals.extend([('meeting','Meeting Room'),('discussion','Discussion Room')])
        if record.roomuser in ['both'] :
            vals.extend([('auditorium','Auditorium'),('board','Board Room')])
    return vals


def _get_roomuser_list(self):
    return [('stpi', 'Belongs to Park'),
                            ('Incubation', 'Belongs to Incubation companies'),
                            ('both', 'Belongs to Park& Incubation companies')]


roomType=fields.Selection(string="Room Type", selection=_get_room_type_list, default='meeting', required=True)
roomuser = fields.Selection(string="Room Assignment",selection=_get_roomuser_list ,required=True)

这里我只是把@api.model放在上面_get_room_type_list并遍历这个(hotel.management)模型中的所有记录并过滤选择字段。