【问题标题】:ODOO Selection - Hide some option on certain conditionsODOO 选择 - 在某些条件下隐藏某些选项
【发布时间】:2021-01-07 17:56:56
【问题描述】:

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

到目前为止,这是我在 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'

【问题讨论】:

    标签: python odoo odoo-13


    【解决方案1】:

    安德烈温·马昆托

    不要在字段中添加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')]
    

    【讨论】:

    • 我已经尝试过了。我确实写了我的条件 self.vendor_state == 'vendor' 它不返回 true 我尝试打印 self.vendor_state 它返回 false,它应该是 'vendor'
    • self 是一个空记录集,您不能使用字段值。
    猜你喜欢
    • 2023-01-10
    • 2014-09-23
    • 2015-10-20
    • 2013-08-15
    • 1970-01-01
    • 1970-01-01
    • 2022-01-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多