Search code examples
pythonxmlpython-3.xpython-2.7odoo

Removing items from an Existing Selection in Odoo


I have pre-existing keys in a selection in a contact form. I added new keys using "selection_add" parameter and I wanted to find out what would be the opposite of a selection_add parameter to remove any old keys from a selection.


Solution

  • There isn't any selection_remove option, unfortunately. You could redefine the field's selection value entirely, removing the option(s) you don't want.

    If a field is defined with:

    class ResPartner(models.Model):
        _name = 'res.partner'
    
        some_field = fields.Selection(string='Some Field',
                                      selection=[('a', 'A'),  ('b', 'B'), ('c', 'C')])
    

    Then you can inherit the class and override the field's selection value

    class ResPartner(models.Model):
        _inherit = 'res.partner'
    
        some_field = fields.Selection(selection=[('a', 'A'),  ('b', 'B')])
    

    Odoo Fields Documentation