MEGAINFRA-WEBAPP/scripts
DEls d4ac4bd6e4 fix(dn-pipeline): key aliases on what actually identifies a product
The alias table shipped keyed on material_code alone. Live data says
that cannot work:

  - 16 of 24 purchase orders carry ONE material_code across every line.
    MEGCPO9239 is "513095" sixteen times.
  - Code "580070" spans 24 different products; "513080" spans 16.

An alias keyed on it would have resolved to every line on the order and
been permanently ambiguous — for Builders, the supplier whose truncated
descriptions need aliases most. I verified every PO item HAD a
material_code and never checked whether it discriminated.

Also found, by reading the source scan: the truncation is the supplier's
printer. Builders' form prints descriptions in a fixed ~20-character
column that wraps twice then stops ("Grip Fibreglass Meas" / "uring Tape
Orange a"). Extraction was faithful; nothing upstream can recover it.
But every line also carries an article number and a barcode, which are
never clipped and which we were discarding.

So:
  - PageItem gains product_code, and the prompt asks for the Art No /
    SKU / Prod Code column plus an explicit instruction to transcribe a
    clipped description verbatim rather than guess its ending.
  - Aliases record slip_product_code and po_description_key as well.
    Lookup tries product code before description; resolution tries the
    PO line description, then material_code ONLY when it narrows to a
    single line on that order, then falls through to text matching.
  - The resolve-item route no longer rejects a PO line for having no
    material_code, which was based on the same wrong assumption.

dn_item_aliases had 0 rows, so there was nothing to migrate.

916 tests. Live regression unchanged: 25 matched, 3 ambiguous, 3 none,
zero wrong; 0 of 24 POs vulnerable to nonsense.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-17 22:47:55 +02:00
..
migrations feat(clock): add clock_events PocketBase collection 2026-09-12 00:14:13 +02:00
build-icons.mjs feat(clock): replace icon with clock-on-cube design + OG share preview 2026-09-13 21:55:40 +02:00
build-og-image.mjs Add Open Graph image + social link preview metadata 2026-08-09 20:01:13 +02:00
generate-plant-hours-template.ts fix(plant-hours-template): ESM-safe __dirname + freeze note 2026-08-28 12:55:08 +02:00
migrate-delivery-notes-ocr.py feat(delivery-notes): enhance delivery note upload and processing 2026-08-26 15:33:30 +02:00
migrate-dn-item-units.py chore: final review polish (trailing newlines, JSDoc, changelog tense) 2026-09-17 12:49:37 +02:00
migrate-plant-hours-backfill-vehicle.py refactor(plant): enhance PlantPage and PlantView for fuel log integration 2026-09-02 12:36:10 +02:00
patch-next-dev-blocker.cjs Fix Coolify build: skip postinstall in deps stage 2026-08-09 02:29:48 +02:00
pb-add-dn-alias-keys.py fix(dn-pipeline): key aliases on what actually identifies a product 2026-09-17 22:47:55 +02:00
pb-add-dn-batch-uploaded-at.py fix(scripts): backfill uploaded_at from real sources, add a dry run 2026-09-17 21:25:33 +02:00
pb-add-dn-batches.py fix(dn-batches): heal created/updated fields on existing live collections 2026-09-17 15:17:17 +02:00
pb-add-dn-doc-type.py feat(dn-pipeline): classify document type instead of assuming delivery note 2026-09-17 21:45:08 +02:00
pb-add-dn-item-aliases.py feat(dn-pipeline): add the remembered product alias table 2026-09-17 21:34:37 +02:00
pb-add-dn-item-units.py feat(delivery-notes): add qty_raw/unit_raw/unit_converted to line items 2026-09-17 12:07:59 +02:00
pb-add-dn-open-pages.py fix(delivery-notes): a stray page no longer condemns good notes 2026-09-17 21:49:16 +02:00
pb-add-fuel-prices.py feat(dashboard): enhance operations dashboard with rain outlook and coordinate support 2026-09-06 19:59:52 +02:00
pb-add-site-coordinates.py feat(dashboard): enhance operations dashboard with rain outlook and coordinate support 2026-09-06 19:59:52 +02:00
pb-add-site-job-start-date.py feat(dashboard): enhance operations dashboard with rain outlook and coordinate support 2026-09-06 19:59:52 +02:00
pb-backup-collection.py feat(dashboard): enhance operations dashboard with rain outlook and coordinate support 2026-09-06 19:59:52 +02:00
pb-bootstrap-schema.py feat(clock): add clock_events PocketBase collection 2026-09-12 00:14:13 +02:00
pb-delete-fixed-costs.py feat(dashboard): enhance operations dashboard with rain outlook and coordinate support 2026-09-06 19:59:52 +02:00
pb-relax-rules.py feat(clock): add clock_events PocketBase collection 2026-09-12 00:14:13 +02:00
pb-show-fixed-costs.py feat(dashboard): enhance operations dashboard with rain outlook and coordinate support 2026-09-06 19:59:52 +02:00
pb-show-sites.py feat(dashboard): enhance operations dashboard with rain outlook and coordinate support 2026-09-06 19:59:52 +02:00
pb_env.py feat(dashboard): enhance operations dashboard with rain outlook and coordinate support 2026-09-06 19:59:52 +02:00