document_parser_service
Orchestrates permit/plan/drive log parsing. Calls permit-parser for extraction, manages file I/O, and auto-creates SOW lines.
Connections
- depends on: permit-parser, drive-log-parser
- feeds into: supabase-write-service (auto-create SOW lines)
- feeds into: cert-data-service (specs in SOW notes JSON)
- called by:
/documentroute, portal reparse button
Auto-Create SOW Lines (session 39)
auto_create_sow_lines(project_id, sow_items):
- Resolves product record IDs from product codes
- Checks for existing SOW lines (idempotent — skips exact matches, updates qty changes)
- Enriches parent services (WTR-CRWL/WTR-BSMT/ENC-SYS from sub-components)
- Creates SOW lines via supabase_write_service with specs serialized in SOW_NOTES JSON
- Computes and creates add-on lines (config.ADDON_TRIGGERS)
- 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