@davoodmehraban89 / Factor-easy / commits / 16796d3
Fork 0

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

Phase 5: harden full restore across ERP collections [skip ci]

davoodmehraban89 committed Sep 29, 2026 at 21:01 UTC 16796d3d575af29e35c27033a84a52e311272566
1 file changed +2 -2
js/sync.js
+2 -2
@@ -136,7 +136,7 @@ function safeId(raw,prefix){
136 }
137 function absorbRecords(imported){
138 const uid=currentUser.id;let count=0;
139 - ['companies','contacts','products','invoices','purchases','cheques','expenses','payments','fiscalYears','accounts','dimensionTypes','dimensionValues','accountDimensionRules','branches','projects','projectLinks','postingProfiles','journalVouchers','journalLines','journalLineDimensions','contracts','contractAmendments','contractParties','contractDeductions','guarantees','guaranteeEvents','contractStatements','phase4Audit'].forEach(key=>{
139 + ['companies','contacts','products','invoices','purchases','cheques','expenses','payments','fiscalYears','accounts','dimensionTypes','dimensionValues','accountDimensionRules','branches','projects','projectLinks','postingProfiles','journalVouchers','journalLines','journalLineDimensions','contracts','contractAmendments','contractParties','contractDeductions','guarantees','guaranteeEvents','contractStatements','phase4Audit','warehouses','stockMovements','inventoryCounts','fixedAssets','assetDepreciations','currencies','exchangeRates','costCenters','importBatches','integrationConnections','integrationOutbox','phase5Audit'].forEach(key=>{
140 if(!Array.isArray(imported[key]))return;
141 imported[key].forEach(raw=>{
142 if(!raw||typeof raw!=='object')return;
@@ -144,7 +144,7 @@ function absorbRecords(imported){
144 item.id=safeId(item.id,key.slice(0,3));
145 item.ownerUserId=uid;
146 const idx=datastore[key].findIndex(x=>x.id===item.id&&x.ownerUserId===uid);
147 - if(idx>=0)datastore[key][idx]=item;else datastore[key].push(item);
147 + if(idx>=0){const old=datastore[key][idx],immutable=(key==='journalVouchers'&&['posted','reversed'].includes(old.status))||(['stockMovements','inventoryCounts','assetDepreciations'].includes(key)&&old.status==='posted');if(immutable&&JSON.stringify(old)!==JSON.stringify(item))throw new Error('تعارض با سابقه قطعی در '+key+' / '+item.id);datastore[key][idx]=item;}else datastore[key].push(item);
148 count++;
149 });
150 });