This question has been flagged
3 Replies
6494 Views

Hi All,


How to hide some value in selection field based on condition ?

 

v13community


request_hour_from = fields.Selection([
('0', '12:00 AM'), ('0.5', '0:30 AM'),
('1', '1:00 AM'), ('1.5', '1:30 AM'),
('2', '2:00 AM'), ('2.5', '2:30 AM'),
('3', '3:00 AM'), ('3.5', '3:30 AM'),
('4', '4:00 AM'), ('4.5', '4:30 AM'),
('5', '5:00 AM'), ('5.5', '5:30 AM'),
('6', '6:00 AM'), ('6.5', '6:30 AM'),
('7', '7:00 AM'), ('7.5', '7:30 AM'),
('8', '8:00 AM'), ('8.5', '8:30 AM'),
('9', '9:00 AM'), ('9.5', '9:30 AM'),
('10', '10:00 AM'), ('10.5', '10:30 AM'),
('11', '11:00 AM'), ('11.5', '11:30 AM'),
('12', '12:00 PM'), ('12.5', '0:30 PM'),
('13', '1:00 PM'), ('13.5', '1:30 PM'),
('14', '2:00 PM'), ('14.5', '2:30 PM'),
('15', '3:00 PM'), ('15.5', '3:30 PM'),
('16', '4:00 PM'), ('16.5', '4:30 PM'),
('17', '5:00 PM'), ('17.5', '5:30 PM'),
('18', '6:00 PM'), ('18.5', '6:30 PM'),
('19', '7:00 PM'), ('19.5', '7:30 PM'),
('20', '8:00 PM'), ('20.5', '8:30 PM'),
('21', '9:00 PM'), ('21.5', '9:30 PM'),
('22', '10:00 PM'), ('22.5', '10:30 PM'),
('23', '11:00 PM'), ('23.5', '11:30 PM')], string='Hour from')


Avatar
Discard
Author Best Answer

Thank you Kiran.

it is done by below code


request_hour_from = fields.Selection(string="Hour from", selection='_get_valid_hours', default='8.5')

@api.model
def _get_valid_hours(self):
selection = [
('8.5', '8:30 AM'),
('9', '9:00 AM'), ('9.5', '9:30 AM'),
('10', '10:00 AM'), ('10.5', '10:30 AM'),
('11', '11:00 AM'), ('11.5', '11:30 AM'),
('12', '12:00 PM'), ('12.5', '12:30 PM'),
('13', '1:00 PM'), ('13.5', '1:30 PM'),
('14', '2:00 PM'), ('14.5', '2:30 PM'),
('15', '3:00 PM'), ('15.5', '3:30 PM'),
('16', '4:00 PM'), ('16.5', '4:30 PM'),
('17', '5:00 PM')
]
return selection


Avatar
Discard
Best Answer

Hi, can I do an if-else condition? It seems not working to me

study_program = fields.Boolean('Study')

work_program = fields.Boolean('Work')

stage_select = fields.Selection(string='Stage', selection='_stage_filter')

 

    @api.model

    @api.onchange('study_program','work_program')

    def _stage_filter(self):

        if self.study_program:

            selection = [('s1', 'S1'),('s2', 'S2')]

            return selection

        if self.work_program:

            selection = [('w1', 'W1'), ('w2', 'W2')]

            return selection

 

Avatar
Discard
Best Answer

Hi ,

Please Refer

http://justodoo.blogspot.com/2019/02/how-to-show-selection-values-based-on.html

Avatar
Discard