Files
Odoo-Modules/fusion_plating/fusion_plating/models/fp_bath_log.py
gsinghpal 11837ed4f5 fix(plating): Manager Desk premature-advance + 6 workflow enforcement gates
**1. Manager Desk: WO no longer jumps to "In Progress" on partial setup**

User-reported bug: when the manager picked a worker, the WO immediately
left the "Unassigned" column even though the bath/tank (or oven, rack,
masking material) wasn't set yet. Worker would see a half-set job in
their queue and couldn't start it.

Fix:
- New compute `mrp.workorder.x_fc_is_release_ready` — True only when
  every field button_start would block on is filled in.
- Companion `x_fc_missing_for_release` — comma-list of what's still
  missing (used by the UI as a hint chip).
- Manager controller swaps the column filter from
  `assigned_user_id == False` to `is_release_ready == False`.
- A WO stays in "Setup Pending" (formerly Unassigned) until BOTH
  worker + per-kind equipment are set; only then does it move to
  "In Progress".

**Manager Desk template + SCSS**

The user also said "the manager doesn't know what task they're
assigning". WO row now shows:
  • Colour-coded WO-kind badge (wet=blue, bake=red, mask=yellow,
    rack=grey, inspect=green)
  • Required-role icon + name
  • Bath / oven / rack / masking-material chips (whatever's set)
  • Yellow "Needs: ..." chip listing what's still missing
  • Tank picker only shows for wet WOs (no point on a mask WO)
  • Open-WO button to drill into the form for advanced edits

**2. Six enforcement gates patched (without breaking the workflow)**

Each gate fires AFTER the manager sets up the WO and the operator
hits Start/Finish — never on create — so the manager → worker → run
flow stays intact.

| # | Gate | Where |
|---|---|---|
| a | SO confirm requires `client_order_ref` (or x_fc_po_number) | sale_order.action_confirm |
| b | Cert issue requires thickness readings (when partner.x_fc_strict_thickness_required) | fp_certificate.action_issue |
| c | Delivery start_route requires assigned_driver_id | fp_delivery.action_start_route |
| d | Bath log create/save requires line_ids (no empty logs) | fp_bath_log create + @api.constrains |
| e | Quality hold: hold_reason + description now `required=True` | fp_quality_hold field schema |
| f | Receiving accept blocks qty mismatch (manager override allowed + logged) | fp_receiving.action_accept |

New partner flag `x_fc_strict_thickness_required` so commercial
customers don't get blocked but aerospace customers do.

**Verified** via `scripts/fp_enforcement_audit.py`: 18/22 ENFORCED
(2 "GAPS" + 2 "ERRs" are all test artifacts — admin bypass + NOT NULL
fires before my custom check; real gates are correct).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-19 12:54:00 -04:00

177 lines
5.5 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 odoo import _, api, fields, models
from odoo.exceptions import ValidationError
class FpBathLog(models.Model):
"""A daily / per-shift chemistry log for a bath.
One log record represents one sampling event: an operator walks to a
tank, runs titrations or reads instruments, and enters the results.
Each log has one or more lines (one per parameter).
Overall log status is rolled up from the lines:
* ok — every line is within target
* warning — at least one line is within warning tolerance
* out_of_spec — at least one line is outside target
"""
_name = 'fusion.plating.bath.log'
_description = 'Fusion Plating — Bath Chemistry Log'
_inherit = ['mail.thread', 'mail.activity.mixin']
_order = 'log_date desc, id desc'
_rec_name = 'display_name'
name = fields.Char(
string='Reference',
required=True,
copy=False,
default=lambda self: self._default_name(),
tracking=True,
)
display_name = fields.Char(
compute='_compute_display_name',
store=True,
)
bath_id = fields.Many2one(
'fusion.plating.bath',
string='Bath',
required=True,
ondelete='cascade',
tracking=True,
)
tank_id = fields.Many2one(
related='bath_id.tank_id',
store=True,
readonly=True,
)
facility_id = fields.Many2one(
related='bath_id.facility_id',
store=True,
readonly=True,
)
process_type_id = fields.Many2one(
related='bath_id.process_type_id',
store=True,
readonly=True,
)
company_id = fields.Many2one(
related='bath_id.company_id',
store=True,
readonly=True,
)
log_date = fields.Datetime(
string='Logged At',
default=fields.Datetime.now,
required=True,
tracking=True,
)
operator_id = fields.Many2one(
'res.users',
string='Operator',
default=lambda self: self.env.user,
tracking=True,
)
shift = fields.Selection(
[
('day', 'Day'),
('evening', 'Evening'),
('night', 'Night'),
],
string='Shift',
)
line_ids = fields.One2many(
'fusion.plating.bath.log.line',
'log_id',
string='Readings',
copy=True,
)
status = fields.Selection(
[
('ok', 'OK'),
('warning', 'Warning'),
('out_of_spec', 'Out of Spec'),
],
string='Status',
compute='_compute_status',
store=True,
tracking=True,
)
status_color = fields.Integer(
compute='_compute_status_color',
)
notes = fields.Text(
string='Notes',
)
# ==========================================================================
@api.model
def _default_name(self):
seq = self.env['ir.sequence'].next_by_code('fusion.plating.bath.log')
return seq or '/'
@api.constrains('line_ids')
def _check_has_readings(self):
"""A bath log without readings is a useless empty record — it
pollutes daily-chemistry reports and the trend graphs assume
every log carries data. Block save until at least one reading.
Note: @api.constrains only fires when line_ids is in the
write/create vals. The create() override below catches the
"no line_ids in vals at all" case so callers can't sneak past.
"""
for rec in self:
if not rec.line_ids:
raise ValidationError(_(
'Bath log "%(name)s" needs at least one parameter '
'reading before it can be saved.\n\nAdd readings via '
'the "Readings" tab (or the Tablet Station\'s Log '
'Chemistry button).'
) % {'name': rec.display_name or rec.name or ''})
@api.model_create_multi
def create(self, vals_list):
for vals in vals_list:
if not vals.get('line_ids'):
raise ValidationError(_(
'A bath log must include at least one parameter '
'reading. Pass `line_ids` with at least one line '
'in the create call (or use the Tablet Station\'s '
'Log Chemistry button which adds them for you).'
))
return super().create(vals_list)
@api.depends('name', 'bath_id', 'log_date')
def _compute_display_name(self):
for rec in self:
parts = []
if rec.bath_id:
parts.append(rec.bath_id.name)
if rec.log_date:
parts.append(fields.Datetime.to_string(rec.log_date))
rec.display_name = ''.join(parts) if parts else rec.name
@api.depends('line_ids', 'line_ids.status')
def _compute_status(self):
for rec in self:
statuses = set(rec.line_ids.mapped('status'))
if 'out_of_spec' in statuses:
rec.status = 'out_of_spec'
elif 'warning' in statuses:
rec.status = 'warning'
else:
rec.status = 'ok'
@api.depends('status')
def _compute_status_color(self):
# Kanban color indexes: 0 default, 1 red, 3 yellow, 4 green
mapping = {'ok': 4, 'warning': 3, 'out_of_spec': 1}
for rec in self:
rec.status_color = mapping.get(rec.status, 0)