---
id: CAP-ACC-BKS-014
title: Prepare Accounting document and export templates
feature: FEAT-ACC-BKS-05
product_area: accounting
module: books
revision: 1
status: draft
product_intent: confirmed
implementation_evidence: observed
supersedes:
  - CAP-ACC-CFG-013
source_sha:
  services-accounting: f47cb263875bbc0c5640fba7dae6785ec32695f8
  react-console: baf6dae382d6f41dce976c7f848667ccc37e076f
intent_sources:
  - >-
    services-accounting:docs/milestones/plans/ACCT-M1-plan.md#3. How it works
    for the user
  - 'services-accounting:docs/milestones/ACCT-M1-books-and-invoices.md#R25'
  - 'services-accounting:docs/milestones/ACCT-M1-books-and-invoices.md#D11'
purpose: Controllers adapt the wording and format of the documents Accounting produces.
outcomes:
  - Saved sources pass template validation.
  - Protected built-ins provide a starting point for customer copies.
  - Preview makes draft output inspectable before delivery.
concepts:
  - CON-ACC-BKS-004
actors:
  - ACT-ACC-001
  - ACT-ACC-002
surfaces:
  - console
  - api
preconditions: []
postconditions: []
permissions:
  - key: accounting.document-templates.read
    where_checked: api
    scope: tenant
  - key: accounting.document-templates.create
    where_checked: api
    scope: tenant
  - key: accounting.document-templates.update
    where_checked: api
    scope: tenant
  - key: accounting.document-templates.delete
    where_checked: api
    scope: tenant
rules:
  - id: BR-CAP-ACC-BKS-014-01
    proved_by: [ATS-ACC-BKS-014-01, ATS-ACC-BKS-014-09, TST-ACC-BKS-052, TST-ACC-BKS-066]
    statement: >-
      Templates have one immutable kind among invoice, payment receipt, refund
      receipt, statement and batch download.
    kind: invariant
    enforced_at:
      - api
      - service
      - database
    must_prove: true
    provenance: test
    source: >-
      services-accounting:modules/books/tests/e2e/document-templates.e2e.spec.js#answers
      409 to a change of kind, which is write-once
    origin: none
  - id: BR-CAP-ACC-BKS-014-02
    proved_by: [ATS-ACC-BKS-014-02, TST-ACC-BKS-052, TST-ACC-BKS-167]
    statement: >-
      Saved body, e-mail and filename sources must be valid Liquid using the
      kind’s variables and permitted currency, number, row-number, title-case
      and date filters; problems identify field and position together and
      Handlebars input receives Liquid guidance.
    kind: validation
    enforced_at:
      - api
      - service
    must_prove: true
    provenance: test
    source: >-
      services-accounting:modules/books/tests/e2e/document-templates.e2e.spec.js#answers
      400 naming the line and column of Liquid that cannot be read
    origin: none
  - id: BR-CAP-ACC-BKS-014-03
    proved_by: [ATS-ACC-BKS-014-03, TST-ACC-BKS-052, TST-ACC-BKS-066]
    statement: >-
      E-mail requires subject and body together and permits sender, reply-to and
      copies only with them; statements require e-mail, downloads instead
      require CSV, IIF or text output and a filename, and normalized copy
      addresses number at most ten.
    kind: validation
    enforced_at:
      - api
      - database
    must_prove: true
    provenance: test
    source: >-
      services-accounting:modules/books/tests/integration/db/document-templates.table.integration.spec.js#refuses
      a statement without its e-mail (Rhythm 1.0’s V6)
    origin: none
  - id: BR-CAP-ACC-BKS-014-04
    proved_by: [ATS-ACC-BKS-014-04, ATS-ACC-BKS-014-10, TST-ACC-BKS-052]
    statement: >-
      Statements default to all customer contacts or select contacts through one
      to fifty named roles.
    kind: policy
    enforced_at:
      - api
      - database
    must_prove: true
    provenance: test
    source: >-
      services-accounting:modules/books/tests/e2e/document-templates.e2e.spec.js#sends
      a statement to all contacts when send_to is not stated
    origin: none
  - id: BR-CAP-ACC-BKS-014-05
    proved_by: [ATS-ACC-BKS-014-05, TST-ACC-BKS-052, TST-ACC-BKS-163]
    statement: >-
      The nine built-ins—four document templates and five software
      downloads—list first and allow reading, preview and duplication, but
      reject replacement, deletion and customer reuse of their identifiers.
    kind: policy
    enforced_at:
      - service
      - database
    must_prove: true
    provenance: test
    source: >-
      services-accounting:modules/books/tests/e2e/document-templates.e2e.spec.js#answers
      409 to a replacement of a built-in
    origin: >-
      services-accounting:docs/milestones/plans/ACCT-M1-plan.md#3. How it works
      for the user
  - id: BR-CAP-ACC-BKS-014-06
    proved_by: [ATS-ACC-BKS-014-05, ATS-ACC-BKS-014-09, ATS-ACC-BKS-014-12, TST-ACC-BKS-020, TST-ACC-BKS-052, TST-ACC-BKS-163]
    statement: >-
      Duplication copies the complete content of a built-in or customer template
      into a new active template with a new identifier.
    kind: lifecycle
    enforced_at:
      - service
    must_prove: true
    provenance: test
    source: >-
      services-accounting:modules/books/tests/e2e/document-templates.e2e.spec.js#copies
      a built-in into a new, active tenant template with the built-in’s content
    origin: none
  - id: BR-CAP-ACC-BKS-014-07
    proved_by: [ATS-ACC-BKS-014-06, TST-ACC-BKS-052]
    statement: >-
      Preview renders unsaved sources against kind-specific samples, escapes
      documents as HTML and exports as plain text, identifies empty fields and
      problems and still renders unaffected parts.
    kind: calculation
    enforced_at:
      - service
    must_prove: true
    provenance: test
    source: >-
      services-accounting:modules/books/tests/e2e/document-templates.e2e.spec.js#names
      the merge fields that rendered empty
    origin: none
  - id: BR-CAP-ACC-BKS-014-08
    proved_by: []
    statement: >-
      Each kind exposes allowed variables with type, description and example
      together with its available filters.
    kind: policy
    enforced_at:
      - api
      - service
    must_prove: false
    provenance: test
    source: >-
      services-accounting:modules/books/tests/e2e/document-templates.e2e.spec.js#describes
      each merge field with its type, description and example
    origin: none
  - id: BR-CAP-ACC-BKS-014-09
    proved_by: []
    statement: >-
      The console separates template kinds into tabs without a kind column or
      filter, creates within the current tab and opens read-only editors for
      readers.
    kind: policy
    enforced_at:
      - console
    must_prove: false
    provenance: documented
    source: 'services-accounting:docs/milestones/ACCT-M1-books-and-invoices.md#R25'
    origin: 'services-accounting:docs/milestones/ACCT-M1-books-and-invoices.md#R25'
  - id: BR-CAP-ACC-BKS-014-10
    proved_by: []
    statement: The built-in invoice template contains no invoice line items.
    kind: policy
    enforced_at:
      - service
    must_prove: false
    provenance: documented
    source: 'services-accounting:docs/milestones/plans/ACCT-M1-plan.md#D12'
    origin: 'services-accounting:docs/milestones/plans/ACCT-M1-plan.md#D12'
scenarios:
  - id: SC-CAP-ACC-BKS-014-01
    given: The chapter needs a personalized invoice greeting.
    when: >-
      The controller copies the built-in, inserts an invalid merge-field name
      and saves it.
    then: The error identifies the position; correcting the field permits saving.
    provenance: test
    source: >-
      react-console:acceptance/accounting/playwright/journeys/configuration/ACT-ACC-0026.spec.ts#ACT-ACC-0026
edge_cases: []
constraints: []
depends_on: []
related:
  - CAP-ACC-BKS-015
journeys:
  - JNY-ACC-BKS-004
open_questions: []
evidence:
  - >-
    Verified source file:
    react-console:acceptance/accounting/playwright/journeys/configuration/ACT-ACC-0026.spec.ts
  - 'Verified source file: services-accounting:aws/accounting.service.ts'
  - >-
    Verified source file:
    services-accounting:docs/milestones/ACCT-M1-books-and-invoices.md
  - >-
    Verified source file:
    services-accounting:docs/milestones/plans/ACCT-M1-plan.md
  - >-
    Verified source file:
    services-accounting:modules/books/db/document-templates.table.ts
  - >-
    Verified source file:
    services-accounting:modules/books/tests/e2e/document-templates.e2e.spec.js
  - >-
    Verified source file:
    services-accounting:modules/books/tests/integration/db/document-templates.table.integration.spec.js
  - >-
    Verified source file:
    services-accounting:modules/books/tests/integration/services/persistence/document-templates.queries.integration.spec.js
  - >-
    Verified source file:
    services-accounting:modules/books/tests/unit/document-templates/built-ins.golden.spec.js
  - >-
    Verified source file:
    services-accounting:modules/books/tests/unit/document-templates/filters.spec.js
  - >-
    Verified source file:
    services-accounting:modules/books/tests/unit/document-templates/sample-data.spec.js
  - >-
    Verified source file:
    services-accounting:modules/books/tests/unit/document-templates/template-sources.spec.js
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-005, TC-AZ-006, TC-TEN-001, TC-TEN-002, TC-TEN-003, TC-DAT-001, TC-DAT-002, TC-DAT-004, TC-DAT-005, TC-LOG-001, 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-BKS-05-01, FAS-ACC-BKS-05-02, FAS-ACC-BKS-05-03, FAS-ACC-BKS-05-04, FAS-ACC-BKS-05-05]
suites: [TST-ACC-BKS-020, TST-ACC-BKS-052, TST-ACC-BKS-066, TST-ACC-BKS-163, TST-ACC-BKS-167]
---

# Prepare Accounting document and export templates

## Purpose

Controllers adapt the wording and format of the documents Accounting produces.

## How It Works

The controller opens the tab for the document kind and starts with a built-in copy or a new template. They edit the document’s sources and choose merge fields appropriate to that kind. Preview shows sample output before anything is saved. Validation identifies sources that cannot be used. The controller corrects those problems and saves a customer template. Readers can inspect an editor without changing the template. Assignment to a unit or the statement default is separate from preparing its content.

## Relationships

Template assignment selects prepared content for units and workspace statements.
