Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
3 Odpowiedzi
2420 Widoki

How to hide a field in a model from a other function model?

Awatar
Odrzuć
Autor

But with python in a function?

Najlepsza odpowiedź

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)]}" />


Awatar
Odrzuć
Najlepsza odpowiedź

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

Awatar
Odrzuć
Najlepsza odpowiedź

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

Awatar
Odrzuć