As the title said,
I need to add some fields that would be available on every modules, as default. They are phone number, room, and extension number. Almost all internal modules are using the phone number to send real time notification, paging the intercom, and many other things. So, I think it would be best to add it to res.users
rather than search those values on another module for every single module made.
I can modify the res.users
module, but I think that wouldn't be a good way to do it. But at the same time, if I make a new model to inherit the res.users
, it won't be used by odoo either.
So, what is the proper way to add it so that it is available for all modules by default?
Thank you
There already is a phone number field on res.users inherited by its res.partner see here.
Adding fields to res.users isn't that complicated, you just have to override/extend 2 special properties (SELF_READABLE_FIELDS
and SELF_WRITEABLE_FIELDS
) to make them readable and writeable, an example can be found here:
class User(models.Model):
_inherit = "res.users"
leave_manager_id = fields.Many2one(related='employee_id.leave_manager_id')
show_leaves = fields.Boolean(related='employee_id.show_leaves')
allocation_count = fields.Float(related='employee_id.allocation_count')
leave_date_to = fields.Date(related='employee_id.leave_date_to')
current_leave_state = fields.Selection(related='employee_id.current_leave_state')
is_absent = fields.Boolean(related='employee_id.is_absent')
allocation_remaining_display = fields.Char(related='employee_id.allocation_remaining_display')
allocation_display = fields.Char(related='employee_id.allocation_display')
hr_icon_display = fields.Selection(related='employee_id.hr_icon_display')
@property
def SELF_READABLE_FIELDS(self):
return super().SELF_READABLE_FIELDS + [
'leave_manager_id',
'show_leaves',
'allocation_count',
'leave_date_to',
'current_leave_state',
'is_absent',
'allocation_remaining_display',
'allocation_display',
'hr_icon_display',
]