Annual audit: tests for the loss-year tax charge, and detect step 4 charges by tax category
Maintainers usually reply within 2 days
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 45/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- postgresql, typescript
Research direction
Start with financial-charges.resolver.ts and charges.provider.ts to trace how annual charges are queried and matched, then check each generator’s tax category, especially the bank-deposits revaluation charge. Add the generator, regeneration, SHAAM 6111, and annual charge integration tests described in the issue; run the listed Vitest commands with a local Postgres database. Done means all six charges are found by category without a ledger, edited descriptions still match, the fallback is removed, and the tests pass in CI.
Written by the indexing model from the issue text.
Description
Follow-up to #5086, fixed in #5096 (epic #5085). Links point to main at the #5096 merge commit (4d5ba86).
Background
#5096 made current tax never negative. In a loss year, the tax-expense charge now gets no tax ledger entry. Two things were left out to keep that PR small:
- tests for the generator, the step 4 lookup and 6111 (they were in the #5086 acceptance criteria);
- a reliable way for step 4 to find annual financial charges.
Part 1: missing tests
Today only the pure computeCurrentTax is tested (tax.helper.test.ts).
1a. Tax-expense generator (unit)
- Code:
generateLedgerRecordsForTaxExpenses- It calls
calculateTaxAmountsand pushes the tax entry only whencurrentTaxExpense > 0(L127). - It then appends the misc-expense entries.
- It calls
- Pattern to copy: monthly-vat-ledger-generation.resolver.test.ts. It mocks helper modules with
vi.mockand fakes the injector. - What to mock:
calculateTaxAmountsandcalculateCumulativeRnDExpenses(reports/helpers/tax.helper.js);generateMiscExpensesLedgerandstoreInitialGeneratedRecords;- the
LedgerProvider,FinancialEntitiesProviderandAdminContextProviderinjector lookups.
- Cases:
- profit year: one entry, Dr
taxExpensesTaxCategoryId/ CrtaxBusinessIdforcurrentTaxExpense, dated 31 Dec; - loss year (
currentTaxExpense = 0): no tax entry, misc-expense entries still returned; - no description, or no year in it:
CommonError.
- profit year: one entry, Dr
1b. Regenerating removes the old wrong entry (unit)
- Code: regeneration matches stored records against new ones with
ledgerRecordsGenerationPartialMatchComparison. Every stored record left unmatched goes totoRemove, which the regenerate flow deletes. - Test: call it with one stored tax-expense record and
newRecords = [], and assert that the record ends up intoRemove. That is the "existing data" acceptance criterion of #5086.
1c. 6111 in a loss year (integration)
- Pattern to copy: shaam6111.integration.test.ts. It seeds books through the real app and checks
balanceSheet/profitAndLosscodes, for exampleamountOf(data.balanceSheet, 9980)at L443. - New case: books with a pre-tax loss and no tax-expense entry. Assert:
- 5600 is 0;
- 9980 equals the accumulated result including the loss (see
retainedProfitFromProfitAndLoss, shaam6111-computation.helper.ts); - 500 equals the (negative) taxable income.
1d. Step 4 finds a ledger-less tax charge (integration)
Covered by Part 2 below.
Part 2: detect step 4 charges by tax category
Current behaviour
annualFinancialCharges loads the year's FINANCIAL charges with fromAnyDate / toAnyDate = year. It then finds each of the six charges by checking whether its ledger's business_array contains a tax category or business.
That breaks for a charge with no ledger:
- No dates: the date filter in
getChargesByFiltersisGREATEST/LEASTover document, transaction, ledger and securities dates. A charge with none of them hasNULLdates and is filtered out. - No businesses:
business_arrayis empty as well.
Stop-gap from #5096 (tax charge only, L63-L78)
If the normal lookup misses, a second query without dates uses freeText: "Tax expenses charge for YYYY" and picks the charge whose tax_category_id is taxExpensesTaxCategoryId. Problems:
- Fragile: it depends on the exact description written by
generateTaxExpensesCharge. Rename the charge and step 4 shows "Missing" again.freeTextalso matches transaction and document text, which is harmless here but imprecise. - Partial: the other five charges (revaluation, depreciation, recovery reserve, vacation reserve, bank-deposits revaluation) still need a ledger to be found.
Proposed fix
- Find each charge by its own tax category.
generateAndTagChargestorescharges.tax_category_idon every generated financial charge, and the provider already returns it (charges.provider.ts L751).- Watch out: the bank-deposits charge is matched today by
bankDepositBusinessId, not by a tax category. Check which categorygenerateBankDepositsRevaluationChargepasses before switching it.
- Watch out: the bank-deposits charge is matched today by
- Make the year lookup independent of ledger dates. Options, simplest first:
- (a) Filter in SQL by
type = 'FINANCIAL',owner_idandtax_category_id IN (...), without the date filter, then pick the charge whose year matches. Every generator puts the year or date inuser_description, and the ledger generators parse it the same way (see the year regex in the tax generator, L52-L58). - (b) Add a dedicated column or filter (for example a period date on the charge). This needs a migration.
- (a) Filter in SQL by
- Remove the description-based fallback added in #5096.
- No client change. Step 4 UI only reads which charges are present.
Tests
- Integration (
packages/server/src/modules/charges/**/*.integration.test.tsorpackages/server/src/__tests__/): seed aFINANCIALcharge with the tax-expense category, the descriptionTax expenses charge for 2025and no ledger, documents or transactions. Assert thatannualFinancialCharges(year: "2025-01-01")returns it astaxExpensesCharge. - Repeat with an edited description once Part 2 lands.
How to run
yarn generate
yarn vitest run --project unit packages/server/src/modules/ledger packages/server/src/modules/reports/helpers
yarn vitest run --project integration packages/server/src/__tests__/shaam6111.integration.test.ts
Integration tests need Postgres and migrations (see the README, Testing). Make sure POSTGRES_* points at a local DB, not the one in the root .env.
Done when
- The tests in 1a, 1b, 1c and 1d exist and pass in CI.
- All six annual financial charges are found by tax category, including a charge with no ledger.
- Editing a generated charge's description doesn't make step 4 report it as missing.
- The
freeTextfallback is gone.
- Dominant language
- TypeScript
- Stars
- 30
- Forks
- 10
- Avg merge
- 2d 12h
- Merged PRs (30d)
- 276
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from Urigo/accounter-fullstack
-
Difficulty 2/5 1-3 hours Newbie friendliness 73/100
Urigo/accounter-fullstack#5302 ·
Maintainers usually reply within 2 days
-
1214 annual-audit-workflow
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Urigo/accounter-fullstack#5257 ·
Maintainers usually reply within 2 days
-
1214 annual-audit-workflow
Difficulty 2/5 1-3 hours Newbie friendliness 83/100
Urigo/accounter-fullstack#5256 ·
Maintainers usually reply within 2 days
-
annual-audit-workflow
Difficulty 1/5 1-3 hours Newbie friendliness 87/100
Urigo/accounter-fullstack#5252 ·
Maintainers usually reply within 2 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 83/100
Urigo/accounter-fullstack#4919 ·
Maintainers usually reply within 2 days
All issues in Urigo/accounter-fullstack
Similar issues
-
area: integrations documentation priority: P2 size: XS
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
eddiejaoude/StackDash#798 ·
Maintainers usually reply within 1 day
-
bot:ai-assisted component:midnight-js status:untriaged
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
midnightntwrk/midnight-js#1790 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Maintainers usually reply within 1 day
-
area:vscode bug has repro platform:macos platform:vscode regression
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
anthropics/claude-code#113502 ·
-
Add: Rajdhani TV HDOpencheck:passed streams:add
Difficulty 1/5 Under an hour Newbie friendliness 77/100
Maintainers usually reply within 1 day