Deleting an invoice — grouping, blockers, rights
The permanent and status-based delete endpoints, document groups, blocking reasons, handling of orphan documents and the permission keys.
The invoice module offers two deletes: physical deletion (delete) and moving to the trash (status = 9). Both use the same grouping and blocking logic.
Document groups
Selected invoices are grouped: the invoice and the interest and recovery fee documents built on it (getDependentInvoiceIds). If any member of a group cannot be deleted, no member is deleted.
Permanent delete (finance/invoice.delete)
- Right: one item
canAction(delete), several itemscanBulkAction(delete)(→bulkdelete); only invoices in scope (invoiceInScope). - Blocking reasons (
invoiceDeleteBlocker): financial settlement (transaction::getSettledInvoiceIds), numbered invoice, ledger entry (entry), status > 2. deleteInvoice(): header, items, NAV control row, document links, entry date, logs; the OTP-kelfo import file status is set to 0.- Orphan documents follow the
invoice_doc_deletesetting:ask(the response returns anorphan_docslist),delete(Dlbtdocstore::purgeDocument()),keep; only withdocument/document::delete. - Response: number of successes and failures, with reasons.
Trash (statusdisable) and restore (statusenable)
Same grouping; blocking reasons are financial settlement and numbered invoice. Without a blocker: updateInvoiceStatus(id, 9). Restoring sets status 2.
statusdisable asks for the edit right and canBulk(statusdelete, db); the latter is always true for one item, so trashing a single invoice only needs edit in the code, not statusdelete. statusenable checks only edit and scope.Tables involved
Table names carry the installation's own prefix in the database: invoice, invoice_item, invoice_ctrl, doc, doc_link; models: finance/transaction, finance/entry, files/otpkelfo, document/document.
Permission keys
| Key | Class | Effect |
|---|---|---|
delete | BASE | permanent delete of one item (row menu, eraser icon) |
bulkdelete | BASE | permanent delete of 2+ items (header bin) |
statusdelete | BASE | move to trash (in practice checked for several items) |
bulkstatusdelete | BASE | bulk move to trash |
The list returns deleted rows only with canSeeDeleted() (super admin or delete right).