Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to hide field depend on condition odoo?

attrs="{'invisible': [('rule_id.type_test', '!=', 'A')]}" in code above not work, how i can fix this?

class test_list(models.Model):
    _name = 'test.list'

    type_test = fields.Selection([('A', 'aaaa'),('B','bbbbb')], default='A', string="Type", required=True)  
    rule_list = fields.One2many('test.rule', 'rule_id')

class test_rule(models.Model):
    _name = 'test.rule'

    rule_id = fields.Many2one('test.list', required=True)

    ul = fields.Many2one('product.ul', string='Package Logistic Unit'

<record model="ir.ui.view" id="rules_form_view">
            <field name="name">test.rules.form.view</field>
            <field name="model">test.rule</field>
            <field name="arch" type="xml">
                <form string="Test Rules">
                   <field name="ul" attrs="{'invisible': [('rule_id.type_test', '!=', 'A')]}"/> 
                </form>
            </field>
</record>
like image 512
Astr0 Avatar asked Feb 03 '15 16:02

Astr0


1 Answers

The fields you use in attrs need to be present in the current view.

You can add this field to model:

class test_rule(models.Model):
    _name = 'test.rule'

    rule_id = fields.Many2one('test.list', required=True)
    type_test = fields.Selection(related='rule_id.type_test')
    ul = fields.Many2one('product.ul', string='Package Logistic Unit')

And then to your form:

<form string="Test Rules">
    <field name="type_test" invisible="1"/>
    <field name="ul" attrs="{'invisible': [('type_test', '!=', 'A')]}"/> 
</form>
like image 111
Ludwik Trammer Avatar answered Sep 23 '22 19:09

Ludwik Trammer