feat(plating): close compliance gaps 7-9 — NCR + CAPA + discharge + invoice ref

**7a. NCR close gate** (fusion.plating.ncr.action_close)
Block close unless these are filled in:
  • Description (what happened)
  • Containment Actions (immediate response)
  • Root Cause (why it happened)
  • Disposition (use-as-is / rework / scrap / RTV decision)

A closed NCR without these is useless for AS9100 audits — it's
the entire point of an NCR to document what went wrong, why, and
how we responded. Empty-HTML strings like "<p><br></p>" are
detected as empty too.

**7b. CAPA close gate** (fusion.plating.capa.action_close)
Block close unless:
  • Root Cause Analysis filled in
  • Action Plan filled in
  • Verification (date + verifier) recorded
  • Effectiveness Notes filled when CAPA was marked Not Effective

AS9100 §10.2 / Nadcap require evidence of root-cause analysis,
the corrective/preventive action plan, AND that effectiveness
was verified before the loop is closed.

**8. Invoice ref defensive default** (account.move.create)
Auto-fills `ref` from the source SO's client_order_ref or
x_fc_po_number when the invoice is created with invoice_origin set
but no ref. Already populated on the SO confirm path; this catches
manually-created invoices that would otherwise miss it. Customer
AP teams reject invoices that don't quote their PO# back.

**9. Discharge sample close gate** (fusion.plating.discharge.sample.action_close)
Block close unless:
  • Lab Report # set
  • Results Received Date set
  • At least one parameter reading on file
  • Lab certificate/report attached

Without lab evidence the record fails any environmental compliance
audit — the whole point is to document the test was performed and
what the lab said.

**Simulator** (scripts/fp_e2e_workforce.py)
Adds 4 new negative tests (Test 8-11), all wrapped in savepoints:
  ✓ Test 8 : NCR close without RC/containment/disposition → blocked
  ✓ Test 9 : CAPA close without analysis/plan/verification → blocked
  ✓ Test 10: Discharge sample close without lab evidence → blocked
  ✓ Test 11: Invoice ref auto-fills from SO.client_order_ref → asserted

**Final E2E**: 52 PASS / 2 WARN / 0 FAIL out of 54 checks.
Both remaining WARNs are expected (bake-window auto-create,
first-piece gate — coating-driven, this coating doesn't trigger them).

11 negative tests in total now, every gate fires when triggered.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
gsinghpal
2026-04-19 10:35:19 -04:00
parent db8b79d22e
commit c118b7c6b5
8 changed files with 200 additions and 12 deletions

View File

@@ -12,21 +12,39 @@ class AccountMove(models.Model):
@api.model_create_multi
def create(self, vals_list):
"""Auto-inherit payment terms from the customer when missing.
"""Auto-inherit payment terms + customer PO# at creation time.
Customers usually have a default `property_payment_term_id`
(Net-30, Net-60, COD…). When an invoice is created without
terms, the due date silently defaults to "immediate" — wrong
for almost every B2B customer. Pull the partner's terms in
before super so the invoice is born with the right schedule.
Two defensive defaults so newly-created invoices come out
compliant out of the box:
1. **invoice_payment_term_id** — pulled from the customer's
property_payment_term_id (Net-30, COD, etc.). Without this
the due date silently becomes "immediate", wrong for B2B.
2. **ref** (customer reference / PO#) — pulled from the source
sale order's client_order_ref or x_fc_po_number. Customer
AP teams reject invoices that don't quote their PO# back.
We already populate this on the SO confirm path, but a
manually-created invoice would miss it without this default.
"""
Partner = self.env['res.partner']
SO = self.env['sale.order']
for vals in vals_list:
if vals.get('move_type') in ('out_invoice', 'out_refund'):
if not vals.get('invoice_payment_term_id') and vals.get('partner_id'):
partner = Partner.browse(vals['partner_id'])
if partner.property_payment_term_id:
vals['invoice_payment_term_id'] = partner.property_payment_term_id.id
# Defensive PO#: invoice_origin links to the SO; pull the
# customer ref from there if the caller didn't pass one.
if not vals.get('ref') and vals.get('invoice_origin'):
so = SO.search([('name', '=', vals['invoice_origin'])], limit=1)
if so:
vals['ref'] = (
so.client_order_ref
or (so.x_fc_po_number if 'x_fc_po_number' in so._fields else False)
or False
)
return super().create(vals_list)
def action_post(self):