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

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 Need :

When I choice value 'Ocean' from field  freight_type I want to filter ship_type to show only values ('FCL','fcl')


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 , 






Аватар
Отменить
Лучший ответ

Hello Eyad,
Hope you are doing well.

Find Code in Comment. 

Thanks & Regards,
Email: odoo@aktivsoftware.com
Skype: kalpeshmaheshwari

Аватар
Отменить

add freight_type onchange

@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 = ''

Автор Лучший ответ

Thank you for your answer,

When I select 'Ocean' I need that ship_type to be 2 value 'FCL' and 'LCL' , not only one value 

ship_type is a selection , so it can contains many values not one value only

Аватар
Отменить
Автор

Thank you for your answer,

When I select 'Ocean' I need that ship_type to be 2 value 'FCL' and 'LCL' , not only one value

ship_type is a selection , so it can contains many values not one value only

Лучший ответ

Hello!

You can use compute method in your field ship_type like this: compute ="_compute_ship" 

after that define the function _compute_ship

@api.depends('freight_type')

def _compute_ship(self):

    for rec in self:

        if rec.freight_type:

            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"

Аватар
Отменить
Related Posts Ответы Просмотры Активность
1
мая 24
3713
1
мар. 21
4128
1
мар. 15
5718
3
нояб. 24
45458
1
янв. 23
2240