@davoodmehraban89 / Factor-easy / commits / 45dd08e
Fork 0

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

Test Excel account-type normalization and validation

davoodmehraban89 committed Sep 29, 2026 at 22:29 UTC 45dd08e91c17eac5a0ac0fdb0ff0e0989a9e3022
1 file changed +3 -2
scripts/phase2-check.mjs
+3 -2
@@ -31,11 +31,12 @@ const ctx={console};vm.createContext(ctx);vm.runInContext(af,ctx);
31 const imported=vm.runInContext(`afNormalizeAccountImportRows([
32 {'کد':'1','عنوان':'دارایی‌ها','سطح':'کل','ماهیت':'بدهکار'},
33 {'کد':'11','عنوان':'دارایی جاری','سطح':'معین','کد والد':'1','ماهیت':'بدهکار'},
34 - {'کد':'1101','عنوان':'بانک','سطح':'تفصیلی','کد والد':'11','ماهیت':'بدهکار'}
34 + {'کد':'1101','عنوان':'بانک','سطح':'تفصیلی','کد والد':'11','ماهیت':'بدهکار','نوع حساب':'دارایی'}
35 ])`,ctx);
36 -if(imported.length!==3||imported[2].level!=='detail'||imported[2].parentCode!=='11'||imported[2].normalBalance!=='debit')throw new Error('Chart Excel normalization behavior failed');
36 +if(imported.length!==3||imported[2].level!=='detail'||imported[2].parentCode!=='11'||imported[2].normalBalance!=='debit'||imported[2].accountType!=='asset')throw new Error('Chart Excel normalization behavior failed');
37 let badParent=false;try{vm.runInContext(`afNormalizeAccountImportRows([{'کد':'1101','عنوان':'بانک','سطح':'تفصیلی','کد والد':'99'}])`,ctx)}catch(_){badParent=true}
38 if(!badParent)throw new Error('Chart import must reject invalid hierarchy');
39 +let badType=false;try{vm.runInContext(`afNormalizeAccountImportRows([{'کد':'1','عنوان':'نمونه','سطح':'کل','نوع حساب':'نامعتبر'}])`,ctx)}catch(_){badType=true}if(!badType)throw new Error('Chart import must reject unknown account types');
40 ctx.values=[{id:'ROOT',dimensionTypeId:'D1',depth:1,active:true},{id:'LEAF',dimensionTypeId:'D1',parentId:'ROOT',depth:2,active:true}];ctx.dimTypes=[{id:'D1',sourceEntity:'manual',maxDepth:2,active:true}];ctx.alerts=[];Object.assign(ctx,{requireWrite:()=>true,alert:m=>ctx.alerts.push(m),prompt:()=>3,saveDatastore:()=>true,renderAccountingFoundation:()=>{}});vm.runInContext("getMyDimensionValues=()=>values;getMyDimensionTypes=()=>dimTypes;",ctx);
41 const leafState=vm.runInContext("({root:afDimensionValuePostable(values[0],dimTypes[0]),leaf:afDimensionValuePostable(values[1],dimTypes[0])})",ctx);
42 if(leafState.root!==false||leafState.leaf!==true)throw new Error('leaf-only analytic posting behavior failed');