How to add a filter to selection field in odoo

2019-07-29 17:02发布

I need to add a filter to a selection field in 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)

Here i need to filter the value of roomType based on the value of roomuser. Suppose roomuser value is both only auditorium and board should be visible in roomType

标签: odoo-9
1条回答
聊天终结者
2楼-- · 2019-07-29 17:38

I have made my comments as below , kindly request you to find it as below it may help in your case:

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)

Here i have just put @api.model on top _get_room_type_list and traversing all the record in this(hotel.management) model and filtering the selection field .

查看更多
登录 后发表回答