Hi everyone, I asked please about a question in the file.xml how i can display a view depending on a field. for example,i have a module with a field married or not.i want to have a special view following the field
thank's
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
Hi everyone, I asked please about a question in the file.xml how i can display a view depending on a field. for example,i have a module with a field married or not.i want to have a special view following the field
thank's
In OpenERP is possibile to show or hide field in relation to another field (or fields) value. For example, if you have married field and boyfriend_name as field to show if married is true, you can use this system:
<field name="boyfriend_name" attrs="{'invisible':[('married', '!=', False)]}" />
You're telling to OpenERP to hide ({'invisible':...) the field boyfriend_name if married is not false (it's true!!)
Another example is the comparation with another type of field. For example a selection.
<field name="boyfriend_name" attrs="{'invisible':[('married', '!=', 'selection_key')]}" />
With this system you can create your view dinamically based on your field value
Hello, could you tell me how can i do that if the married field is in on another model?
If the field is in another class, you must insert a related field in the current class and set the attrs on this one.
It works great.
Exemple for label: http://gitlab.opengest.fr/opengest/odoo/blob/master/addons/account/views/account_invoice_view.xml#L233
Exemple for div:
Exemple for field:
Exemple for button:
not visible when condition is not false... *head explodes*
Hello, I have tried to compare to a string but it does not work:
<field name="x_studio_company_name_1" optional="show" attrs="{'invisible': [('location_id', '!=', 'Partner Locations/Customers/Rented out')]}"/>
Could you help me?
Hi,
You are using following which is correct for selection field:
attrs="{'invisible':[('lang_mat', '!=', 'eng')]}"
You can use another operators like : 'in' or 'not in' and check.
Email : info@acespritech.com
Skype : acespritech
Thank you for your answer it works now...I had an error on the bug windows :)
You can add an invisible field on your view (invisible="1") relating to a function field in your model. There you can evolve by anything you want and return a stringm bool or number and so in to evaluate if another field is visible or maybe readonly:
The View:
<field name="write_if_manager" attrs="{'readonly':['|',('is_manager', '==', 'false'),('state','not in','['draft']') ] }/>
<field name="is_manager" invisible="1"/>
The class looks like
class classname(osv.osv):
...
def _is_manager(cr, uid, ids ...
res = {}
for this_id in ids:
if obj_users.has_group(cr, uid, 'MANAGER-GROUPNAME'):
res[this_id] = manager
return res
...
_columns = {
'is_manager':fields.function(_is_manager, type='boolean' ...
'write_if_manager':fields.char( ...)
Nice Its working good..
I have an issue please help me.
<record id="view_order_form_inherit" model="ir.ui.view">
<field name="name">sale.order.form</field>
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_order_form"/>
<field name="arch" type="xml"><xpath expr="//field[@name='payment_term_id']" position="after"> <field name="head_option"/>
</xpath>
<xpath expr="//field[@name='order_line']/tree/field[@name='product_id']" position="before">
<field name="head" attrs="{'required':[('head_option','=',True)], 'invisible':[('head_option','=',False)]}"/>
</xpath>
he head option is a Boolean field that is in the sale order. and head option is in the sale order_line tree view..
so attrs can't work.
replay ur answers,...
You shoud create a related field. Exemple: http://gitlab.opengest.fr/opengest/odoo/blob/8.0/addons/sale/sale.py#L945
Hi,thank u for your answer;it work's with a boolean fields but i have an error when the type of field is a selection it doesn't work...
file.py
class student(osv.osv):
_name = 'student'
_order = 'name, prenom'
_description = 'Informations sur l etudiants'
_columns = {
'name': fields.char('Nom Famille', size=64),
'prenom': fields.char('Prenom', size=64),
'married':fields.boolean('marri'),
'boy':fields.char('boyfriend',size=30),
'lang_mat':fields.selection([('eng','English'), ('fr','French')], 'Langue Maternelle'),
'email':fields.char('E-mail',size=14),
}
student()
file.xml
<openerp>
<data>
<menuitem name="marriedbis" id="menu_stage_parent"/>
<menuitem name="enseignant" id="menu_enseignant_parent1" parent="menu_stage_parent"/>
<record model="ir.ui.view" id="view_school_student_form">
<field name="name">student.form</field>
<field name="model">student</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Information Eleve">
<field name="name" colspan="6" />
<field name="prenom" colspan="6"/>
<field name="married" colspan="6"/>
<field name="lang_mat" colspan="6"/>
<field name="boy" attrs="{'invisible':[('lang_mat', '!=', 'eng')]}" />
</form>
</field>
</record>
<record model="ir.ui.view" id="view_school_student_tree">
<field name="name">student.tree</field>
<field name="model">student</field>
<field name="type">tree</field>
<field name="arch" type="xml">
<tree string="stages.enseignant">
<field name="name"/>
<field name="prenom"/>
</tree>
</field>
</record>
<record model="ir.actions.act_window" id="action_school_student_form">
<field name="name">Eleves</field>
<field name="res_model">student</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
</record>
<!-- Et finalement il y a le menu qui contient l'action pour ouvrir la vue tree de ton module -->
<menuitem action="action_school_student_form" id="menu_stages_enseignant" parent="menu_enseignant_parent1" />
</data> </openerp>
The attrs values works witrh all the type of field. If you nedd to hide a field in relation a selection you must compare che field to show/hide with the selection field. I've updated my answer.
Thank you for you're answer;it works now :)
Create an account today to enjoy exclusive features and engage with our awesome community!
Sign up
How to visible and invisible fields in odoo: http://learnopenerp.blogspot.com/2016/10/how-to-visible-and-invisible-fields-in.html