Skip to content

Add credit notes - #194

Merged
kittendevv merged 2 commits into
kittendevv:mainfrom
Bouni:feat/credit-notes
Nov 26, 2026
Merged

kittendevv merged 2 commits into
kittendevv:mainfrom
Bouni:feat/credit-notes

Conversation

@Bouni

@Bouni Bouni commented Nov 20, 2026

Copy link
Copy Markdown
Contributor

Summary

Closes #191

Issued invoices can't be edited, and the error messages already tell users to "issue a credit note instead", but there was no way to do that. This adds credit notes.

Workflow: on an issued invoice (sent, overdue, paid or complete), choose More → Create credit note. This opens a draft copy of the invoice that references it. Edit the draft to credit only part of the invoice, then publish it like an invoice.

Changes

Data

  • New columns invoices.document_type (invoice | credit_note, default invoice) and invoices.credited_invoice_id, added by the usual column migration and included in the table rebuild for old databases.
  • Credit notes store positive amounts; the document type makes them a credit (this is also how UBL, CII and FatturaPA expect them).
  • Invoice details include creditedInvoice (for credit notes) and creditNotes (for invoices).
  • POST /api/v1/invoices/:id/credit-note (permission invoices:create). Drafts, voided invoices and credit notes can't be credited.

Numbering

  • By default credit notes take the next invoice number, so invoices and credit notes form one continuous sequence (required e.g. in Bulgaria, see Invoice Numbering does not change with a custom one #152).
  • Settings → Numbering → "Credit note numbers" can switch to an own pattern (default CN-{YYYY}-{SEQ}).
  • Numbers are assigned when the credit note leaves draft.

PDF / HTML

  • Credit notes swap in credit-note labels (title, number, date, headings) in all invoice languages, so every template, including custom ones, says "Credit Note" (German: "Rechnungskorrektur").
  • The built-in templates show "Credit note for invoice ()".
  • Downloads and email attachments are named credit-note-<number>.pdf/.xml; the email body says "Credit note".

E-invoice XML

  • UBL: CreditNote document (CreditNote-2 namespace), CreditNoteTypeCode 381, BillingReference/InvoiceDocumentReference, CreditNoteLine/CreditedQuantity, no header DueDate.
  • Factur-X / ZUGFeRD: TypeCode 381 and InvoiceReferencedDocument (BG-3) after the monetary summation.
  • FatturaPA: TipoDocumento TD04 and DatiFattureCollegate.

App

  • Invoice list and dashboard: "Credit note" badge and negative totals.
  • Invoice page links to its credit notes; credit note page links to the invoice.
  • Dashboard revenue, billed, paid and outstanding subtract credit notes, and they don't count as open invoices or as additional sales.
  • The public page heading says "Credit note".
  • Translations for all new strings in all locales.

Verification

  • New backend/src/controllers/credit_notes_test.ts (10 tests): creation and references, which invoices can be credited, shared and separate numbering, duplicating, no overdue status, UBL/Factur-X/FatturaPA output, PDF labels in English and German.
  • New frontend tests for the signed totals and the dashboard figures with credit notes.
  • All backend and frontend tests pass, deno check and svelte-check have no errors.
  • Clicked through on a fresh instance built from this branch: invoice RE-001 (2 × 50 + 19% = 119.00) → credit note for 1 × 50 → published as RE-002 (59.50), next invoice RE-003. With the separate pattern GS-{SEQ} the next credit note became GS-001. The PDF, UBL and Factur-X files were checked by hand and are well-formed; they were not run through an official validator.

Not included

  • No limit on how much of an invoice can be credited: several credit notes can together exceed the invoice total.
  • Debit notes.

Note: this touches the same numbering code and settings section as #192 and #193, so whichever is merged later needs a small conflict resolution.

🤖 Generated with Claude Code

Issued invoices can now be corrected with a credit note instead of being
edited ("Create credit note" in the invoice's More menu). The credit note
starts as a draft copy of the invoice that references it; edit it to
credit only part of the invoice, then publish it like an invoice.

- Data: invoices.document_type ('invoice' | 'credit_note') and
  invoices.credited_invoice_id. Credit notes store positive amounts; the
  document type makes them a credit.
- Numbering: credit notes share the invoice counter by default (one
  continuous sequence, as required e.g. in Bulgaria). Under Numbering they
  can get their own pattern instead (default CN-{YYYY}-{SEQ}).
- PDF/HTML: credit-note title and labels in all invoice languages, and a
  "Credit note for invoice <number> (<date>)" line in the built-in
  templates. Downloads are named credit-note-<number>.
- XML: UBL exports a CreditNote document (type 381, BillingReference,
  CreditNoteLine/CreditedQuantity, no header DueDate); Factur-X/ZUGFeRD
  uses type 381 with InvoiceReferencedDocument; FatturaPA uses TD04 with
  DatiFattureCollegate.
- UI: credit notes are marked in the invoice list and dashboard and shown
  with negative totals; an invoice links to its credit notes and vice
  versa. Dashboard revenue, billed, paid and outstanding subtract credit
  notes, and they are not counted as open invoices.

Closes kittendevv#191

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Bouni Bouni mentioned this pull request Nov 20, 2026
@kittendevv

Copy link
Copy Markdown
Owner

Could you possibly resolve the merge conflicts

@kittendevv

Copy link
Copy Markdown
Owner

Then its ready to merge

@Bouni

Bouni commented Nov 25, 2026

Copy link
Copy Markdown
Contributor Author

Let me check

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CsybXd62SCcD732L4x6uYX
@Bouni

Bouni commented Nov 25, 2026

Copy link
Copy Markdown
Contributor Author

@kittendevv merge conflict resolved

@kittendevv
kittendevv merged commit 47402cc into kittendevv:main Nov 26, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Credit/debit notes sharing the invoice number sequence

2 participants