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

Hi Guys, Good to see you again!

I tried to remove the one option from the selection field but it's again showing up and the actual code is below

Model Name is hr.leave.type

request_unit = fields.Selection([
('day', 'Day'), ('half_day', 'Half Day'), ('hour', 'Hours')],
default='day', string='Take Time Off in', required=True)

Changed Code

class TrailLeaveTypes(models.Model):
_inherit = 'hr.leave.type'
request_unit = fields.Selection([('day', 'Day'), ('half_day', 'Half Day')], default='day', string='Take Time Off in', required=True)
Ảnh đại diện
Huỷ bỏ

Same problem here in Odoo 15

Câu trả lời hay nhất
Hi dear ones,

To remove options from an odoo 15 selection field, proceed as follows:

Example:

Basic model

class SurveyQuestion(models.Model):
_name = 'survey.question'

​question_type = fields.Selection([
('text_box', 'Multiple Lines Text Box'),
('char_box', 'Single Line Text Box'),
('numerical_box', 'Numerical Value'),
('date', 'Date'),
('datetime', 'Datetime'),
('simple_choice', 'Multiple choice: only one answer'),
('multiple_choice', 'Multiple choice: multiple answers allowed'),
('matrix', 'Matrix')], string='Question Type',
compute='_compute_question_type', readonly=False, store=True)

*****************************************************************************

Inheritance model

class SurveyQuestionInherited(models.Model):
_inherit = 'survey.question'

question_type = fields.Selection(selection='_get_new_question_type', string='Type de question', compute='_compute_question_type', readonly=False, store=True)

@api.model
def _get_new_question_type(self):
"""Cette methode permet de mettre à jour les type de question,
Dans le but de retirer les options 'multiple_choice' et 'matrix'
"""
selection = [
('text_box', 'Zone de texte à plusieurs lignes'),
('char_box', 'Zone de texte sur une seule ligne'),
('numerical_box', 'Valeur numérique'),
('date', 'Date'),
('datetime', 'Date et heure'),
('simple_choice', 'Choix multiple : une seule réponse')
]
return selection

After several unsuccessful attempts, this method worked for me.

I really hope it helps !
Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

you may refer the blow link having similar question:

https://www.odoo.com/forum/help-1/how-to-remove-item-from-selection-94279

Thanks & Regards,



CandidRoot Solutions Pvt. Ltd.

Mobile: (+91) 8849036209
Email: 
info@candidroot.com
Skype: live:candidroot
Web: https://www.candidroot.com
Address: 1229-1230, Iconic Shyamal, Near Shyamal Cross Road, Ahmedabad, Gujarat 380015
    

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

hello 

I have the same problem , did you solve it?

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 9 22
1900
1
thg 2 21
2710
1
thg 7 25
2330
2
thg 7 25
7810
2
thg 7 25
4210