如何在odoo中的选择字段中添加过滤器 [英] How to add a filter to selection field in odoo
本文介绍了如何在odoo中的选择字段中添加过滤器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要在odoo的选择字段中添加一个过滤器.
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)
在这里,我需要根据roomuser的值来过滤roomType的值.假设roomuser的值既是礼堂,又是板子,在roomType中应该可见
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
推荐答案
我的评论如下,请您如下查找,可能对您有帮助:
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)
在这里,我只是将@ api.model放在_get_room_type_list顶部,并遍历此(hotel.management)模型中的所有记录并过滤选择字段.
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 .
这篇关于如何在odoo中的选择字段中添加过滤器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文