How to hide a field in a model from a other function model?
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- Müşteri İlişkileri Yönetimi
- e-Commerce
- Muhasebe
- Envanter
- PoS
- Project
- MRP
Bu soru işaretlendi
Hi Duvan,
You cannot hide a field from the py file using attrs. Either use attrs in XML or if your condition is complex then you can create a boolean field, change its value from onchange / compute field and use it in attrs.
role = # your role field definition
hide = field.Boolean(string='Hide', compute="_compute_hide")
@api.depends('role')
def _compute_hide(self):
# simple logic, but you can do much more here
if self.role == 'testrole':
self.hide = True
else:
self.hide = False
Then in the XML,
<field name="fieldToHide" attrs="{'invisible':[('hide', '=', True)]}" />
To hide a field you can do it by code in the debug mode. Simply got to the location where the field is displayed and edit the form view. Search the field you want to hide an write something like this:
style="display: none;" (behind or before the field name)
Hope it helps. Regards
Hi,
In Python functions, it is not possible to hide a field in a model. However, you can achieve this through Odoo's XML view or by using groups.
1. To hide a field using XML view, you can add the "invisible" attribute to the field and set it to "1". This will hide the field in the view.
For example:
<field name="my_field" invisible="1"/>
2. Another Way, To hide a field using groups, first, you need to define a group by creating a record for it in the "res.groups" model. For example:
<record id="my_module.my_group" model="res.groups"> <field name="name">My Group</field> </record>
Then, you can add the group to the field's access rights using the "groups" attribute. For example:
<field name="my_field" groups="my_module.my_group"/>
Regards
Enjoying the discussion? Don't just read, join in!
Create an account today to enjoy exclusive features and engage with our awesome community!
Üye Ol
But with python in a function?