Перейти к содержимому
Меню
Чтобы взаимодействовать с сообществом, необходимо зарегистрироваться.
Этот вопрос был отмечен
1 Ответить
3713 Представления

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
4972
0
мар. 15
8915
1
мая 24
2621
9
июн. 22
59596
1
мар. 21
4128