Files
Odoo-Modules/fusion_plating/fusion_plating_batch/models/fp_batch.py
gsinghpal 6658544f85 feat(fusion_plating): Tier 2 (quality + audit) and Tier 3 (business) features
Tier 2 — Quality & audit readiness:

- T2.1 SPC on thickness readings (fp.certificate)
  - spec_min_mils / spec_max_mils auto-pulled from coating config on create
  - Computed: std_dev_mils, min/max, cpk, cpk_status (incapable/marginal/
    capable/excellent/insufficient)
  - Western Electric trend rules (rule 1: any point beyond 3σ; rule 4:
    8 consecutive on one side of mean) → trend_alert + explanation
  - New SPC group on certificate form with badge-coloured indicators

- T2.2 Operator certification enforcement (fp.operator.certification)
  - Per (employee, process_type) records with issued/expires dates,
    training record attachment, revocation workflow
  - State auto-computed: active → expired when date passes
  - MrpWorkorder.button_start() blocks with UserError if current user's
    linked hr.employee lacks an active cert for the bath's process_type
  - Managers bypass the check; expiring-soon filter in search view
  - HR Employee form: "Plating Certifications" tab

- T2.3 Material traceability chain
  - fusion.plating.batch.workorder_id (new Many2one) + production_id
    (related through WO) for full chain
  - fp.certificate gets computed batch_ids / bath_ids / batch_count
  - "Batches" stat button → list of batches used for this cert's MO,
    with their chemistry logs intact

- T2.4 Pre-treatment as first-class baths
  - process_family selection on fusion.plating.process.type
    (pre_treatment / plating / post_treatment / bake / strip / passivation /
    masking / inspection)
  - Bath search view: Pre-Treatments / Plating / Post-Treatments / Strip
    quick filters
  - Existing bath infra (logs, replenishment, SPC) now applies to pre-
    treatment baths equally

Tier 3 — Business / revenue:

- T3.1 Customer-specific price lists (fp.customer.price.list)
  - Per (customer, coating_config) with unit_price + basis (per_part /
    sqin / sqft / lb)
  - effective_from / effective_to for annual contract pricing
  - min_quantity for volume breaks (cheapest price at requested qty wins)
  - _find_price() helper resolves active entry by date + qty
  - Direct Order wizard auto-fills unit_price on (partner, coating, qty)
    change unless operator has typed an override
  - Configurator menu → Customer Price Lists

- T3.2 Quote win/loss tracking (fp.quote.configurator)
  - State values: draft → confirmed (won) / lost / expired / cancelled
  - lost_reason selection (price / lead_time / tech / spec_mismatch /
    no_bid / no_response / competitor / other) + lost_competitor_name
    + lost_details text
  - Action buttons: Mark as Lost (requires reason), Mark as Expired
  - won_date auto-set on SO creation; lost_date auto-set on mark_lost
  - New "Win / Loss" tab on configurator form

- T3.3 Actuals vs. quoted margin (mrp.production)
  - Computed monetary fields: x_fc_consumables_cost, x_fc_labour_cost,
    x_fc_actual_cost, x_fc_quoted_revenue, x_fc_margin_actual,
    x_fc_margin_pct
  - Labour = sum(WO duration × workcentre cost_hour)
  - Revenue = SO amount_untaxed via mo.origin lookup
  - New "Job Costing" group on MO form with badge-coloured margin

- T3.4 Job consumables tracking (fp.job.consumption)
  - One row per consumable event (bath replenisher, masking tape, PPE,
    chemistry): product, qty, uom, unit_cost (snapshot), total_cost,
    source, optional workorder link
  - One2many x_fc_consumption_ids on mrp.production
  - "Consumables" stat button on MO → filtered list

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-16 23:55:22 -04:00

156 lines
4.7 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
class FpBatch(models.Model):
"""A rack or barrel load of parts being processed through a tank.
Lifecycle:
draft → loading → in_process → unloading → complete
(any non-complete state) → cancelled
"""
_name = 'fusion.plating.batch'
_description = 'Plating Batch (Rack/Barrel Load)'
_inherit = ['mail.thread', 'mail.activity.mixin']
_order = 'create_date desc'
name = fields.Char(
string='Batch Reference',
required=True,
copy=False,
readonly=True,
default=lambda self: self.env['ir.sequence'].next_by_code(
'fusion.plating.batch') or '/',
tracking=True,
)
facility_id = fields.Many2one(
'fusion.plating.facility',
string='Facility',
required=True,
tracking=True,
)
bath_id = fields.Many2one(
'fusion.plating.bath',
string='Bath',
required=True,
tracking=True,
)
tank_id = fields.Many2one(
'fusion.plating.tank',
string='Tank',
related='bath_id.tank_id',
store=True,
readonly=True,
)
process_type_id = fields.Many2one(
related='bath_id.process_type_id',
store=True,
readonly=True,
)
state = fields.Selection(
selection=[
('draft', 'Draft'),
('loading', 'Loading'),
('in_process', 'In Process'),
('unloading', 'Unloading'),
('complete', 'Complete'),
('cancelled', 'Cancelled'),
],
string='Status',
default='draft',
required=True,
tracking=True,
)
rack_ref = fields.Char(string='Rack / Barrel Ref (legacy)')
rack_id = fields.Many2one(
'fusion.plating.rack', string='Rack / Fixture',
domain="[('state', '!=', 'retired')]",
tracking=True,
)
workorder_id = fields.Many2one(
'mrp.workorder', string='Work Order',
help='The WO this batch ran through. Used for material traceability.',
tracking=True,
)
production_id = fields.Many2one(
'mrp.production', string='Manufacturing Order',
related='workorder_id.production_id', store=True, readonly=True,
)
part_count = fields.Integer(string='Part Count')
start_time = fields.Datetime(string='Process Start', tracking=True)
end_time = fields.Datetime(string='Process End', tracking=True)
duration_minutes = fields.Float(
string='Duration (min)',
compute='_compute_duration',
store=True,
)
chemistry_ids = fields.One2many(
'fusion.plating.batch.chemistry',
'batch_id',
string='Chemistry Readings',
)
chemistry_count = fields.Integer(
string='Readings',
compute='_compute_chemistry_count',
)
operator_id = fields.Many2one(
'res.users',
string='Operator',
default=lambda self: self.env.user,
tracking=True,
)
company_id = fields.Many2one(
'res.company',
string='Company',
default=lambda self: self.env.company,
)
notes = fields.Html(string='Notes')
active = fields.Boolean(default=True)
# -------------------------------------------------------------------------
# Compute
# -------------------------------------------------------------------------
@api.depends('start_time', 'end_time')
def _compute_duration(self):
for rec in self:
if rec.start_time and rec.end_time:
delta = rec.end_time - rec.start_time
rec.duration_minutes = delta.total_seconds() / 60.0
else:
rec.duration_minutes = 0.0
@api.depends('chemistry_ids')
def _compute_chemistry_count(self):
for rec in self:
rec.chemistry_count = len(rec.chemistry_ids)
# -------------------------------------------------------------------------
# Actions
# -------------------------------------------------------------------------
def action_start_loading(self):
self.write({'state': 'loading'})
def action_start_process(self):
self.write({
'state': 'in_process',
'start_time': fields.Datetime.now(),
})
def action_start_unloading(self):
self.write({
'state': 'unloading',
'end_time': fields.Datetime.now(),
})
def action_complete(self):
self.write({'state': 'complete'})
def action_cancel(self):
self.write({'state': 'cancelled'})