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

In Odoo 9:

i need create a field like check boxes:

what is your favorite color?  ☐ Blue  ☐Pink  ☐Yellow <--The user only can choice one favorite color, if the user select  ☐Blue then the  ☐Pink or  ☐Yellow field can not be selected, if the user select  ☐Pink, then  ☐Blue or  ☐Yellow can not be selected....

any idea how to create this type of field and function...

อวตาร
ละทิ้ง

Please check the following link for custom module:

https://youtu.be/Xya_fCNr6tw

Thanks & Regards

คำตอบที่ดีที่สุด

@Carlos

You could create boolean fields for every color and put those rules in the view definition, like:

from openerp import models, fields, api

class module_example(models.Model):

_name = 'module.example'


blue = fields.Boolean('Blue')

pink = fields.Boolean('Pink')

yellow = fields.Boolean('Yellow')

and in the xml:

<record id="module_example_form" model="ir.ui.view">

<field name="name">myquality list</field>

<field name="model">myquality.myquality</field>

<field name="arch" type="xml">

<form>

<group>

<field name="blue" attrs="{'invisible': [('pink','=',True),('yellow','=',True)]}"/>

<field name="pink" attrs="{'invisible': [('blue','=',True),('yellow','=',True)]}"/>

<field name="yellow" attrs="{'invisible': [('pink','=',True),('blue','=',True)]}"/>

</group>

</form>

</field>

</record>

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

Use Axel's answer. But in the condition, put '|' in front of the condition (for OR).

<field name="blue" attrs="{'invisible':['|',('pink','=',True),('yellow','=',True)]}"/>
<field name="pink" attrs="{'invisible':['|',('blue','=',True),('yellow','=',True)]}"/>
<field name="yellow" attrs="{'invisible':['|',('pink','=',True),('blue','=',True)]}"/>

If you use Axel's answer, it's AND, so it will only disappear when 2 options is selected. OP only wanted 1 selection, and the others disappear, meaning OR command.


Thansk Alex!

อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
Time field in odoo แก้ไขแล้ว
3
มี.ค. 20
42038
2
ธ.ค. 17
16278
0
เม.ย. 15
3545
1
มี.ค. 15
9098
1
ธ.ค. 24
1143