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>
This commit is contained in:
gsinghpal
2026-04-16 23:55:22 -04:00
parent d3dd6376a6
commit 6658544f85
30 changed files with 1098 additions and 15 deletions

View File

@@ -56,6 +56,7 @@ Copyright (c) 2026 Nexa Systems Inc. All rights reserved.
'views/fp_quality_hold_views.xml',
'views/fp_batch_views.xml',
'views/fp_workorder_priority_views.xml',
'views/fp_job_consumption_views.xml',
],
'installable': True,
'application': False,

View File

@@ -12,4 +12,5 @@ from . import fp_quality_hold
from . import fp_delivery
from . import fp_batch
from . import fp_job_node_override
from . import fp_job_consumption
from . import account_move

View File

@@ -0,0 +1,84 @@
# -*- 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 FpJobConsumption(models.Model):
"""A single consumable drawdown charged to a manufacturing order.
Sources include bath replenishment applied against a job, masking tape
rolls, PPE, nickel salts — anything that has a cost and should roll
into job costing.
Kept deliberately lightweight: one row per event, cost derived from
`product.standard_price` at log time (snapshot, not reactive).
"""
_name = 'fp.job.consumption'
_description = 'Fusion Plating — Job Consumption'
_order = 'logged_date desc, id desc'
production_id = fields.Many2one(
'mrp.production', string='Manufacturing Order',
required=True, ondelete='cascade',
)
workorder_id = fields.Many2one(
'mrp.workorder', string='Work Order',
domain="[('production_id', '=', production_id)]",
)
product_id = fields.Many2one(
'product.product', string='Product', required=True,
domain="[('sale_ok', '=', False)]",
)
product_name = fields.Char(
string='Product Name (snapshot)',
help='Free-text product label if no inventory product is linked.',
)
quantity = fields.Float(string='Quantity', required=True, digits=(12, 3))
uom_id = fields.Many2one(
'uom.uom', string='UoM',
)
unit_cost = fields.Float(
string='Unit Cost (snapshot)', digits=(12, 4),
help='Taken from product.standard_price at log time.',
)
total_cost = fields.Float(
string='Total Cost', compute='_compute_total_cost', store=True, digits=(12, 2),
)
currency_id = fields.Many2one(
'res.currency', default=lambda self: self.env.company.currency_id,
)
logged_date = fields.Datetime(
string='Logged', default=fields.Datetime.now,
)
logged_by_id = fields.Many2one(
'res.users', string='Logged By', default=lambda self: self.env.user,
)
source = fields.Selection(
[('replenishment', 'Bath Replenishment'),
('masking', 'Masking Material'),
('ppe', 'PPE / Consumables'),
('chemistry', 'Process Chemistry'),
('other', 'Other')],
string='Source', default='other', required=True,
)
replenishment_id = fields.Many2one(
'fusion.plating.bath.replenishment.suggestion',
string='Replenishment Suggestion',
ondelete='set null',
)
notes = fields.Char(string='Notes')
@api.depends('quantity', 'unit_cost')
def _compute_total_cost(self):
for rec in self:
rec.total_cost = round((rec.quantity or 0) * (rec.unit_cost or 0), 2)
@api.onchange('product_id')
def _onchange_product(self):
if self.product_id:
self.product_name = self.product_id.display_name
self.unit_cost = self.product_id.standard_price or 0.0
self.uom_id = self.product_id.uom_id or False

View File

@@ -81,6 +81,98 @@ class MrpProduction(models.Model):
'or "Ready to Ship" when all work is done.',
)
# ------------------------------------------------------------------
# T3.3 — Actuals vs quoted margin
# T3.4 — Consumables tied to jobs
# ------------------------------------------------------------------
x_fc_consumption_ids = fields.One2many(
'fp.job.consumption', 'production_id',
string='Consumables Log',
)
x_fc_consumables_cost = fields.Monetary(
string='Consumables Cost', compute='_compute_job_costs',
store=True, currency_field='x_fc_currency_id',
)
x_fc_labour_cost = fields.Monetary(
string='Labour Cost', compute='_compute_job_costs',
store=True, currency_field='x_fc_currency_id',
help='Sum of WO duration × workcentre cost_hour, across all done WOs.',
)
x_fc_actual_cost = fields.Monetary(
string='Actual Total Cost', compute='_compute_job_costs',
store=True, currency_field='x_fc_currency_id',
)
x_fc_quoted_revenue = fields.Monetary(
string='Quoted Revenue', compute='_compute_job_costs',
store=True, currency_field='x_fc_currency_id',
help='Revenue from the originating sale order.',
)
x_fc_margin_actual = fields.Monetary(
string='Actual Margin ($)', compute='_compute_job_costs',
store=True, currency_field='x_fc_currency_id',
)
x_fc_margin_pct = fields.Float(
string='Actual Margin (%)', compute='_compute_job_costs',
store=True, digits=(6, 2),
)
x_fc_currency_id = fields.Many2one(
'res.currency', compute='_compute_job_costs', store=True,
)
x_fc_consumption_count = fields.Integer(
compute='_compute_consumption_count',
)
def _compute_consumption_count(self):
for mo in self:
mo.x_fc_consumption_count = len(mo.x_fc_consumption_ids)
@api.depends(
'x_fc_consumption_ids.total_cost',
'workorder_ids.duration',
'workorder_ids.workcenter_id.costs_hour',
'origin',
)
def _compute_job_costs(self):
SO = self.env['sale.order']
for mo in self:
currency = mo.company_id.currency_id
consumables = sum(mo.x_fc_consumption_ids.mapped('total_cost'))
labour = 0.0
for wo in mo.workorder_ids:
rate = wo.workcenter_id.costs_hour or 0.0
dur_hours = (wo.duration or 0.0) / 60.0
labour += dur_hours * rate
actual = consumables + labour
revenue = 0.0
if mo.origin:
so = SO.search([('name', '=', mo.origin)], limit=1)
if so:
revenue = so.amount_untaxed or 0.0
currency = so.currency_id or currency
margin = revenue - actual
pct = (margin / revenue * 100.0) if revenue else 0.0
mo.x_fc_consumables_cost = round(consumables, 2)
mo.x_fc_labour_cost = round(labour, 2)
mo.x_fc_actual_cost = round(actual, 2)
mo.x_fc_quoted_revenue = round(revenue, 2)
mo.x_fc_margin_actual = round(margin, 2)
mo.x_fc_margin_pct = round(pct, 2)
mo.x_fc_currency_id = currency
def action_view_consumption(self):
self.ensure_one()
return {
'type': 'ir.actions.act_window',
'name': _('Consumables — %s') % self.name,
'res_model': 'fp.job.consumption',
'view_mode': 'list,form',
'domain': [('production_id', '=', self.id)],
'context': {'default_production_id': self.id},
'target': 'current',
}
@api.depends('x_fc_override_ids')
def _compute_override_count(self):
for rec in self:

View File

@@ -403,6 +403,42 @@ class MrpWorkorder(models.Model):
})
return {'holds': holds, 'ncrs': ncrs}
# ------------------------------------------------------------------
# T2.2 — Certification gate on WO start
# ------------------------------------------------------------------
def button_start(self):
"""Block start unless the current user's linked employee holds
an active certification for this WO's process type."""
self._fp_check_operator_certification()
return super().button_start()
def _fp_check_operator_certification(self):
"""Raise UserError if the user isn't certified for this process."""
from odoo.exceptions import UserError
Cert = self.env.get('fp.operator.certification')
if Cert is None:
return
for wo in self:
# Figure out process_type: use bath's process if bath set,
# else workcenter's x_fc_facility_id.* — bath is the reliable one.
if not wo.x_fc_bath_id or not wo.x_fc_bath_id.process_type_id:
continue # Nothing to check
process_type = wo.x_fc_bath_id.process_type_id
employee = self.env.user.employee_id
if not employee:
# Admins without an employee record skip the check.
if not self.env.user.has_group('fusion_plating.group_fusion_plating_manager'):
raise UserError(_(
'You must be linked to an HR employee record to start '
'plating work orders. Contact your manager.'
))
return
if not Cert.has_active_cert(employee.id, process_type.id):
raise UserError(_(
'Operator %s is not certified for process "%s". '
'Request certification from your supervisor before starting this WO.'
) % (employee.name, process_type.name))
# ------------------------------------------------------------------
# T1.1 — Bake window auto-create on plating WO finish
# T1.3 — Rack MTO increment when a rack was used

View File

@@ -12,3 +12,6 @@ access_fp_recipe_config_wizard_supervisor,fp.recipe.config.wizard.supervisor,mod
access_fp_recipe_config_wizard_manager,fp.recipe.config.wizard.manager,model_fp_recipe_config_wizard,fusion_plating.group_fusion_plating_manager,1,1,1,1
access_fp_recipe_config_wizard_line_supervisor,fp.recipe.config.wizard.line.supervisor,model_fp_recipe_config_wizard_line,fusion_plating.group_fusion_plating_supervisor,1,1,1,0
access_fp_recipe_config_wizard_line_manager,fp.recipe.config.wizard.line.manager,model_fp_recipe_config_wizard_line,fusion_plating.group_fusion_plating_manager,1,1,1,1
access_fp_job_consumption_operator,fp.job.consumption.operator,model_fp_job_consumption,fusion_plating.group_fusion_plating_operator,1,1,1,0
access_fp_job_consumption_supervisor,fp.job.consumption.supervisor,model_fp_job_consumption,fusion_plating.group_fusion_plating_supervisor,1,1,1,0
access_fp_job_consumption_manager,fp.job.consumption.manager,model_fp_job_consumption,fusion_plating.group_fusion_plating_manager,1,1,1,1
1 id name model_id:id group_id:id perm_read perm_write perm_create perm_unlink
12 access_fp_recipe_config_wizard_manager fp.recipe.config.wizard.manager model_fp_recipe_config_wizard fusion_plating.group_fusion_plating_manager 1 1 1 1
13 access_fp_recipe_config_wizard_line_supervisor fp.recipe.config.wizard.line.supervisor model_fp_recipe_config_wizard_line fusion_plating.group_fusion_plating_supervisor 1 1 1 0
14 access_fp_recipe_config_wizard_line_manager fp.recipe.config.wizard.line.manager model_fp_recipe_config_wizard_line fusion_plating.group_fusion_plating_manager 1 1 1 1
15 access_fp_job_consumption_operator fp.job.consumption.operator model_fp_job_consumption fusion_plating.group_fusion_plating_operator 1 1 1 0
16 access_fp_job_consumption_supervisor fp.job.consumption.supervisor model_fp_job_consumption fusion_plating.group_fusion_plating_supervisor 1 1 1 0
17 access_fp_job_consumption_manager fp.job.consumption.manager model_fp_job_consumption fusion_plating.group_fusion_plating_manager 1 1 1 1

View File

@@ -0,0 +1,62 @@
<?xml version="1.0" encoding="UTF-8"?>
<odoo>
<record id="view_fp_job_consumption_list" model="ir.ui.view">
<field name="name">fp.job.consumption.list</field>
<field name="model">fp.job.consumption</field>
<field name="arch" type="xml">
<list editable="bottom" default_order="logged_date desc">
<field name="logged_date"/>
<field name="production_id"/>
<field name="workorder_id"/>
<field name="product_id"/>
<field name="quantity"/>
<field name="uom_id"/>
<field name="unit_cost"/>
<field name="total_cost" sum="Total"/>
<field name="source"/>
<field name="currency_id" invisible="1"/>
<field name="logged_by_id" optional="hide"/>
</list>
</field>
</record>
<record id="view_fp_job_consumption_form" model="ir.ui.view">
<field name="name">fp.job.consumption.form</field>
<field name="model">fp.job.consumption</field>
<field name="arch" type="xml">
<form>
<sheet>
<group>
<group>
<field name="production_id"/>
<field name="workorder_id"/>
<field name="product_id"/>
<field name="product_name"/>
<field name="source"/>
</group>
<group>
<field name="quantity"/>
<field name="uom_id"/>
<field name="unit_cost"/>
<field name="total_cost" readonly="1"/>
<field name="currency_id" invisible="1"/>
<field name="logged_date"/>
<field name="logged_by_id"/>
</group>
</group>
<group string="Notes">
<field name="notes" nolabel="1"/>
</group>
</sheet>
</form>
</field>
</record>
<record id="action_fp_job_consumption" model="ir.actions.act_window">
<field name="name">Job Consumables Log</field>
<field name="res_model">fp.job.consumption</field>
<field name="view_mode">list,form</field>
</record>
</odoo>

View File

@@ -25,6 +25,27 @@
<field name="x_fc_recipe_id"/>
</group>
</group>
<group string="Job Costing" name="job_costing">
<field name="x_fc_currency_id" invisible="1"/>
<group>
<field name="x_fc_quoted_revenue" readonly="1"
widget="monetary"/>
<field name="x_fc_labour_cost" readonly="1"
widget="monetary"/>
<field name="x_fc_consumables_cost" readonly="1"
widget="monetary"/>
<field name="x_fc_actual_cost" readonly="1"
widget="monetary"/>
</group>
<group>
<field name="x_fc_margin_actual" readonly="1"
widget="monetary"
decoration-success="x_fc_margin_actual &gt; 0"
decoration-danger="x_fc_margin_actual &lt; 0"/>
<field name="x_fc_margin_pct" readonly="1"
widget="percentage"/>
</group>
</group>
<group string="Rework" name="rework"
invisible="not x_fc_is_rework and not x_fc_original_production_id">
<group>
@@ -58,6 +79,11 @@
<span class="o_stat_text">Create Rework</span>
</div>
</button>
<button name="action_view_consumption" type="object"
class="oe_stat_button" icon="fa-flask">
<field name="x_fc_consumption_count" widget="statinfo"
string="Consumables"/>
</button>
</xpath>
</field>