سامانه صدور فاکتور و حسابداری
Mirrored from https://github.com/davoodmehraban89/Factor-easy.git
Synced Dec 4, 09:15 UTC
test(wp4): prove linked source and voucher are persisted DRAFT before blocked source delete
davoodmehraban89 committed
Nov 23, 2026 at 23:15 UTC
65e667b9b77aab8bcdb4a436ddad0a6e6b138b1a
1 file changed
+15
supabase/tests/wp4_journal_document_lifecycle.sql
+15
@@ -205,6 +205,21 @@ BEGIN
205
'date',(SELECT data->>'startDate' FROM public.records WHERE organization_id=org AND collection='fiscalYears' AND id=fy),
206
'sourceType','sale','sourceId','WP4_INV_B','status','draft'));
207
208
+ -- Strict positive preconditions: both *persisted* linked records are
209
+ -- genuinely draft before testing source -> voucher atomic deletion.
210
+ IF NOT EXISTS (
211
+ SELECT 1 FROM public.records s JOIN public.records v
212
+ ON v.organization_id=s.organization_id
213
+ AND v.collection='journalVouchers'
214
+ AND v.id=s.data->>'journalVoucherId'
215
+ WHERE s.organization_id=org AND s.collection='invoices' AND s.id='WP4_INV_B'
216
+ AND s.data->>'documentStatus'='draft'
217
+ AND s.data->>'accountingStatus'='draft'
218
+ AND s.data->>'journalVoucherId'='WP4_SOURCE_V_B'
219
+ AND v.data->>'status'='draft'
220
+ AND v.data->>'sourceType'='sale' AND v.data->>'sourceId'='WP4_INV_B'
221
+ ) THEN RAISE EXCEPTION 'WP4_LINKED_DRAFT_PRECONDITIONS_MISSING'; END IF;
222
+ RAISE NOTICE 'WP4_LINKED_SOURCE_AND_VOUCHER_ARE_DRAFT_PASS';
223
DELETE FROM public.records WHERE organization_id=org AND collection='invoices' AND id='WP4_INV_B';
224
IF EXISTS(SELECT 1 FROM public.records WHERE organization_id=org AND collection='journalVouchers' AND id='WP4_SOURCE_V_B')
225
THEN RAISE EXCEPTION 'WP4_SOURCE_DELETE_DID_NOT_DELETE_VOUCHER'; END IF;