I want to extend the "state" column of the mrp.production model. There was an example I found in https://www.odoo.com/de_DE/forum/how-to/developers-13/how-to-extend-fields-selection-options-without-overwriting-them-21529 but it seems to not work in odoo 11.
i.e. the __init__
signature changed to __init__(self, pool, cr)
(guessing this from the error trace that I saw referencing model.__init__(pool, cr)
)
from odoo import models, fields
import logging
_logger = logging.getLogger(__name__)
class mrp_production(models.Model):
_inherit = 'mrp.production'
def __init__(self, pool, cr):
super(mrp_production, self).__init__(pool, cr)
states = self._columns['state'].Selection
_logger.debug('extend state of mrp.production')
state_other = ('other_state', 'My State')
if state_other not in states:
states.append(state_other)
The Error I'm receiving is:
AttributeError: 'mrp.production' object has no attribute '_columns'
You don't need to extend the __init__
. Please look into the documentation to get a first look how to extend odoo business models.
For your example the correct code:
from odoo import models, fields
class MrpProduction(models.Model):
_inherit = 'mrp.production'
state = fields.Selection(
selection_add=[('other_state', 'My State')])