Is there a way to add custom field attribute in Odoo? For example every field has attribute help
where you can enter message explaining the field for the user. So I want to add custom attribute, so that would change the way field acts for all types of fields.
I want to add into Field
class, so all fields would get that attribute. But it seems no matter what I do, Odoo does not see that such attribute was added.
If I simply add new custom attribute like:
some_field = fields.Char(custom_att="hello")
Then it is simply ignored. And I need it to be picked up by method fields_get
, which can return wanted attribute value (info what it does:
def fields_get(self, cr, user, allfields=None, context=None, write_access=True, attributes=None):
""" fields_get([fields][, attributes])
Return the definition of each field.
The returned value is a dictionary (indiced by field name) of
dictionaries. The _inherits'd fields are included. The string, help,
and selection (if present) attributes are translated.
:param allfields: list of fields to document, all if empty or not provided
:param attributes: list of description attributes to return for each field, all if empty or not provided
"""
So calling it, does not return my custom attribute (it does return the ones originally defined by Odoo though).
I also tried updating _slots
(with monkey patch or just testing by changing source code) attribute in Field
class, but it seems it is not enough. Because my attribute is still ignored.
from openerp import fields
original_slots = fields.Field._slots
_slots = original_slots
_slots['custom_att'] = None
fields.Field._slots = _slots
Does anyone know how to properly add new custom attribute for field?