콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
3 답글
2516 화면

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

아바타
취소
작성자

But with python in a function?

베스트 답변

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

아바타
취소