فینورا پرو - سامانه جامع حسابداری و صدور فاکتور
fix(A04): prohibit replacing posted commercial and ledger records during company restore
davoodmehraban89 committed
Oct 16, 2026 at 17:24 UTC
89afa9d6b5a68e2c87010f543d4a9106272cb72d
1 file changed
+31
src/core/CompanyBackupService.js
+31
@@ -74,6 +74,37 @@ export async function restoreCompanyBackup(data, { companyId, userId, mode = 'me
74
counts.skipped++;
75
continue;
76
}
77
+ // Replace mode is NOT permission to rewrite posted commercial or
78
+ // accounting facts. A recovery of older data must be append-only for
79
+ // finalized documents; superseding them requires a new correction.
80
+ let protectedPosted = false;
81
+ if (existing) {
82
+ protectedPosted =
83
+ (store === 'journal_entries' && (existing.status === 'posted' || row.status === 'posted')) ||
84
+ (store === 'invoices' && (existing.financePosted || row.financePosted)) ||
85
+ (store === 'cheques' && (existing.financePosted || row.financePosted)) ||
86
+ (store === 'expenses' && (existing.financePosted || row.financePosted)) ||
87
+ (store === 'treasury' && (existing.recordType === 'transaction' || row.recordType === 'transaction')) ||
88
+ ['stock_movements', 'settlements', 'transactions'].includes(store);
89
+ if (store === 'journal_lines' || store === 'invoice_items') {
90
+ const refStore = store === 'journal_lines' ? 'journal_entries' : 'invoices';
91
+ const refId = store === 'journal_lines' ? row.journalId : row.invoiceId;
92
+ const existingParentId = store === 'journal_lines' ? existing.journalId : existing.invoiceId;
93
+ const parent = await tx.get(refStore, refId);
94
+ const previousParent = refId === existingParentId ? parent :
95
+ await tx.get(refStore, existingParentId);
96
+ protectedPosted = store === 'journal_lines'
97
+ ? parent?.status === 'posted' || previousParent?.status === 'posted'
98
+ : Boolean(parent?.financePosted || previousParent?.financePosted);
99
+ }
100
+ }
101
+ if (existing && protectedPosted) {
102
+ if (!sameImmutableRecord(existing, row)) {
103
+ throw new Error('بازنویسی سند مالی قطعی از فایل پشتیبان مجاز نیست');
104
+ }
105
+ counts.skipped++;
106
+ continue;
107
+ }
108
if (existing && mode === 'merge') {
109
counts.skipped++;
110
continue;