main
John Lauer Verify top-access cooler mount and reconcile current BOM with internal inventory pricing ae78bc0
#!/usr/bin/env python3
"""Group exact MPN demands; keep unpriced rows and candidate status explicit."""
from pathlib import Path
import csv,json,hashlib
from decimal import Decimal
from collections import defaultdict
R=Path(__file__).resolve().parents[1];rows=list(csv.DictReader((R/'design/bom.csv').open()));groups=defaultdict(list)
for row in rows:
 if row['mpn']!='no part':groups[row['mpn']].append(row)
out=[]
for mpn,items in sorted(groups.items()):
 prices={r['unit_price_usd']for r in items if r['unit_price_usd']};assert len(prices)<=1,mpn
 price=next(iter(prices),'');qty=len(items)
 out.append(dict(scope='board',status='prototype-demand-not-order',mpn=mpn,quantity=qty,refs=' '.join(x['ref']for x in items),unit_price_usd=price,extended_usd=str(Decimal(price)*qty)if price else '',source='; '.join(sorted({x['source']for x in items})),checked_on='; '.join(sorted({x['stock_checked_on']for x in items if x['stock_checked_on']})),note='Dated listing only; no reservation'if price else 'Unpriced; exact stock quantity and packaging unverified'))
for ref,mpn,qty,price,status,source,date in [
 ('FAN1','MF40200V1-1000U-G99',1,'8.45','selected-fan','design/ps_fan.json','2026-10-07'),
 ('HS1','680-125220',1,'17.17','cooling-candidate','design/browser-evidence/stock-sink-api.json','2026-10-09'),
 ('NTC1','NTCLE428E3103H301A',1,'1.82','sensor-candidate-not-adopted','design/ps_ntcle428_long.json','2026-10-10'),
 ('FAN_HOUSING','M20-1060300',1,'0.15','nominal-harness-candidate','design/sourcing-2026-10-10/M20-1060300.json','2026-10-10'),
 ('SENSOR_HOUSING','GHR-03V-S',1,'0.10','sensor-harness-candidate','design/component-catalog-audit/jst-gh-threeway-housing-sourcing.json','2026-10-11'),
 ('FAN_CONTACTS','M20-1180046',3,'0.14','nominal-harness-candidate','design/sourcing-2026-10-10/M20-1180046.json','2026-10-10'),
 ('SENSOR_CONTACTS','SSHL-002T-P0.2',2,'0.22','sensor-harness-candidate','design/component-catalog-audit/jst-gh-contact-sourcing.json','2026-10-11'),
 ('TIM1','178-25-220',1,'','unresolved-drawing-do-not-order','docs/package-cooling-review.md','')]:
 out.append(dict(scope='external',status=status,mpn=mpn,quantity=qty,refs=ref,unit_price_usd=price,extended_usd=str(Decimal(price)*qty)if price else '',source=source,checked_on=date,note='Candidate price; excludes freight/tax; not a purchase quote'if price else 'Unpriced and not released'))
p=R/'docs/cost/procurement-review.csv'
with p.open('w',newline='')as f:
 w=csv.DictWriter(f,fieldnames=list(out[0]));w.writeheader();w.writerows(out)
board=[x for x in out if x['scope']=='board'];assert sum(x['quantity']for x in board)==91
summary=dict(status='incomplete-prototype-demand-not-purchase-order',sourceBomSha256=hashlib.sha256((R/'design/bom.csv').read_bytes()).hexdigest(),boardPurchasedReferences=91,printedTestPadsExcluded=13,uniqueBoardMpns=len(board),unpricedBoardMpns=sum(not x['unit_price_usd']for x in board),unpricedBoardReferences=sum(x['quantity']for x in board if not x['unit_price_usd']),pricedBoardSubtotalUsd=str(sum((Decimal(x['extended_usd'])for x in board if x['extended_usd']),Decimal(0))),pricedProposedConfigurationSubtotalUsd=str(sum((Decimal(x['extended_usd'])for x in out if x['extended_usd']),Decimal(0))),additionalUnpriced=[str(sum(x['quantity']for x in board if not x['unit_price_usd']))+' board references across '+str(sum(not x['unit_price_usd']for x in board))+' exact MPNs; see separate internal inventory snapshot','TIM, grease, clamp and retention hardware','Fan guard and carrier material/processing','3rdPartyFab processing and any setup charges','Assembly labor, calibration and qualification','Shipping and tax'],recurringCosts='No recurring cost estimate or service subscription charge verified',quoteObtained=False,orderPlaced=False)
(R/'docs/cost/procurement-review.json').write_text(json.dumps(summary,indent=2)+'\n');print(json.dumps(summary,indent=2))