سامانه صدور فاکتور و حسابداری
Mirrored from https://github.com/davoodmehraban89/Factor-easy.git
Synced Dec 3, 23:15 UTC
fix(accounting): migrate every linked source to temporary accounting state
davoodmehraban89 committed
Nov 18, 2026 at 09:09 UTC
a2638836219f61ab0a946f7132b046470cb4e76f
1 file changed
+15
supabase/migrations/20261118100000_journal_document_lifecycle.sql
+15
@@ -225,6 +225,21 @@ BEGIN
225
WHERE s.collection IN ('invoices','purchases')
226
AND (s.data->>'journalVoucherId') IS NOT NULL
227
AND coalesce(s.data->>'accountingStatus','')='posted';
228
+
229
+ -- All other source modules linked to a journal voucher are moved to the
230
+ -- same temporary accounting lifecycle. Operational status fields are left
231
+ -- untouched; only the accounting/document projection is reset.
232
+ UPDATE public.records s
233
+ SET data=(s.data-'accountingPostedAt'-'documentPostedAt'-'documentPostedBy')
234
+ ||jsonb_build_object('documentStatus','draft','accountingStatus','draft'),
235
+ version=s.version+1
236
+ FROM public.records v
237
+ WHERE s.collection<>'journalVouchers'
238
+ AND s.data->>'journalVoucherId'=v.id
239
+ AND v.collection='journalVouchers'
240
+ AND v.organization_id=s.organization_id
241
+ AND v.data->>'status'='draft'
242
+ AND coalesce(s.data->>'accountingStatus','')='posted';
243
END $$;
244
245
REVOKE ALL ON FUNCTION public.finora_journal_allocate_identity(uuid,text,text,text,uuid)