# -*- 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 FpCgpPsa(models.Model): """Personnel Security Assessment. Every person — employee, contractor, or long-term visitor — who has access to controlled goods must have a current Personnel Security Assessment on file. PSAs are valid for up to five years and include a review of citizenship, criminal record, and loyalty considerations. PSA records are restricted via ``ir.rule`` so that only the CGP Officer and Designated Official can see them. A regular plating manager cannot see personnel assessments. """ _name = 'fusion.plating.cgp.psa' _description = 'Fusion Plating — Personnel Security Assessment' _inherit = ['mail.thread', 'mail.activity.mixin'] _order = 'assessment_date desc, id desc' name = fields.Char( string='Reference', required=True, copy=False, readonly=True, default=lambda self: self._default_name(), tracking=True, ) employee_id = fields.Many2one( 'hr.employee', string='Employee', required=True, tracking=True, ) assessment_date = fields.Date( string='Assessment Date', tracking=True, ) assessed_by_id = fields.Many2one( 'res.users', string='Assessed By', default=lambda self: self.env.user, tracking=True, ) result = fields.Selection( [ ('pass', 'Pass'), ('conditional_pass', 'Conditional Pass'), ('fail', 'Fail'), ], string='Result', tracking=True, ) expiry_date = fields.Date( string='Expiry Date', tracking=True, help='PSAs are typically valid for five years.', ) notes = fields.Html( string='Internal Notes', help='Internal notes — restricted to CGP Officer and above.', ) document_ids = fields.Many2many( 'ir.attachment', 'fp_cgp_psa_attachment_rel', 'psa_id', 'attachment_id', string='Supporting Documents', help='Restricted-access supporting documents (criminal record ' 'check, references, etc.).', ) state = fields.Selection( [ ('draft', 'Draft'), ('in_progress', 'In Progress'), ('completed', 'Completed'), ('expired', 'Expired'), ], string='Status', default='draft', required=True, tracking=True, ) company_id = fields.Many2one( 'res.company', string='Company', default=lambda self: self.env.company, ) active = fields.Boolean(default=True) @api.model def _default_name(self): seq = self.env['ir.sequence'].next_by_code('fusion.plating.cgp.psa') return seq or '/' @api.model_create_multi def create(self, vals_list): for vals in vals_list: if not vals.get('name') or vals.get('name') == '/': vals['name'] = self._default_name() return super().create(vals_list) @api.onchange('assessment_date') def _onchange_assessment_date(self): """Default expiry to five years after assessment.""" for rec in self: if rec.assessment_date and not rec.expiry_date: rec.expiry_date = rec.assessment_date + relativedelta(years=5) def action_start(self): self.write({'state': 'in_progress'}) def action_complete(self): self.write({'state': 'completed'}) def action_expire(self): self.write({'state': 'expired'}) def action_reset_to_draft(self): self.write({'state': 'draft'})