Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

add extra options to selection field using inheritance? [Closed]

By
Eric
on 2/27/14, 2:41 PM 2,019 views

The Question has been closed

by
Sudhir Arya (SA)
on 02/28/2014 03:44:46

Hello everyone, does anyone know if you inherit a model and inherit all the fields with it, can you add more selections to a selection field in the inherited model. For example, if I have a new module that inherits the res.partner table and I want to add more selections to the "type" field, then can I add those new selections in the new module without having to add them to the original module? I know you can create new fields to the inherited model, but I'm not sure you can modify the original fields by giving them more options to choose from like the selection fields. Thank you everyone

Okay so I tested it out to see what it does, and it turns out that it does add the new selections that were added in the inherited module. However, it overwrote the original selections with the new ones. So if you are going to add more selections to choose from in the inherited module, then make sure to also include the original selections, if you don't want to lose them.

Eric
on 2/27/14, 2:58 PM

@sudhir: your answer is not what he has asked, you should not have closed his question with wrong answer.

John
on 3/30/15, 9:09 AM

Hi, in new api the correct way is to use selection_add attribute as in the documentation: class openerp.fields.Selection(selection=None, string=None, **kwargs) Bases: openerp.fields.Field Parameters: selection – specifies the possible values for this field. It is given as either a list of pairs (value, string), or a model method, or a method name. selection_add – provides an extension of the selection in the case of an overridden field. It is a list of pairs (value, string). The attribute selection is mandatory except in the case of related fields or field extensions.

Pouya Maleki
on 9/19/15, 6:31 AM

Sorry for the mess, but the question is closed and i cannot add an answer, in one sentence , just write: state= fields.Selection(selection_add=[('in_progress','In Progress')])

Pouya Maleki
on 9/19/15, 6:34 AM
0

Sudhir Arya (SA)

--Sudhir Arya (SA)--
10150
| 6 8 8
Ahmedabad, India
--Sudhir Arya (SA)--

Working as an OpenERP/Odoo developer and a Team Leader 

Top 5 Odoo contributor On Stackoverflow

LinkedIn

Blog

Stackoverflow

Sudhir Arya (SA)
On 2/27/14, 6:17 PM

Yes Eric you can do so. But for that you have to include original values with you new values.

Ex: Original value is 'state': fields.selection([('draft', 'New')])

Now I want to add some more values by inherit the object and override the field like this:

'state': fields.selection([('draft', 'New'), ('in_progress', ' In Progress')])

Hope this will help you.

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

0 follower(s)

Stats

Asked: 2/27/14, 2:41 PM
Seen: 2019 times
Last updated: 9/19/15, 6:34 AM