Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
3 ตอบกลับ
2423 มุมมอง

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

อวตาร
ละทิ้ง