Odoo Help

0

Hide one field when another change

By
Christophe dos Santos
on 9/2/13, 11:01 AM 1,848 views

Hi,

I'm trying to hide one field without sucess. I saw a lot of examples but I can't solve my case.

I create a new module hr_payroll_sn, with hr_payroll_sn.py and hr_payroll_sn_view.xml files.

In the py file, I have a class which inherit hr.employee and I add a new integer field wife_number.

I want to hide the wife_number field when the field marital change, but it doesn't work. The xml file is below:

 <openerp>
    <data>
        <record id="hr_payroll_sn_employee_view_form" model="ir.ui.view">
            <field name="name">hr.payroll.sn.employee.view.form</field>
            <field name="model">hr.employee</field>
            <field name="inherit_id" ref="hr.view_employee_form"/>
            <field name="arch" type="xml">
                <data>
                    <field name="marital" on_change="onchange_marital(marital)" position="after">
                        <field name="wife_number" 
                               attrs="{'invisible': [('marital','!=', 'married')]}"/>
                    </field>
                </data>
            </field>
        </record>
    </data>
   </openerp>

Can you post the value of the field you declare in the .py ?

Tuxservices, Jeudy Nicolas
on 9/4/13, 10:13 AM

I have a last problem with this module, I don't understand why it doesn't execute the on_change method in the following tag: <field name="marital" on_change="onchange_marital(marital)" position="after">

Else IT, Christophe dos Santos
on 9/7/13, 11:09 AM

see my answer, i think it will work next :)

Tuxservices, Jeudy Nicolas
on 9/10/13, 10:36 AM
1

Jeudy Nicolas

--Jeudy Nicolas--
1181
| 6 7 8
Pelousey, France
--Jeudy Nicolas--

- Linux administrator - Functional guy with OpenERP - Python, html, css, javascript developer OpenERP Ready Partner

Jeudy Nicolas
On 9/10/13, 10:35 AM

hi, your on_change is not correctly set, try this:

<openerp>
<data>
    <record id="hr_payroll_sn_employee_view_form" model="ir.ui.view">
        <field name="name">hr.payroll.sn.employee.view.form</field>
        <field name="model">hr.employee</field>
        <field name="inherit_id" ref="hr.view_employee_form"/>
        <field name="arch" type="xml">
            <data>
                <field name="marital"  position="replace">
                      <field name="marital" on_change="onchange_marital(marital)" />
                    <field name="wife_number" 
                           attrs="{'invisible': [('marital','!=', 'married')]}"/>
                </field>
            </data>
        </field>
    </record>
</data>

</openerp>

Thank you Nicolas, it's work well!

Else IT, Christophe dos Santos
on 9/10/13, 2:27 PM
1

odoo.ma by IBS Group

--odoo.ma by IBS Group--
1302
| 4 5 8
Tétouan, Morocco
--odoo.ma by IBS Group--

For more informations about IBS, please visit our website at www.ibs-na.com.

For a specific questions, collaboration or help, please send us an email to support@ibs-na.com

odoo.ma by IBS Group
On 9/2/13, 3:11 PM

Try this instead :

<field name="wife_number" attrs="{'invisible': [('marital','&lt;&gt;', 'married')]}"/>

Thank you for your response Karim, but it doesn't work.

Else IT, Christophe dos Santos
on 9/2/13, 3:38 PM
0

The code is nice. I had to update the module. Thank you for your help.

can you say what is the nice code ?

Tuxservices, Jeudy Nicolas
on 9/3/13, 7:29 PM

The code above, where we are: <field name="wife_number" attrs="{'invisible': [('marital','!=', 'married')]}"/>/>

Else IT, Christophe dos Santos
on 9/4/13, 9:23 AM

I have a last problem with this module, I don't understand why it doesn't execute the on_change method in the following tag: <field name="marital" on_change="onchange_marital(marital)" position="after">

Else IT, Christophe dos Santos
on 9/7/13, 11:09 AM
0

Jeudy Nicolas

--Jeudy Nicolas--
1181
| 6 7 8
Pelousey, France
--Jeudy Nicolas--

- Linux administrator - Functional guy with OpenERP - Python, html, css, javascript developer OpenERP Ready Partner

Jeudy Nicolas
On 9/3/13, 7:28 PM

Hello,

To have the correct behaviour, you should add this correct line:

<field name="wife_number" attrs="{'invisible': [(marital,'!=', 'married')]}"/>

Be carrefull, marital as no '' in the attrs value, because your are pointed the field (object) and not the string 'marital'

Nicolas, in attrs value, we have to put the field name into quote. The correct way is 'marital' not marital without quote.

Else IT, Christophe dos Santos
on 9/4/13, 9:26 AM

Yes it's true, I just test it :)

Tuxservices, Jeudy Nicolas
on 9/4/13, 10:12 AM

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

0 follower(s)

Stats

Asked: 9/2/13, 11:01 AM
Seen: 1848 times
Last updated: 3/16/15, 8:10 AM