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

​how Can I raise an error while user selecting multiple items from many2many fields. The user can select only one items if he select multiple items then I want to raise an error. Please help me. user_ids = fields.Many2many('res.users', string="Salesperson", required=False)

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

Hi Nahid Jawad Angon, 

First of all if you want to select only one record then you should use many2one field instead of many2many and if you use many2many purposefully then you can write constraints on that field like below.

Find code in comment.

I hope this will help you.

Thanks & Regards,
Email: odoo@aktivsoftware.com
Skype: kalpeshmaheshwari

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

Code :-
@api.constraints(user_ids)
def check_user_ids_lenght(self):
if len(user_ids) > 1:
raise usererror("Please select only one record for this field.")

Tác giả

Thank you

Tác giả Câu trả lời hay nhất

Thank you 

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