Invoice recognition and text extraction – system description
Steps of the shared recognition process, bulk queuing, the two background jobs (recognition, PDF text) and the rights of the text endpoints.
Invoice recognition runs through one shared entry point (recognition library run()), by hand for one document or as a background job for many. A new invoice is created only through the finance module's addInvoice() method.
Data model
Table names carry the installation's own prefix in the database.
| Table | Role |
|---|---|
doc | recog_status, recog_note, content_text, text_status |
doc_link | document ↔ invoice link (invoice_image type) |
invoice | the recognised invoice (with lines, through the finance model) |
company | partner data completion |
cron_queue | doc_recognise, doc_text jobs |
Recognition steps
- Scope check; merging earlier copies of the same file.
- If a linked invoice exists, no new one is created (for a technical customer only a customer swap, on a linked invoice completion).
- Text: text layer → local OCR → a paid language model if needed; pro forma detection (does not become an invoice); invoice pre-check.
- Reading; if complete (
verified): match an existing invoice or create one viafinance/invoice::addInvoice(),doc_link+invoice_imagetype, partner data completion, mirror invoice sync. - Result: structured answer (status, doc_id, invoice_id, changes), log,
setRecogResulton the document.
Background jobs
bulkrecognise: max. 2000 documents; missing, trashed or out-of-scope ones are skipped (logged); a recognition row per company (queueRecognition) and onedoc_recognisejob with thedoc_idslist.doc_recognise(one-off, per company): batches of 25 within a time budget, the sharedrun()in a restricted system context (only the job company's documents, no deletion,classifypre-filter); success to the system log, errors to the error log; notification at the end of a bulk run.doc_text(one-off, per document; queued by the upload): downloads the PDF from local path or Drive, extracts with a PDF parser, saves intocontent_text;text_status1 = extracted, 2 = no extractable text; the temporary file is deleted.
Text endpoints
extracttext: one or more documents (the client sends batches);textOf()→saveExtractedText(); counts incounts.textcontent: the stored text; a meaningful message on JSON encoding errors; without the right the badge is a plain label.
Permissions
recogniseinvoice(UNMAPPED) + coremodify; bulkcanBulkAction(recogniseinvoice).- The library receives from the caller: scope companies,
documentdelete,finance/invoicerepointandstatusdelete(rebuild),company/companyedit. textextract(not in the catalogue), bulkcanBulkAction(textextract);textview(BASE); scope per document.- Prerequisite: OCR and language model settings for paid reading.