Files
accounted/supabase/migrations/20260715120000_credit_note_creation_and_posting_guards.sql
T
Mattsson 072aedeaf9 Fix/supp ag fb (#1023)
* fix: prevent credit notes from entering payment flow

* fix: persist and display customer personal numbers

* feat: configure automatic invoice reminder days

* fix: issue credit notes through send flow

* chore: add repository agent guidance

* feat(mcp): route tools across user companies

* fix(articles): delete unused register entries

* feat(invoices): improve issued invoice actions

* feat(supplier-invoices): retain uploaded source documents

* docs: record implementation decisions

* feat: enhance customer personal number handling and validation

- Updated CustomerForm to allow personal numbers in the format of "********-1234" for individual customers.
- Added validation to ensure personal numbers are only accepted for individual customers in CreateCustomerSchema.
- Implemented masking and encryption for personal numbers to enhance data protection.
- Introduced new utility functions for masking and encrypting personal numbers.
- Added database migration to enforce unique constraints on credit note relationships and prevent duplicate entries.
- Enhanced error handling and logging for credit note issuance and invoice processing.
- Updated tests to cover new credit note creation guards and personal number handling.

* test: enhance list companies test with supabase query mocks
2026-07-15 15:53:15 +02:00

21 lines
847 B
SQL

-- Keep partially-created credit notes invisible and prevent duplicate credit
-- relationships or posted vouchers under concurrent requests.
ALTER TABLE public.invoices
ADD COLUMN IF NOT EXISTS creation_complete boolean NOT NULL DEFAULT true;
CREATE UNIQUE INDEX IF NOT EXISTS uq_invoices_company_credited_invoice
ON public.invoices (company_id, credited_invoice_id)
WHERE credited_invoice_id IS NOT NULL;
CREATE UNIQUE INDEX IF NOT EXISTS uq_posted_credit_note_journal_source
ON public.journal_entries (company_id, source_id)
WHERE source_type = 'credit_note'
AND source_id IS NOT NULL
AND status = 'posted';
COMMENT ON COLUMN public.invoices.creation_complete IS
'False only while a credit-note parent and its items are being assembled. API reads must expose only complete credit notes.';
NOTIFY pgrst, 'reload schema';