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

Hello, I would like to create a checkbox that makes another float field invisible or visible. I tried using the "invisible" attribute but it doesn't work. Please help me.

อวตาร
ละทิ้ง

share code, what you have tried?

คำตอบที่ดีที่สุด
Try this code:
อวตาร
ละทิ้ง

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

ผู้เขียน คำตอบที่ดีที่สุด

.


อวตาร
ละทิ้ง
ผู้เขียน

Here is the code in my python file
class InheritSaleOrder(models.Model):
_inherit = 'sale.order'

overall_discount = fields.Boolean('Remise globale')
amount_overall_discount = fields.Float(string='Montant de la remise globale', invisible=True)

In my xml file:
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="view_overall_discount" model="ir.ui.view">
<field name="name">view.order.form.inherit</field>
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_order_form"/>
<field name="arch" type="xml">
<xpath expr="//form//sheet//notebook" position="after">
<field name="overall_discount"/>
<field name="amount_overall_discount"
attrs="{'invisible': [('overall_discount', '=', False)]}"/>
</xpath>
</field>
</record>
</odoo>

When I run it, it doesn't show the text "Remise globale" and "Montant de la remise globale" in the view.

To see label (name of field) of your fields you must insert them inside <group></group> tag. Or add label tag seperatly:
<label for="your_field_name"/>

ผู้เขียน

I solve it by putting all my fields in a group. Thanks for your help.

ผู้เขียน

Yes that's what I did, thanks.