Files
Odoo-Modules/fusion-plating/fusion_plating_cgp/models/hr_employee.py
gsinghpal be611876ad changes
2026-04-12 09:09:50 -04:00

75 lines
2.4 KiB
Python

# -*- coding: utf-8 -*-
# Copyright 2026 Nexa Systems Inc.
# License OPL-1 (Odoo Proprietary License v1.0)
# Part of the Fusion Plating product family.
from dateutil.relativedelta import relativedelta
from odoo import api, fields, models
class HrEmployee(models.Model):
"""Extend hr.employee with CGP-specific fields.
Uses the ``x_fc_`` prefix on every new field, per Fusion Central
convention for extensions to base Odoo models.
"""
_inherit = 'hr.employee'
x_fc_cgp_psa_id = fields.Many2one(
'fusion.plating.cgp.psa',
string='Current PSA',
help='The current Personnel Security Assessment on file for '
'this employee.',
)
x_fc_cgp_psa_status = fields.Selection(
[
('not_assessed', 'Not Assessed'),
('current', 'Current'),
('expiring', 'Expiring'),
('expired', 'Expired'),
],
string='PSA Status',
compute='_compute_x_fc_cgp_psa_status',
store=False,
)
x_fc_cgp_ai = fields.Boolean(
string='Authorized Individual',
help='This employee is an Authorized Individual under the '
'Controlled Goods Program.',
)
x_fc_cgp_access_level = fields.Selection(
[
('none', 'No Access'),
('general', 'General Access'),
('controlled_area', 'Controlled Area'),
('designated_official', 'Designated Official'),
],
string='CGP Access Level',
default='none',
help='Level of physical access this employee has to CGP areas.',
)
@api.depends(
'x_fc_cgp_psa_id',
'x_fc_cgp_psa_id.state',
'x_fc_cgp_psa_id.expiry_date',
)
def _compute_x_fc_cgp_psa_status(self):
today = fields.Date.context_today(self)
warn_cutoff = today + relativedelta(months=3)
for rec in self:
psa = rec.x_fc_cgp_psa_id
if not psa or psa.state != 'completed':
rec.x_fc_cgp_psa_status = 'not_assessed'
continue
expiry = psa.expiry_date
if not expiry:
rec.x_fc_cgp_psa_status = 'current'
elif expiry < today:
rec.x_fc_cgp_psa_status = 'expired'
elif expiry <= warn_cutoff:
rec.x_fc_cgp_psa_status = 'expiring'
else:
rec.x_fc_cgp_psa_status = 'current'