Skip to Content
Menu
This question has been flagged
3 Replies
7581 Views

Hi,

I wanted to overwrite the state field in sale order so that i add new values and delete existing ones.

for adding i used the attribute selection_add  and it works fine. but for deleting it does not.

state = fields.Selection(selection_add=[('a','AA'),('b','BB')],  selection_remove=['draft'])

is this the correct syntax to do that (deleting i mean) ?

Avatar
Discard
Best Answer

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):
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 !

Avatar
Discard
Best Answer

Simple way to do it is to override the field it self.

class ma_class(models.Model) : 
	​_inherit = "sale.order"
	​state = fields.Selection([ ('draft', 'Quotation'), ('sent', 'Quotation Sent'), ('sale',       'Sales Order'),('done','Locked'), ('cancel', 'Cancelled'), ], string='Status',    readonly=True, copy=False, index=True,track_visibility='onchange', 
track_sequence=3, default='draft')


Avatar
Discard
Best Answer

Hello,

I think there is no param called selection_remove, you check here

Thanks

Avatar
Discard
Author

Thank you ahmed for your response. I guessed so too.