跳至内容
菜单
此问题已终结

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"

形象
丢弃
相关帖文 回复 查看 活动
1
5月 24
3713
1
3月 21
4128
1
3月 15
5718
3
11月 24
45458
1
1月 23
2240