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)

  1. Right: one item canAction(delete), several items canBulkAction(delete) (→ bulkdelete); only invoices in scope (invoiceInScope).
  2. Blocking reasons (invoiceDeleteBlocker): financial settlement (transaction::getSettledInvoiceIds), numbered invoice, ledger entry (entry), status > 2.
  3. deleteInvoice(): header, items, NAV control row, document links, entry date, logs; the OTP-kelfo import file status is set to 0.
  4. Orphan documents follow the invoice_doc_delete setting: ask (the response returns an orphan_docs list), delete (Dlbtdocstore::purgeDocument()), keep; only with document/document::delete.
  5. 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

KeyClassEffect
deleteBASEpermanent delete of one item (row menu, eraser icon)
bulkdeleteBASEpermanent delete of 2+ items (header bin)
statusdeleteBASEmove to trash (in practice checked for several items)
bulkstatusdeleteBASEbulk move to trash

The list returns deleted rows only with canSeeDeleted() (super admin or delete right).

Related topics: invoice trash permissions