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

i have a many2one field and i want that if certain value is selected a field must get invisible . There are many questions like that on the forum but nothing working for me. Please help

here is the code

py


class MaintNewCust(models.Model):
_inherit = 'maintenance.request'

number = fields.Char(string='Serial Number')
complaint_type = fields.Many2one('my.model',string='Complaint Type')
emr = fields.Selection([
('ws', 'Water Supply'),
('sui', 'Sui Gas'),('electric', 'Electric'),('SA', 'Split AC')], string='E & M', copy=False)
bbr = fields.Selection([
('fw', 'Finishing Work'),
('sf', 'Sanitary Fitting'), ('ss', 'Sewarage System'), ('fp', 'Footpaths'), ('rd', 'Roads'), ('ww', 'Wood Works')], string='B & R', copy=False)
used = fields.Boolean(string='Boolean')

@api.onchange('complaint_type')
def _onchange_type(self):
if self.complaint_type == "Buildings and roads":
self.used = True
else:
self.used = False
xml 

    <xpath expr="//field[@name='employee_id']" position="after">
<field name="complaint_type"/>
</xpath>
<xpath expr="//field[@name='maintenance_type']" position="after">
<field name="emr" attrs="{'invisible': [('used','==',False)]}"/>
</xpath>
<xpath expr="//field[@name='maintenance_type']" position="after">
<field name="bbr" attrs="{'invisible':[('used', '==', True)]}"/>
</xpath>

อวตาร
ละทิ้ง

How to visible and invisible fields in odoo: https://goo.gl/BCxCpk

คำตอบที่ดีที่สุด
<xpath expr="//field[@name='maintenance_type']" position="attributes">
<attribute name="attrs">{'invisible': [('used','=',False)]}</attribute>
</xpath>
อวตาร
ละทิ้ง
ผู้เขียน

i want fields name "emr" and "bbr" to be visible or invisible, not maintenance type. Sir how will this help?

<xpath expr="//field[@name='maintenance_type']" position="after">

<field name="emr" attrs="{'invisible':[('used', '=', False)]}"/>

<field name="bbr" attrs="{'invisible':[('used', '=', True)]}"/>

</xpath>

Related Posts ตอบกลับ มุมมอง กิจกรรม
1
ส.ค. 23
3849
0
พ.ย. 21
2882
Attrs multiple condition. Boolean AND. แก้ไขแล้ว
4
ต.ค. 21
80916
0
เม.ย. 21
5909
1
ธ.ค. 19
4175