Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
749 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 Answer

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')]

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...