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

Hi all,

I need to add more selection option to an existing field, can i replace(Am not aware of the after affects of replacing an existing fields) the same with my new options or is there any other methods for this.

Thanks in advance

Ảnh đại diện
Huỷ bỏ
Tác giả

Thanks @Niyas Raphy and @Cybrosys Techno Solutions Pvt.Ltd for your quick response

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

Hi,

For adding new values to an existing selection field in Odoo, you can do it by using the selection_add , see the below example,

alias_contact = fields.Selection(selection_add=[('employees', 'Authenticated Employees')])

Original field definition:


alias_contact = fields.Selection([
('everyone', 'Everyone'),
('partners', 'Authenticated Partners'),
('followers', 'Followers only')], default='everyone',
string='Alias Contact Security', required=True,
help="Policy to post a message on the document using the mailgateway.\n"
"- everyone: everyone can post\n"
"- partners: only authenticated partners\n"
"- followers: only followers of the related document or members of following channels\n")

Thanks

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

Hi,

Replacing an existing field is not a good option. For extending an existing selection field you can use the method selection_add. For reference you can use the below example

field_name = fields.Selection(selection_add=[('name', 'display_name')])

Hope it helps

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

Odoo 16 


field_name = fields.Selection(selection_add=[('name', 'display_name'), ('name', 'display_name'), ('name', 'display_name')])
field_name2 = ['display_name']

When I tried to use a comparison in domain search. It is not working.

all = self.env["field_name module"].search([("type",=,"field_name2")]) 

But working to search by name. it is not working to search by display name

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
0
thg 4 22
4021
1
thg 5 22
2914
6
thg 1 24
13826
1
thg 10 19
5682
4
thg 1 19
5469