This commit is contained in:
gsinghpal
2026-04-26 15:05:17 -04:00
parent 160198edb1
commit d9f58b9851
110 changed files with 6210 additions and 1182 deletions

View File

@@ -23,3 +23,12 @@ from . import fp_operator_certification
from . import fp_tz
from . import res_company
from . import res_config_settings
# Phase 1 (Sub 11) — relocated from fusion_plating_bridge_mrp via
# fusion_plating_jobs to core, so other downstream modules
# (fusion_plating_cgp, etc.) that touch hr.employee can see the
# shop-roles fields without a transitive dep on jobs.
from . import fp_work_role
from . import fp_proficiency
from . import hr_employee
from . import fp_process_node_inherit

View File

@@ -40,3 +40,15 @@ class FpJobStepTimeLog(models.Model):
log.duration_minutes = delta.total_seconds() / 60.0
else:
log.duration_minutes = 0.0
@api.depends('user_id', 'date_started', 'duration_minutes')
def _compute_display_name(self):
for log in self:
user = log.user_id.name or 'User'
when = log.date_started.strftime('%Y-%m-%d %H:%M') if log.date_started else ''
mins = ('%.0f min' % log.duration_minutes) if log.duration_minutes else 'open'
rec_bits = [user]
if when:
rec_bits.append(when)
rec_bits.append(mins)
log.display_name = ' · '.join(rec_bits)

View File

@@ -0,0 +1,23 @@
# -*- coding: utf-8 -*-
# Copyright 2026 Nexa Systems Inc.
# License OPL-1 (Odoo Proprietary License v1.0)
# Part of the Fusion Plating product family.
from odoo import fields, models
class FpProcessNode(models.Model):
"""Tag each recipe operation with the shop role that performs it.
The auto-assigner reads this when generating WOs: each WO inherits
its operation node's role, then hunts for an employee with a
matching x_fc_work_role_ids membership.
"""
_inherit = 'fusion.plating.process.node'
x_fc_work_role_id = fields.Many2one(
'fp.work.role', string='Performed By (Role)',
ondelete='set null',
help='Shop role that performs this step. When the WO is '
'generated it auto-routes to an employee with this role.',
)

View File

@@ -0,0 +1,163 @@
# -*- coding: utf-8 -*-
# Copyright 2026 Nexa Systems Inc.
# License OPL-1 (Odoo Proprietary License v1.0)
# Part of the Fusion Plating product family.
#
# Phase 1 (Sub 11) — relocated from fusion_plating_bridge_mrp. The model
# never had MRP fields; the bridge module was just its initial home.
from markupsafe import Markup
from odoo import _, api, fields, models
class FpOperatorProficiency(models.Model):
"""Operator proficiency tracker — counts successful step completions
per (employee, role) pair and auto-promotes the employee once the
role's mastery threshold is crossed.
The promotion mechanic lets managers casually train workers on the job:
they assign someone a task they've never done, the worker finishes it
successfully, and after N successes the role is added to the
employee's Shop Roles automatically. The operator never has to fill
in a form; their growing skill set just unlocks itself.
"""
_name = 'fp.operator.proficiency'
_description = 'Fusion Plating — Operator Task Proficiency'
_rec_name = 'display_name'
_order = 'employee_id, role_id'
employee_id = fields.Many2one(
'hr.employee', string='Operator',
required=True, ondelete='cascade', index=True,
)
role_id = fields.Many2one(
'fp.work.role', string='Role',
required=True, ondelete='cascade', index=True,
)
completed_count = fields.Integer(
string='Completions',
default=0,
help='Number of times this operator has successfully finished a '
'step that required this role.',
)
first_completed_at = fields.Datetime(
string='First Success',
help='When the operator finished their first step for this role.',
)
last_completed_at = fields.Datetime(
string='Last Success',
help='Most recent step completion against this role.',
)
promoted = fields.Boolean(
string='Promoted',
default=False,
index=True,
help='True once the role has been added to the operator\'s Shop '
'Roles automatically. Stays True even if a manager removes '
'the role afterwards — the count and promotion history are '
'preserved as a training record.',
)
promoted_at = fields.Datetime(
string='Promoted On',
help='When the auto-promotion fired (count crossed the role\'s '
'mastery threshold).',
)
display_name = fields.Char(
compute='_compute_display_name', store=True,
)
progress_label = fields.Char(
compute='_compute_progress_label',
help='"3 / 5" style indicator of how close this operator is to '
'mastery.',
)
_sql_constraints = [
('fp_proficiency_uniq',
'unique(employee_id, role_id)',
'There is already a proficiency record for this operator and role.'),
]
@api.depends('employee_id.name', 'role_id.name')
def _compute_display_name(self):
for rec in self:
rec.display_name = (
f'{rec.employee_id.name or "?"}{rec.role_id.name or "?"}'
)
@api.depends('completed_count', 'role_id.mastery_required')
def _compute_progress_label(self):
for rec in self:
target = rec.role_id.mastery_required or 0
rec.progress_label = (
f'{rec.completed_count} / {target}' if target
else str(rec.completed_count)
)
@api.model
def _record_completion(self, employee, role):
"""Increment the (employee, role) tally and promote if at threshold.
Idempotent for the (employee, role) pair — if no record exists,
we create one. Always uses sudo() because the worker may not
have write access to their own profile.
"""
if not employee or not role:
return self.browse()
rec = self.sudo().search([
('employee_id', '=', employee.id),
('role_id', '=', role.id),
], limit=1)
now = fields.Datetime.now()
if rec:
new_count = rec.completed_count + 1
rec.write({
'completed_count': new_count,
'last_completed_at': now,
})
else:
rec = self.sudo().create({
'employee_id': employee.id,
'role_id': role.id,
'completed_count': 1,
'first_completed_at': now,
'last_completed_at': now,
})
rec._maybe_promote()
return rec
def _maybe_promote(self):
for rec in self:
if rec.promoted:
continue
target = rec.role_id.mastery_required or 0
if target <= 0:
continue
if rec.completed_count < target:
continue
employee = rec.employee_id
role = rec.role_id
already_assigned = role in employee.x_fc_work_role_ids
rec.sudo().write({
'promoted': True,
'promoted_at': fields.Datetime.now(),
})
if already_assigned:
continue
employee.sudo().write({
'x_fc_work_role_ids': [(4, role.id)],
})
employee.message_post(
body=Markup(_(
'<b>%(name)s promoted</b> — qualified for '
'<b>%(role)s</b> after %(count)s successful '
'completions.'
)) % {
'name': employee.name,
'role': role.name,
'count': rec.completed_count,
},
subtype_xmlid='mail.mt_note',
)

View File

@@ -0,0 +1,62 @@
# -*- coding: utf-8 -*-
# Copyright 2026 Nexa Systems Inc.
# License OPL-1 (Odoo Proprietary License v1.0)
# Part of the Fusion Plating product family.
#
# Phase 1 (Sub 11) — relocated from fusion_plating_bridge_mrp. The model
# never had MRP fields; the bridge module was just its initial home.
from odoo import api, fields, models
class FpWorkRole(models.Model):
"""A shop role assigned to a recipe step and to the employees who
can perform it.
Shops run the same part with different staffing models:
- One employee does every step (small shop): give them every role.
- Specialists per operation (masking person, racker, plater): one
role each.
- Cross-trained workers: multiple roles per worker.
The model is intentionally flat — no hierarchy, no workflow. Roles
are just tags that the step auto-assignment compares.
"""
_name = 'fp.work.role'
_description = 'Fusion Plating — Shop Work Role'
_order = 'sequence, code'
name = fields.Char(string='Role Name', required=True, translate=True)
code = fields.Char(string='Code', required=True,
help='Short stable identifier used in auto-assignment.')
sequence = fields.Integer(default=10)
description = fields.Char(
string='Description',
help='Short operator-facing description of what this role covers.',
)
icon = fields.Selection(
[('fa-scissors', 'Scissors (masking)'),
('fa-cogs', 'Cogs (racking)'),
('fa-flask', 'Flask (plating)'),
('fa-fire', 'Fire (oven)'),
('fa-search', 'Inspection'),
('fa-wrench', 'Wrench (rework)'),
('fa-user', 'Generic worker')],
string='Icon', default='fa-user',
)
active = fields.Boolean(default=True)
mastery_required = fields.Integer(
string='Mastery Threshold',
default=lambda self: self._default_mastery_required(),
help='Number of successful step completions a worker needs on this '
"role before they're added to its qualified-operators list "
'automatically. 1 = promote on first success; 3 = solid '
"default for everyday roles; 5+ for tasks that need real "
'practice. Defaults from Settings > Fusion Plating > '
'Default Mastery Threshold.',
)
@api.model
def _default_mastery_required(self):
return self.env.company.x_fc_default_mastery_threshold or 3

View File

@@ -0,0 +1,161 @@
# -*- coding: utf-8 -*-
# Copyright 2026 Nexa Systems Inc.
# License OPL-1 (Odoo Proprietary License v1.0)
# Part of the Fusion Plating product family.
from odoo import api, fields, models
class HrEmployee(models.Model):
"""Tag employees with the shop roles they can perform.
An employee with role 'masking' receives the masking steps when WOs
are generated; an employee with multiple roles receives WOs for all
of them. A small shop where the owner wears every hat just tags
themselves with every role.
Lead hands are a separate per-role list — they don't have to be
primary owners of those roles, but they're authorised to step in
when the regular owner is absent or behind. The Manager Desk
promotes lead hands above other workers in its dropdown for any
role they cover.
"""
_inherit = 'hr.employee'
x_fc_work_role_ids = fields.Many2many(
'fp.work.role', 'fp_employee_work_role_rel',
'employee_id', 'role_id', string='Shop Roles',
help='Which shop roles this employee performs. Used by the '
'Manager Desk and auto-assignment on WO generation. '
'Roles are added automatically when an employee completes '
'a task that meets the role mastery threshold.',
)
# Per-role lead-hand list. Sarah might be a lead hand for masking +
# racking but not for plating; Mike might cover everything during
# a graveyard shift. Stored on a separate relation table so the
# primary "Shop Roles" list stays distinct from the cover-anything
# authority.
x_fc_lead_hand_role_ids = fields.Many2many(
'fp.work.role', 'fp_employee_lead_hand_role_rel',
'employee_id', 'role_id', string='Lead Hand For',
help='Roles where this employee is authorised to lead or cover '
'for an absent operator. Lead hands are surfaced first in '
'the Manager Desk worker picker for these roles.',
)
x_fc_proficiency_ids = fields.One2many(
'fp.operator.proficiency', 'employee_id',
string='Task Proficiency',
help='Per-role completion tally. Workers earn one count per WO '
'they finish on a given role. Once the count crosses the '
"role's mastery threshold the role is added to their "
'Shop Roles list automatically.',
)
# ------------------------------------------------------------------
# Attendance helpers — used by the Manager Desk to show who is
# currently clocked in. Works with vanilla hr_attendance or the
# full fusion_clock module — both store an open record (no
# check_out) for as long as the employee is on shift.
# ------------------------------------------------------------------
x_fc_is_clocked_in = fields.Boolean(
string='Clocked In',
compute='_compute_x_fc_is_clocked_in',
search='_search_x_fc_is_clocked_in',
help='True if this employee currently has an open hr.attendance '
'record (clocked in but not clocked out).',
)
def _compute_x_fc_is_clocked_in(self):
"""Compute attendance status from hr.attendance.
Batched so the manager dashboard doesn't issue one query per
employee — important when the shop has dozens of operators.
"""
if not self:
return
Att = self.env.get('hr.attendance')
if Att is None:
for emp in self:
emp.x_fc_is_clocked_in = False
return
# One read for the whole recordset.
open_emp_ids = set(Att.sudo().search([
('employee_id', 'in', self.ids),
('check_out', '=', False),
]).mapped('employee_id').ids)
for emp in self:
emp.x_fc_is_clocked_in = emp.id in open_emp_ids
def _search_x_fc_is_clocked_in(self, *args):
"""Lets `[('x_fc_is_clocked_in', '=', True)]` work as a domain.
Two compounding gotchas surfaced after fusion_clock auto-closed
the demo open attendances:
1. Odoo 19 normalises ``('=', True)`` into
``('in', OrderedSet([True]))`` before invoking the search
method. The previous code only handled ``=`` / ``!=`` and
fell through to ``return []`` for ``in`` / ``not in`` —
which Odoo treats as "no constraint" and matches every
row.
2. ``('id', 'in', [])`` is also treated as no-constraint in
some Odoo versions; replaced with a ``[0]`` sentinel so
the empty-open-list case correctly matches nothing.
Strategy: reduce caller intent to a *match_set* of booleans
(which values of ``x_fc_is_clocked_in`` should match), flip on
negative operators, then translate into ``id IN`` / ``NOT IN``
on the cached open-attendance employee ids. Variable signature
future-proofs against Odoo's compute-field API shifting again.
"""
# Variable signature — Odoo 19 may pass (records, op, val).
if len(args) == 3:
_records, operator, value = args
elif len(args) == 2:
operator, value = args
else:
return [('id', '=', False)]
Att = self.env.get('hr.attendance')
if Att is None:
return [('id', '=', False)]
if operator in ('=', '!='):
match_set = {bool(value)}
elif operator in ('in', 'not in'):
match_set = set(map(bool, value))
else:
return [('id', '=', False)]
# Negated operators flip the match set.
if operator in ('!=', 'not in'):
match_set = {True, False} - match_set
if not match_set:
return [('id', '=', False)]
if match_set == {True, False}:
return [] # every row matches
open_emp_ids = Att.sudo().search(
[('check_out', '=', False)]
).employee_id.ids
ids_term = open_emp_ids or [0]
return [('id', 'in' if True in match_set else 'not in', ids_term)]
@api.model
def _fp_clocked_in_user_ids(self):
"""Return the set of res.users.ids whose linked employee is on shift.
Used by the Manager Desk controller to short-circuit the worker
dropdown to "present today" without an N+1 attendance query
per worker.
"""
Att = self.env.get('hr.attendance')
if Att is None:
return set()
emps = Att.sudo().search([
('check_out', '=', False),
]).mapped('employee_id')
return set(emps.user_id.ids)