Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
2 Trả lời
31101 Lượt xem

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...

Ảnh đại diện
Huỷ bỏ

Please check the following link for custom module:

https://youtu.be/Xya_fCNr6tw

Thanks & Regards

Câu trả lời hay nhất

@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>

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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!

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
Time field in odoo Đã xử lý
3
thg 3 20
43022
2
thg 12 17
17059
0
thg 4 15
4068
1
thg 3 15
9585
1
thg 12 24
1683