Odoo Help

11 Answers
1/13/16, 11:48 AM

Hi, In V8 you have selection_add attribute, it can be used like

state = fields.Selection(selection_add=[('early_payment', 'Early payment: Discount early payment')])

Mohammad Alhashash

--Mohammad Alhashash--
| 5 5 8
October City, Egypt
--Mohammad Alhashash--


Mohammad Alhashash
3/2/13, 4:08 PM

Redefine the state field and make your module depending on sale_stock instead of sale (in __openerp__.py). That way, you insure your object will be the last to update the state field properties.

In OpenERP inheritance, when several classes try to update the same field, the last one will win.

You cannot use the __init__() because the inheritance tree is built after instantiation by the ORM. When __init__() is called, your object would not have sale_order class as an ancestor or pool attribute.

Poiesis Consulting, Nico Bustillos
3/6/13, 12:14 PM

Thank you. Indeed this simple change solves my particular problem. I guess in some other cases where the 3rd party addon is unknown this inherit issue could still be a problem. Fortunately, in my case 'sale_stock' is among the certified addons and I have no problem including it as a dependency. Thanks again.

Pouya Malekinejad
9/19/15, 6:37 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.


Cyril Gaspard (GEM)

--Cyril Gaspard (GEM)--

| 5 6 8
Paris, France
--Cyril Gaspard (GEM)--

Forum contributor since 2008

Cyril Gaspard (GEM)
3/2/13, 3:17 PM


to add a field type selection in the class, do like this :

class sale_order(osv.osv):
   _inherit = 'sale.order'
   _columns = {
       'state': fields.selection((('keyx', 'valuex'), ('keyz', 'valuez')), 'State'),
   _defaults = {
       'state': 'keyx',  

Hope this will help and work.


Poiesis Consulting, Nico Bustillos
3/6/13, 12:25 PM

This would be the standard way to add a value to any given 'selection' field and it usually works. The key problem here however is that there is a 3rd addon that does exactly that and is being priorized upon my own module, which ultimately gets ignored. But as you can see from the correct answer given, it is just a matter of making the dependencies lineal among the three addons (instead of both addons inheriting from a single one). Also note that I don't want to change my new value as the default one, as I still need 'draft' to be the initial state. Thanks a lot anyway.

Cyril Gaspard (GEM)
3/6/13, 4:57 PM

Hi, then you could use states parameter too, this will follow the workflow and depend not of the dependencies, it will overwrite all properties, see openerp developer documentation : http://doc.openerp.com/v6.1/developer/03_modules_2.html .thanks for the comment. Bye

7/31/13, 11:25 AM

Hi, Please note that super(...)._columns['state'] will only work if no other module has a _inherit to the same class. Otherwise, super(...)._columns may contain the columns added/modified by the other module.

To achieve this cleanly, the main class must be patched to make the state selection a class attribute. This has not been done for Sale Orders yet but it looks like something you could reasonably ask for. Check out Purchase Orders for example:

class purchase_order(osv.osv):
        ('draft', 'Draft PO'),
        ('sent', 'RFQ Sent'),
        ('confirmed', 'Waiting Approval'),
        ('approved', 'Purchase Order'),
        ('except_picking', 'Shipping Exception'),
        ('except_invoice', 'Invoice Exception'),
        ('done', 'Done'),
        ('cancel', 'Cancelled')
    _columns = {
        'state': fields.selection(STATE_SELECTION, 'Status', ...),

Then you can add states like this:

class PurchaseOrder (osv.osv):
    _inherit = 'purchase.order'    
    def __init__(self, pool, cr):
        """Add a new state value"""
        super(PurchaseOrder, self).STATE_SELECTION.append(('foo', 'Foo'))
        return super(PurchaseOrder, self).__init__(pool, cr)
Mohammad Alhashash
8/23/13, 9:57 AM

This is completely wrong. When __init__() method is called, the inherited class would not be in the MRO chain and is not reachable through super(). That is why the OP got the missing pool attribute error; the model was not initialized yet and has no pool attribute. This is not standard python inheritance. You can use init() method which is called by the ORM after initialization, but this will not solve the problem too.

Mohammad Alhashash
8/23/13, 9:58 AM

Having the list as a class attribute is irrelevant because model._columns['state'].selection is a reference to that list whether it is inline, class or module variable and using it is the most reliable way to reach the list. The problem of the OP was that sale_stock module is replacing the list with a new one that overrides his list. Check my answer for the correct solution.

Ask a Question
Keep Informed
3 follower(s)
About This Community

This platform 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.

Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now