document_parser_service

Orchestrates permit/plan/drive log parsing. Calls permit-parser for extraction, manages file I/O, and auto-creates SOW lines.

Connections

Auto-Create SOW Lines (session 39)

auto_create_sow_lines(project_id, sow_items):

  1. Resolves product record IDs from product codes
  2. Checks for existing SOW lines (idempotent — skips exact matches, updates qty changes)
  3. Enriches parent services (WTR-CRWL/WTR-BSMT/ENC-SYS from sub-components)
  4. Creates SOW lines via supabase_write_service with specs serialized in SOW_NOTES JSON
  5. Computes and creates add-on lines (config.ADDON_TRIGGERS)
  6. Returns summary: lines_created, lines_skipped, lines_updated, addon_lines_created, errors

Opt-in via auto_create_sow=True on parse_document() and the /document route.

Spec Serialization

_extract_specs_json() handles all 9 spec types: wall_specs, footer_specs, joist_specs, beam_specs, anchor_specs, fnd_specs, wtr_specs, enc_specs, rtw_specs. Serialized to JSON in SOW_NOTES field for downstream consumption by cert-data-service.

Notes

  • Reparse path (portal “Reparse Permits” button) uses same code path as intake parsing
  • Specs are additive — updates merge new specs without losing existing data