Skip to Content
Menu
This question has been flagged

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 , 






Avatar
Discard
Best Answer

Hello Eyad,
Hope you are doing well.

Find Code in Comment. 

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

Avatar
Discard

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

Author Best Answer

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

Avatar
Discard
Author

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

Best Answer

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"

Avatar
Discard
Related Posts Replies Views Activity
1
May 24
2720
1
Mar 21
2779
1
Mar 15
4687
3
Nov 24
43355
1
Jan 23
1062