Odoo Help

Welcome!

This community 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.

0

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

By
chirra
on 2/25/16, 4:10 AM 1,049 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

--Axel Mendoza--
10203
| 7 7 8
Camaguey, Cuba
--Axel Mendoza--

DevOps - Full stack - Software Architect - Developer - Technology Integrator

I could help you to develop anything and solve complex problems based on technologies, integrations and tricky stuffs mostly in Python with OpenERP/Odoo, Zato, Django and many others frameworks programming languages and technologies.

I offers consulting services to anyone with an unanswered questions or needs for customizations. Think about it, maybe it's better to have an expert to solve your issues and projects than having a full time employee trying to understand what to do an how

Reach me at aekroft@gmail.com

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

--Akhil P Sivan--
3423
| 5 3 6
Kochi, India
--Akhil P Sivan--

Interested in exploring Odoo both technically & functionality wise.

email-id : akhilpsivan01@gmail.com

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>

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 2/25/16, 4:10 AM
Seen: 1049 times
Last updated: 2/25/16, 6:47 AM