---
id: CAP-ACC-BAT-006
title: Remove an unused batch safely
feature: FEAT-ACC-BAT-01
product_area: accounting
module: batches
revision: 1
status: draft
product_intent: proposed
implementation_evidence: observed
supersedes:
- inventory CAP-ACC-BAT-001 (delete half)
- inventory RUL-ACC-BAT-012
- journey ACT-ACC-0508
source_sha:
  services-accounting: f47cb263875bbc0c5640fba7dae6785ec32695f8
  react-console: baf6dae382d6f41dce976c7f848667ccc37e076f
intent_sources:
- services-accounting:docs/milestones/ACCT-M1-books-and-invoices.md#D11
purpose: Staff discard an unused batch without removing the records that accounting still relies on.
outcomes:
- Unused eligible collections can be removed without leaving recurring intake pointed at a deleted batch.
concepts:
- CON-ACC-BAT-001
actors:
- ACT-ACC-012
- ACT-ACC-006
surfaces:
- api
permissions:
- key: accounting.batches.delete
  where_checked: api
  scope: tenant
rules:
- id: BR-CAP-ACC-BAT-006-01
  proved_by: [ATS-ACC-BAT-006-01]
  statement: Deletion requires the batch-delete permission.
  kind: permission
  enforced_at:
  - api
  must_prove: true
  provenance: observed
  source: services-accounting:modules/batches/aws/api/batch-records.routes.ts:deleteBatch
  origin: none
- id: BR-CAP-ACC-BAT-006-02
  proved_by: [ATS-ACC-BAT-006-02, ATS-ACC-BAT-006-09, ATS-ACC-BAT-013-17, TST-ACC-BAT-060, TST-ACC-BAT-085]
  statement: Posted and Downloaded batches reject deletion.
  kind: lifecycle
  enforced_at:
  - service
  must_prove: true
  provenance: test
  source: services-accounting:modules/batches/tests/integration/services/persistence/batches.integration.spec.js#refuses
    deleting a posted batch
  origin: none
- id: BR-CAP-ACC-BAT-006-03
  proved_by: [ATS-ACC-BAT-006-03, TST-ACC-BAT-085]
  statement: A remaining document, posting or ledger entry prevents deletion, with an in-use refusal identifying
    the dependency.
  kind: invariant
  enforced_at:
  - database
  - service
  must_prove: true
  provenance: test
  source: services-accounting:modules/batches/tests/integration/services/persistence/batches.integration.spec.js#answers
    409 naming the batch for every table whose restrict foreign key names a batch, never a 500 (DEF-ACT-0012)
  origin: services-accounting:docs/milestones/ACCT-M1-books-and-invoices.md#D11
- id: BR-CAP-ACC-BAT-006-04
  proved_by: [ATS-ACC-BAT-006-04]
  statement: Either kind of record lock prevents batch deletion.
  kind: policy
  enforced_at:
  - service
  must_prove: true
  provenance: observed
  source: services-accounting:modules/batches/services/persistence/batches.ts:deleteBatch
  origin: none
- id: BR-CAP-ACC-BAT-006-05
  proved_by: [ATS-ACC-BAT-006-05, TST-ACC-BAT-063, TST-ACC-BAT-074]
  statement: Period-close system batches cannot be removed through ordinary deletion.
  kind: policy
  enforced_at:
  - service
  must_prove: true
  provenance: test
  source: services-accounting:modules/batches/tests/e2e/system-batches.e2e.spec.js#refuses DELETE 409 system_batch,
    the batch still there
  origin: none
- id: BR-CAP-ACC-BAT-006-06
  proved_by: [ATS-ACC-BAT-006-06, ATS-ACC-BAT-006-08, ATS-ACC-BAT-009-13, TST-ACC-BAT-085]
  statement: An unused active batch can be deleted, clearing its recurring configuration’s active reference until
    a later roll supplies another.
  kind: policy
  enforced_at:
  - database
  - service
  must_prove: true
  provenance: test
  source: services-accounting:modules/batches/tests/integration/services/persistence/batches.integration.spec.js#deletes
    the batch a recurring batch names as its active batch and clears the reference (DEF-ACT-0012)
  origin: none
- id: BR-CAP-ACC-BAT-006-07
  proved_by: [ATS-ACC-BAT-006-02, ATS-ACC-BAT-006-07, ATS-ACC-BAT-006-10, ATS-ACC-BAT-008-08, TST-ACC-BAT-060, TST-ACC-BAT-085]
  statement: Deletion also removes the automatic-close schedule and resolves the batch’s outstanding posting attention
    item.
  kind: lifecycle
  enforced_at:
  - service
  must_prove: true
  provenance: test
  source: services-accounting:modules/batches/tests/integration/services/persistence/batches.integration.spec.js#deletes
    an empty batch with its automatic close’s schedule
  origin: none
scenarios:
- id: SC-CAP-ACC-BAT-006-01
  given: An accidental Open batch has no references preventing removal.
  when: An authorized caller deletes it.
  then: A subsequent read reports that the batch does not exist.
  provenance: test
  source: services-accounting:modules/batches/tests/e2e/batches.e2e.spec.js#deletes it, and then reads it 404
- id: SC-CAP-ACC-BAT-006-02
  given: Payments and credits still reference an Open batch.
  when: Staff request its deletion.
  then: An in-use refusal identifies those dependencies and preserves the batch.
  provenance: documented
  source: services-accounting:docs/milestones/plans/ACCT-M1-plan.md#D11. Four repairs that already landed and carry
    a product choice
edge_cases: []
constraints: []
depends_on: []
related:
- CAP-ACC-BAT-009
- CAP-ACC-BAT-013
journeys: []
open_questions: []
evidence:
- 'Pinned services-accounting (f47cb263), examined sources: aws/api/batch-records.routes.ts (deleteBatch), services/persistence/batches.ts
  (deleteBatch, deleteBatchIfUnused), services/persistence/batches-refusals.ts, services/rules/batch-rules.ts (assertBatchCanBeDeleted);
  tests integration/services/persistence/batches.integration.spec.js ("a delete"), e2e/batches.e2e.spec.js, e2e/system-batches.e2e.spec.js;
  docs/milestones/ACCT-M1-books-and-invoices.md (D11).'
- 'Pinned react-console (baf6dae3), examined sources: journey ACT-ACC-0508 (the console offers no delete; its open
  decision).'
controls: [TC-IAM-001, TC-IAM-002, TC-IAM-004, TC-IAM-005, TC-AZ-001, TC-AZ-002, TC-AZ-003, TC-AZ-004, TC-AZ-006, TC-TEN-001, TC-TEN-002, TC-TEN-003, TC-DAT-001, TC-DAT-004, TC-LOG-002, TC-LOG-003, TC-LOG-004, TC-LOG-005, TC-PI-001, TC-PI-003, TC-PI-005]
exercised_by: [FAS-ACC-BAT-01-03, FAS-ACC-BAT-01-04, FAS-ACC-BAT-01-05]
suites: [TST-ACC-BAT-060, TST-ACC-BAT-063, TST-ACC-BAT-074, TST-ACC-BAT-085]
---

# Remove an unused batch safely

## Purpose

Staff discard an unused batch without removing the records that accounting still relies on.

## How It Works

Staff use deletion to clear a batch opened in error. The service first checks record protection and lifecycle restrictions. Dependencies then determine whether removal is safe. A successful deletion also clears its associated scheduled and attention work. Deleting the active batch can leave a recurring stream without a current batch. An in-use refusal preserves the batch and identifies the record that prevents removal.

## Relationships

- Related outcome: Configure recurring batch streams, which addresses the connected batch work.
- Related outcome: Run and monitor a batch posting job, which addresses the connected batch work.
