سامانه صدور فاکتور و حسابداری
Mirrored from https://github.com/davoodmehraban89/Factor-easy.git
Synced Dec 4, 03:00 UTC
fix(accounting): reject unsafe Rial precision before RPC
davoodmehraban89 committed
Nov 16, 2026 at 07:16 UTC
8a16c87d6b2e16b0224ad700e3c865605512b2c1
2 files changed
+17
js/journal-rpc.js
+4
@@ -26,6 +26,10 @@ function jeRpcHeader(input,companyId,fiscalYearId){
26
reference:String(input.reference||''),voucherType:String(input.voucherType||'manual')};
27
}
28
function jeRpcLines(lines){
29
+ for(const [i,l] of lines.entries()){
30
+ if(!Number.isSafeInteger(Number(l.debit))||!Number.isSafeInteger(Number(l.credit))||Number(l.debit)<0||Number(l.credit)<0)
31
+ throw new Error('مبلغ آرتیکل '+(i+1)+' خارج از محدوده دقت امن ریال است؛ ثبت برای جلوگیری از تغییر مبلغ متوقف شد.');
32
+ }
33
jeValidateLines(lines);
34
return lines.map(l=>({accountId:l.accountId,debit:jeNum(l.debit),credit:jeNum(l.credit),
35
description:String(l.description||''),dimensions:(l.dimensions||[]).map(d=>({
scripts/journal-rpc-adapter.test.mjs
+13
@@ -60,6 +60,19 @@ test('ambiguous draft-create retry reuses the same idempotency key',async()=>{
60
assert.equal(result.id,firstId);
61
});
62
63
+test('unsafe or fractional Rial values are rejected before reaching the RPC',async()=>{
64
+ const h=harness();
65
+ await assert.rejects(()=>h.context.jeRpcCreateDraft({date:'1405/07/19',lines:[
66
+ {accountId:'A1',debit:9007199254740992,credit:0},{accountId:'A2',debit:0,credit:9007199254740992}
67
+ ]}),/محدوده دقت امن/);
68
+ assert.equal(h.calls.length,0);
69
+ const fractional=harness();
70
+ await assert.rejects(()=>fractional.context.jeRpcCreateDraft({date:'1405/07/19',lines:[
71
+ {accountId:'A1',debit:1.5,credit:0},{accountId:'A2',debit:0,credit:1.5}
72
+ ]}),/محدوده دقت امن/);
73
+ assert.equal(fractional.calls.length,0);
74
+});
75
+
76
test('draft update uses the server row version as compare-and-swap token',async()=>{
77
const h=harness({vouchers:[{id:'JV_D',status:'draft',sourceType:'manual',companyId:'CO_A',fiscalYearId:'FY_A',_serverVersion:7}]});
78
await h.context.jeRpcUpdateDraft('JV_D',{date:'1405/07/19',description:'edited',voucherType:'manual',lines:[{accountId:'A1',debit:100,credit:0},{accountId:'A2',debit:0,credit:100}]});