سامانه صدور فاکتور و حسابداری
Mirrored from https://github.com/davoodmehraban89/Factor-easy.git
Synced Dec 3, 23:15 UTC
Add negative accounting invariant scenarios
davoodmehraban89 committed
Sep 29, 2026 at 22:15 UTC
f7d9b033e45416260b8062e413ef9340b59b6e9d
1 file changed
+6
-1
scripts/phase3-behavior-check.mjs
+6
-1
@@ -9,12 +9,17 @@ const accounts=[
9
{id:'rev',code:'4101',title:'فروش',active:true,postingAllowed:true},{id:'buy',code:'5101',title:'خرید',active:true,postingAllowed:true},
10
{id:'exp',code:'6103',title:'هزینه',active:true,postingAllowed:true},{id:'inc',code:'4201',title:'سایر درآمد',active:true,postingAllowed:true}];
11
const fiscal=[{id:'FY1',startDate:'1405/01/01',endDate:'1405/12/29',status:'open'}];
12
+const rules=[],dimensions=[],dimensionValues=[];
13
const ctx={console,datastore,currentUser:{id:'U1'},requireWrite:()=>true,afCompanyId:()=> 'C1',afId:p=>p+'_'+(++seq),toEnDigits:String,getJalaliNumeric:()=> '1405/07/07',
13
-getMyFiscalYears:()=>fiscal,getMyAccounts:()=>accounts,getMyAccountDimensionRules:()=>[],getMyDimensionTypes:()=>[],afResolvedValues:()=>[],saveDatastore:()=>true,
14
+getMyFiscalYears:()=>fiscal,getMyAccounts:()=>accounts,getMyAccountDimensionRules:()=>rules,getMyDimensionTypes:()=>dimensions,afResolvedValues:t=>dimensionValues.filter(v=>v.dimensionTypeId===t.id),saveDatastore:()=>true,
15
getMyInvoices:()=>[],getMyPurchases:()=>[],getMyPayments:()=>[],getMyExpenses:()=>[]};
16
vm.createContext(ctx);vm.runInContext(source,ctx);
17
const assert=(ok,msg)=>{if(!ok)throw new Error(msg)};
18
ctx.jeEnsureDefaultProfiles();
19
+let unbalanced=false;try{ctx.jeCreateDraft({date:'1405/07/07',description:'bad',sourceType:'manual',sourceId:'BAD1',lines:[{accountId:'cash',debit:100,credit:0,dimensions:[]},{accountId:'rev',debit:0,credit:90,dimensions:[]}]})}catch(_){unbalanced=true}assert(unbalanced,'unbalanced journal must be rejected');
20
+dimensions.push({id:'D_PARTY',sourceEntity:'contact',active:true});dimensionValues.push({id:'CUST1',dimensionTypeId:'D_PARTY',postable:true},{id:'OTHER',dimensionTypeId:'D_PARTY',postable:false});rules.push({accountId:'ar',dimensionTypeId:'D_PARTY',applicability:'required',active:true});
21
+let missingDim=false;try{ctx.jeCreateDraft({date:'1405/07/07',description:'missing dim',sourceType:'manual',sourceId:'BAD2',lines:[{accountId:'ar',debit:100,credit:0,dimensions:[]},{accountId:'rev',debit:0,credit:100,dimensions:[]}]})}catch(_){missingDim=true}assert(missingDim,'required analytic dimension must be enforced');
22
+let invalidDim=false;try{ctx.jeCreateDraft({date:'1405/07/07',description:'invalid dim',sourceType:'manual',sourceId:'BAD3',lines:[{accountId:'ar',debit:100,credit:0,dimensions:[{dimensionTypeId:'D_PARTY',dimensionValueId:'OTHER'}]},{accountId:'rev',debit:0,credit:100,dimensions:[]}]})}catch(_){invalidDim=true}assert(invalidDim,'non-postable analytic value must be rejected');
23
const receipt={id:'PAY1',date:'1405/07/07',amount:125000,contactId:'CUST1'};
24
const v=ctx.jePostSourceRecord('receipt',receipt);
25
assert(v.status==='posted','receipt must post');