Odoo Help

0

How to make a field invisible using compute field based on a condition?

By
chirra
on 2/25/16, 4:10 AM 2,636 views

Hi,

Is it possible to use a computed field to make a particular field invisible based on a condition?

is it possible using compute field?
If the answer is yes, how can this effect be visible in the view?

Please help me

0
Axel Mendoza
On 2/25/16, 5:23 AM

@chirra

You could use it like a normal field, for example:

<field name="make_invisible" invisible="1"/>
<field name="field_x" attrs="{'invisible':[('make_invisible', '=', True)]}"/>

Just note that the fields functions just compute it's value when the form is saved. You could assign a default_value for the function field or change it's value using an onchange.

Hi Axel Mendoza i need invisible the filed through python code only for field level security my issue like this: . When we want to invisible a field conditionally in same group, we using domains to “attrs”. Using browser inspect element feature we can simply remove “oe_invisible” css class and remove the invisible logic.

chirra
on 2/25/16, 6:41 AM

then change the view by override of the method fields_view_get and deal with xml nodes

Axel Mendoza
on 2/26/16, 9:18 PM
0
Akhil P Sivan
On 2/25/16, 6:47 AM

Hi,

I think you may use a compute boolean field, that becomes true or false based on the condition. You can make another field visible or invisible using the "attrs" attribute, based on that boolean field. You may note that onchange is default on compute fields and it also compute the values, when you open or edit in form view.

For example, you may see the following example, in that, if the value of field1 is "Any_String", the field2 will be invisible.

in .py file:

class test_model(models.Model):

_name = "test.model"


field1 = fields.Many2one('another.model', String="First field")

check = fields.Boolean(compute='_get_value')

field2 = fields.Char(String="Second field")


@api.one

@api.depends('field1')

def _get_value(self):

if self.field1.name == "Any_String":

self.check = True

else:

self.check = False

in xml file:

    <record model="ir.ui.view" id="test_model_form_view">

<field name="name">test.model.form.view</field>

<field name="model">test.model</field>

<field name="arch" type="xml">

                 <group>

                    <field name="field1" />

                    <field name="check" invisible="1" />

                    <field name="field2" attrs="{'invisible':[('check', '=', True)]}"


</field>

</record>

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

Register

Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)

Stats

Asked: 2/25/16, 4:10 AM
Seen: 2636 times
Last updated: 11/20/17, 6:24 PM