Help

1

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

Avatar
Chaanto

Hello guys,

Let me give you some example

E.g : 

state = fields.Selection([
                                          ('1', '1 Years'), 
                                          ('2', '2 Years'),
                                          ('3', '3 Years'),
                                          ('4', '4 Years'),
                                          ('5', '5 Years'),
                                          ('6', '6 Years')], 
                                          string='Period'')

there is 2 boolean e.g : bool_assosiate and bool_professional

if bool_associate :

                  hide 2 - 4 - 6 Years

if bool_professional :              

                  hide 1 - 3 - 5 years

it will hidden based on that condition in xml view

Thank you,
Best Regards,
Chaanto


1 Comment
Avatar
Discard
Avatar
Mital Vaghani
-

Do you want to hide it in statusbar?

3 Answers
1
Avatar
Bharat Devnani
Best Answer

Hi Chaanto,


There are two ways you can achieve:

1) Creating two selection fields, show relevant selection field based on your requirement and hide using attrs

2) Creating Many2one fields and hiding the unwanted records based on domain.


Hope this helps. 



Avatar
Discard
0
Best Answer

To add more context to this question, can you please provide the information of those 2 boolean fields that you are using? These fields values are default on record init, or accessible through self._context?. 

According to these additional context, you can create model method, or method to return a list of (value, string), through selection=method (fields.Selection attribute), with the initial list (1,2,3,4,5,6) as default variable on top of your code.

Avatar
Discard
0
Avatar
Andrei Borcea
Best Answer

In the statusbar is easy to hide you need to set the invisible attribute attrs="{'invisible':['|',('condition','goes','here')]}"... but if i understand correctly you need to show different selection range based on a boolean condition so the best solution is to split the selection in 2 selections and use an invisible with the boolean condition that show or hide your elements

1 Comment
Avatar
Discard
Avatar
Chaanto
-

the problem is how i can hide that option, if i using invsible syntax that should be hide all option on the selection field, but what i need is hide a few option in the selection field, just like my example when i choose associate boolean 2 - 4 - 6 years option should be gone and will show 1 - 3 - 5 years

Thank You,

Best Regards,

Chaanto