فینورا پرو - سامانه جامع حسابداری و صدور فاکتور

fix(A04): retain original author of historical ledger and treasury records on restore

davoodmehraban89 committed Oct 16, 2026 at 17:25 UTC fe7f84c3985fac1216e66269a58657d6b842acf7
1 file changed +10 -1
src/core/CompanyBackupService.js
+10 -1
@@ -14,6 +14,11 @@ export const COMPANY_BACKUP_STORES = Object.freeze([
14 'audit_events', 'document_corrections'
15 ]);
16 const V2_STORES = new Set(['account_chart', 'fiscal_periods', 'journal_entries', 'journal_lines']);
17 +const HISTORICAL_ACTOR_STORES = new Set([
18 + 'journal_entries', 'journal_lines', 'invoices', 'invoice_items',
19 + 'stock_movements', 'settlements', 'treasury', 'transactions',
20 + 'cheques', 'expenses'
21 +]);
22 const isId = id => typeof id === 'string' && id.trim().length > 0;
23
24 // Backups serialize object fields in arbitrary insertion order. Immutable
@@ -59,7 +64,11 @@ export async function restoreCompanyBackup(data, { companyId, userId, mode = 'me
64 throw new Error('رویداد ممیزی یا اصلاح سند متعلق به شرکت دیگری است');
65 }
66 const row = { ...incoming, companyId };
62 - if (row.ownerUserId && !immutable) row.ownerUserId = userId;
67 + // Never rewrite the original actor of an accounting/treasury event.
68 + // The administrator performing recovery is recorded in backup_restored.
69 + if (row.ownerUserId && !immutable && !HISTORICAL_ACTOR_STORES.has(store)) {
70 + row.ownerUserId = userId;
71 + }
72 if (store === 'journal_entries' && row.sourceType && row.sourceId) {
73 row.sourceKey = journalSourceKey(companyId, row.sourceType, row.sourceId, row.revision || 1);
74 }