Updated GL system allows changing account defaults and add/updating journal entries

This commit is contained in:
2026-06-08 11:43:02 -05:00
parent 582720bf01
commit 15e93c1e45
16 changed files with 980 additions and 495 deletions

View File

@@ -1839,6 +1839,36 @@ async function main() {
const glB = (await request('/api/books/GAAP/gl-entries', { headers: companyHeaders(companyB) })).entries;
if (glB.some((e) => e.id === glEntry.id)) throw new Error('Company B sees company A GL entries');
// ---- GL chart of accounts + posting defaults -------------------------------
const seededChart = await request('/api/gl-accounts', { headers: companyHeaders(companyA) });
if (seededChart.accounts.length < 5 || !seededChart.defaults.asset_account) throw new Error('Chart of accounts / posting defaults were not seeded');
const newAcct = (await request('/api/gl-accounts', {
method: 'POST', headers: companyHeaders(companyA),
body: JSON.stringify({ code: `1501-${suffix}`, name: 'Equipment — Co A', type: 'asset', normal_balance: 'debit' })
})).account;
if (!newAcct || newAcct.entity_id !== companyA) throw new Error('GL account was not created/scoped');
await request(`/api/gl-accounts/${newAcct.id}`, { method: 'PUT', headers: companyHeaders(companyA), body: JSON.stringify({ name: 'Equipment — revised' }) });
// Point the asset-cost posting default at the new account and confirm the ledger posts to it.
await request('/api/gl-account-defaults', { method: 'PUT', headers: companyHeaders(companyA), body: JSON.stringify({ asset_account: `1501-${suffix}` }) });
const ledgerA = (await request('/api/books/GAAP/ledger?year=2026', { headers: companyHeaders(companyA) })).ledger;
if (!ledgerA.accounts.some((a) => a.account === `1501-${suffix}` && a.type === 'Asset cost')) {
throw new Error('Ledger did not use the configured default asset account');
}
// GL account + defaults changes are audited.
const acctAudit = await request('/api/audit-logs?entity_type=gl_account', { headers: auth });
if (acctAudit.total < 2) throw new Error('GL account changes were not audited');
if ((await request('/api/audit-logs?entity_type=gl_account_defaults', { headers: auth })).total < 1) {
throw new Error('GL account-default change was not audited');
}
// Isolation: company B has its own seeded chart, not company A's custom account.
const acctsB = (await request('/api/gl-accounts', { headers: companyHeaders(companyB) })).accounts;
if (!acctsB.length) throw new Error('Company B chart of accounts was not seeded');
if (acctsB.some((a) => a.code === `1501-${suffix}`)) throw new Error('Company B sees company A GL account');
console.log('Smoke test passed');
}