Note (2026-04-24): After this document was written,
legal_entitywas renamed totenantand the oldtenantwas renamed toorganization. Read references to these terms with the pre-rename meaning.
Split documents.clj (2,574 lines) and document_management.clj (1,424 lines) into a com.getorcha.erp.http.documents.* namespace tree with grouped handlers, unified URL structure, and deduplicated shared code.
com.getorcha.erp.http.documents — route assembly + /documents → 404
com.getorcha.erp.http.documents.shared — shared helpers, UI components, parameterized list-events SSE
com.getorcha.erp.http.documents.upload — single upload handler (all doc types)
com.getorcha.erp.http.documents.accounts-payable — AP list, search, bulk DATEV export, list SSE
com.getorcha.erp.http.documents.management — DM list, search, type filtering, list SSE
com.getorcha.erp.http.documents.view — route assembly for /documents/view/:uuid, type dispatch
com.getorcha.erp.http.documents.view.shared — shared detail layout, detail SSE, navigation, reingest
com.getorcha.erp.http.documents.view.invoice — invoice detail + DATEV export + QA dataset
com.getorcha.erp.http.documents.view.notice — MAESN notice detail
com.getorcha.erp.http.documents.view.contract — contract detail
com.getorcha.erp.http.documents.view.purchase-order — PO detail
com.getorcha.erp.http.documents.view.goods-received-note — GRN detail
/documents → 404 (placeholder for future)
/documents/upload → POST (all document types)
/documents/accounts-payable → GET list
/documents/accounts-payable/search → GET search
/documents/accounts-payable/events → GET SSE (list updates)
/documents/accounts-payable/bulk/toggle/:id → POST
/documents/accounts-payable/bulk/toggle-all → POST
/documents/accounts-payable/bulk/deselect-all → POST
/documents/accounts-payable/bulk/export-datev → POST
/documents/management → GET list
/documents/management/search → GET search
/documents/management/events → GET SSE (list updates)
/documents/view/:uuid → GET detail (dispatches by document type)
/documents/view/:uuid/events → GET SSE (detail updates)
/documents/view/:uuid/reingest → POST
/documents/view/:uuid/export/datev → POST (invoice-only)
/documents/view/:uuid/export/datev/status → GET (invoice-only)
/documents/view/:uuid/add-to-qa-dataset → POST (invoice-only)
Following existing convention (approach B), each submodule owns its full route prefix. The parent concatenates:
;; com.getorcha.erp.http.documents
(defn routes [config]
["/documents"
["" {:get {:handler (constantly {:status 404})}}]
(upload/routes config)
(accounts-payable/routes config)
(management/routes config)
(view/routes config)])
The erp/http.clj router replaces both erp.http.documents/routes and erp.http.document-management/routes with a single erp.http.documents/routes call.
documents.shared)Deduplicated from both existing files:
legal-entity-ids, primary-legal-entity-idexcel-content-type?, display-file-pathsortable-th, pagination-url, pagination-controlsdocument-builder-fn / row buildermake-list-events-handler — accepts a document type filter set and a row-renderer fn, returns an SSE handler. Each list module (accounts-payable, management) calls it with their specific config.documents.view)The get-document handler in view loads the document, determines its type, and delegates rendering to the appropriate submodule:
invoice, financial-notice → view.invoice, view.noticecontract → view.contractpurchase-order → view.purchase-ordergoods-received-note → view.goods-received-noteview.shared)Single detail-events handler replacing two nearly-identical handlers:
:export events: delegates to view.invoice for DATEV section rendering/documents/view/:uuid URL)documents.shared)Parameterized handler used by both AP and management lists:
documents.upload)Single upload handler serving all document types. Currently duplicated nearly identically in both files — merged into one at /documents/upload.
DATEV bulk export (selection toggling, toggle-all, deselect-all, export) stays exclusively in accounts-payable. Not shared.
com.getorcha.erp.http.documents-test — route assembly tests
com.getorcha.erp.http.documents.upload-test — upload handler tests
com.getorcha.erp.http.documents.accounts-payable-test — AP list, search, bulk, list SSE
com.getorcha.erp.http.documents.management-test — DM list, search, list SSE
com.getorcha.erp.http.documents.view-test — detail dispatch, shared detail SSE, reingest
com.getorcha.erp.http.documents.view.invoice-test — invoice detail, DATEV export, QA dataset
com.getorcha.erp.http.documents.view.contract-test — contract detail
Simpler view types (notice, PO, GRN) grouped into view-test initially, split if they grow.
Existing tests in documents_test.clj and document_management_test.clj redistributed to match.