سامانه صدور فاکتور و حسابداری
Mirrored from https://github.com/davoodmehraban89/Factor-easy.git
Synced Dec 4, 00:30 UTC
test: reject generic mutations of posted sale and purchase vouchers
davoodmehraban89 committed
Nov 17, 2026 at 21:56 UTC
3c947ffd481b6e915b04527ab8faf3183e8ca78c
1 file changed
+11
scripts/accounting-document-workflow.spec.js
+11
@@ -32,6 +32,12 @@ async function installHarness(page,server){
32
for(const row of args.p_upserts||[]){
33
const key=row.collection+'|'+row.id,current=server.records.get(key);
34
const currentVersion=current?(Number(current.version)||1):0;
35
+ const parentVoucherId=row.collection==='journalLines'?(row.data?.voucherId||current?.data?.voucherId):null;
36
+ const parentVoucher=parentVoucherId?server.records.get('journalVouchers|'+parentVoucherId):null;
37
+ if(row.collection==='journalVouchers'&¤t&¤t.data.status==='posted'&&['sale','purchase'].includes(current.data.sourceType))
38
+ return {error:{message:'FINORA_POSTED_SOURCE_VOUCHER_IMMUTABLE',code:'23514'}};
39
+ if(row.collection==='journalLines'&&parentVoucher&&parentVoucher.data.status==='posted'&&['sale','purchase'].includes(parentVoucher.data.sourceType))
40
+ return {error:{message:'FINORA_POSTED_SOURCE_VOUCHER_IMMUTABLE',code:'23514'}};
41
if(Number(row.expected_version||0)!==currentVersion)return {error:{message:'FINORA_VERSION_CONFLICT',code:'40001'}};
42
const version=currentVersion+1;
43
server.records.set(key,{collection:row.collection,id:row.id,data:copy(row.data),version});
@@ -41,6 +47,11 @@ async function installHarness(page,server){
47
for(const row of args.p_deletes||[]){
48
const key=row.collection+'|'+row.id,current=server.records.get(key);
49
const currentVersion=current?(Number(current.version)||1):0;
50
+ const parentVoucherId=row.collection==='journalLines'?current?.data?.voucherId:null;
51
+ const parentVoucher=parentVoucherId?server.records.get('journalVouchers|'+parentVoucherId):null;
52
+ if((row.collection==='journalVouchers'&¤t?.data?.status==='posted'&&['sale','purchase'].includes(current.data.sourceType))||
53
+ (row.collection==='journalLines'&&parentVoucher?.data?.status==='posted'&&['sale','purchase'].includes(parentVoucher.data.sourceType)))
54
+ return {error:{message:'FINORA_POSTED_SOURCE_VOUCHER_IMMUTABLE',code:'23514'}};
55
if(!current||Number(row.expected_version)!==currentVersion)return {error:{message:'FINORA_VERSION_CONFLICT',code:'40001'}};
56
server.records.delete(key);deletes.push({collection:row.collection,id:row.id});
57
}