Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
756 views
in Technique[技术] by (71.8m points)

python - ODOO Selection - Hide some option on certain conditions

I have a customer_type selection field in xml file but i need to hide 2 out of 4 selections that depends on condition.

enter image description here

So far this is my code in python

res_partner.py

customer_type = fields.Selection([
        ('cash_customer','Cash Customer'),
        ('credit_customer','Credit Customer'),
        ('cash_customer_vendor','Cash Customer and Vendor'),
        ('credit_customer_vendor','Credit Customer and Vendor')],
        string="Customer Type" )

res_partner.xml

<field name="customer_type" 
       attrs="{'required': 
       [('customer_tick', '=', True)],
       'invisible': [('customer_tick', '!=', True)]}"/>

My condition is

vendor_state = 'vendor'
question from:https://stackoverflow.com/questions/65617589/odoo-selection-hide-some-option-on-certain-conditions

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Andrywin Maquinto

Instead of add the key, value in the field try to add with the method.

customer_type = fields.Selection(selection="_get_customer_type", string="Customer Type")

def _get_customer_type(self):
    if self: # your codnition to check
        return [('cash_customer', 'Cash Customer'), ('credit_customer', 'Credit Customer'),
                ('cash_customer_vendor', 'Cash Customer and Vendor'),
                ('credit_customer_vendor', 'Credit Customer and Vendor')]
    else:
        return [('cash_customer', 'Cash Customer'), ('credit_customer', 'Credit Customer')]

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...