Files
Odoo-Modules/fusion_clock/models/clock_role.py
gsinghpal b4ca85e291 feat(fusion_clock): native shift roles (fusion.clock.role) [A1-A3]
Replaces Odoo Planning's planning.role: name+colour model with the same
1-11 palette, employee default/allowed role fields, Employee Roles editor,
role_id on shift template + schedule with default resolution, ACLs, menus.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-04 20:42:04 -04:00

47 lines
1.6 KiB
Python

# -*- coding: utf-8 -*-
# Copyright 2026 Nexa Systems Inc.
# License OPL-1 (Odoo Proprietary License v1.0)
#
# Native shift role. Re-implements the small, useful subset of Odoo
# Enterprise ``planning.role`` (name + colour) so Fusion Clock can colour and
# label shifts on the portal without depending on the Enterprise Planning app.
from random import randint
from odoo import fields, models
class FusionClockRole(models.Model):
_name = 'fusion.clock.role'
_description = 'Clock Shift Role'
_order = 'sequence, name'
_rec_name = 'name'
def _get_default_color(self):
return randint(1, 11)
name = fields.Char(required=True, translate=True)
color = fields.Integer(default=_get_default_color)
active = fields.Boolean(default=True)
sequence = fields.Integer(default=10)
company_id = fields.Many2one(
'res.company',
string='Company',
default=lambda self: self.env.company,
)
# Kanban colour code (1-11) -> hex, mirroring planning.role._get_color_from_code
# so the portal Schedule tab shows the same palette Planning used.
_COLOR_HEX = {
0: '#008784', 1: '#EE4B39', 2: '#F29648', 3: '#F4C609',
4: '#55B7EA', 5: '#71405B', 6: '#E86869', 7: '#008784',
8: '#267283', 9: '#BF1255', 10: '#2BAF73', 11: '#8754B0',
}
def _get_color_from_code(self, is_open_shift=False):
"""Return a hex colour for this role. Open shifts get an '80' alpha
suffix (matching Planning's open-shift transparency convention)."""
self.ensure_one()
hex_value = self._COLOR_HEX.get(self.color, '#008784')
return hex_value + ('80' if is_open_shift else '')