@davoodmehraban89 / Factor-easy-2 Mirror · read-only / commits / 70b001d
Fork 0

سامانه صدور فاکتور و حسابداری

Mirrored from https://github.com/davoodmehraban89/Factor-easy.git

Synced Dec 4, 00:30 UTC

fix(db): reject null autopost source types and kinds

davoodmehraban89 committed Nov 17, 2026 at 21:40 UTC 70b001d8e9323e07af35f5cb182852925b3a8c5f
1 file changed +2 -2
supabase/migrations/20261117110000_wp1_autopost_source_link_atomic.sql
+2 -2
@@ -9,7 +9,7 @@ DECLARE typ text:=p_header->>'sourceType';coll text;source public.records%rowtyp
9 cfg_version bigint;lines jsonb;draft jsonb;posted jsonb;voucher public.records%rowtype;
10 prior public.records%rowtype;v_prior_effective_status text;
11 BEGIN
12 - IF typ NOT IN ('sale','purchase') THEN
12 + IF coalesce(typ,'') NOT IN ('sale','purchase') THEN
13 RAISE EXCEPTION 'FINORA_AUTOPOST_CONTRACT_UNSUPPORTED' USING ERRCODE='23514';END IF;
14 coll:=CASE WHEN typ='sale' THEN 'invoices' ELSE 'purchases' END;
15 IF p_source_collection IS DISTINCT FROM coll OR coalesce(p_source_id,'')=''
@@ -24,7 +24,7 @@ BEGIN
24 AND private.can_access_record(p_organization_id,coll,owner_id,data,'create') FOR UPDATE;
25 IF NOT FOUND THEN
26 RAISE EXCEPTION 'FINORA_SOURCE_NOT_COMMITTED_IN_ORG' USING ERRCODE='23503';END IF;
27 - IF (typ='sale' AND source.data->>'kind' NOT IN ('formal','non_formal'))
27 + IF (typ='sale' AND coalesce(source.data->>'kind','') NOT IN ('formal','non_formal'))
28 OR coalesce(source.data->>'accountingVersion','1')
29 IS DISTINCT FROM coalesce(p_header->>'sourceVersion','1') THEN
30 RAISE EXCEPTION 'FINORA_SOURCE_TYPE_OR_VERSION_MISMATCH' USING ERRCODE='23514';END IF;