ODOO选择在某些条件下隐藏某些选项

2024-04-18 22:04:52 发布

您现在位置:Python中文网/ 问答频道 /正文

我在xml文件中有一个customer_类型选择字段,但我需要根据条件隐藏4个选择中的2个

enter image description here

到目前为止,这是我用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)]}"/>

我的情况是

vendor_state = 'vendor'

Tags: andtruepartnertyperescashcustomerxml
1条回答
网友
1楼 · 发布于 2024-04-18 22:04:52

安德里温·马昆托

不要在字段中添加key, value,而是尝试使用该方法添加

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

相关问题 更多 >