Skip to Content
Меню
Вам необхідно зареєструватися, щоб взаємодіяти зі спільнотою.
Це запитання позначене
1 Відповісти
3711 Переглядів

Hello All 

first of all , thanks in advanced :)


I have the Following 2 fields:

freight_type = fields.Selection(
[('Ocean', 'Ocean'), ('Air', 'air'), ('Land', 'Land')],
default='',
required=True
)


ship_type = fields.Selection(
[('FCL', 'fcl'), ('LCL', 'lcl'), ('Air', 'air'), ('Land', 'land')],
default='',
required=True
)
What I tried:

@api.onchange('freight_type')
def onchange_freight_type(self):
for rec in self:
if rec.freight_type == 'Ocean':
rec.ship_type = 'FCL'
elif rec.freight_type == 'Air':
rec.ship_type = 'Air'
elif rec.freight_type == 'Land':
rec.ship_type = 'Land'
else:
rec.ship_type = ''


Not what I need, cause  rec.ship_type may have values 

[('FCL', 'fcl'), ('LCL', 'lcl')] or one value
[('Air', 'air')]



What I Need :

When I choice value 'Ocean' from field  freight_type I want to filter ship_type to show only values

[('FCL', 'fcl'), ('LCL', 'lcl')]


When I choice value 'Air' from field  freight_type I want to filter ship_type to show only values

[('Air', 'air')]


When I choice value 'Land' from field  freight_type I want to filter ship_type to show only values

[('Land', 'land')]


So, the field ship_type  will show values which depends on field  freight_type 


regards , 


Аватар
Відмінити

If you don't need to show it in real time, did you think to do it in a computed field instead of the onchange

Найкраща відповідь

Hi,

Hi,

If you have limited selection options, you can achieve this by creating separate selection fields for each option and making them visible in XML based on the condition.

Python (.py):
freight_type = fields.Selection(
[('Ocean', 'Ocean'), ('Air', 'Air'), ('Land', 'Land')],
string='Freight Type',
default='',
required=True
)
ship_type_ocean = fields.Selection(
selection=[('FCL', 'FCL'), ('LCL', 'LCL')],
string='Ship Type'
)

ship_type_air = fields.Selection(
selection=[('Air', 'Air')],
string='Ship Type'
)
ship_type_land = fields.Selection(
selection=[('Land', 'Land')],
string='Ship Type'
)
ship_type_default = fields.Selection(
selection=[('Default', 'Default')],
string='Ship Type'
)

XML:

<field name="freight_type"/>
<field name="ship_type_ocean" invisible="freight_type != 'Ocean'" required="freight_type == 'Ocean'"/>
<field name="ship_type_air" invisible="freight_type != 'Air'" required="freight_type == 'Air'"/>
<field name="ship_type_land" invisible="freight_type != 'Land'" required="freight_type == 'Land'"/>


Hope it helps

Аватар
Відмінити
Related Posts Відповіді Переглядів Дія
3
трав. 22
4966
0
бер. 15
8910
1
трав. 24
2621
9
черв. 22
59596
1
бер. 21
4128