Depreciation report: 0% depreciation category is missing from the report

Aperta
#5,250 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 2 giorni

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
54/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
graphql, typescript
Ambito
api, backend

Direzione di ricerca

Start by reproducing the issue in the depreciation report, then inspect packages/server/src/modules/reports/helpers/depreciation-report.helper.ts, especially calculateDepreciation, and the resolver at reports/resolvers/depreciation-report.resolver.ts. Trace the client table under components/screens/reports/depreciation-report/ if the category is still absent after fixing the calculations. Add the requested helper and resolver tests; done means a 0% category reports cost and net value correctly with no NaN or Infinity, while non-zero results remain unchanged.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

annual-audit-workflow depreciation

Bug

A depreciation category with a 0% rate works on the charge side (entering it on a charge, generating the ledger), but it does not show up in the depreciation report. Make the report present it.

Likely cause

The report maths in packages/server/src/modules/reports/helpers/depreciation-report.helper.ts (calculateDepreciation) divides by the rate and doesn't handle a rate of 0:

  • With no explicit end date, yearsToFullDepreciation = 1 / normalizedRate is Infinity, so the computed fullDepreciationYear and depreciationEndDate are garbage (Math.ceil(Infinity), then date maths on it).
  • The return value computes depreciationRate * (yearlyDepreciationAmount / annualDepreciationAmount), which is 0 * (0 / 0) = NaN when the annual amount is 0.

NaN amounts can't be serialized as GraphQL Float, and the bad dates can throw. So the depreciationReport resolver (reports/resolvers/depreciation-report.resolver.ts) probably fails for that record or category, and the category is missing from the result. I haven't run the report with a 0% category, so please confirm by reproducing first.

The ledger side apparently doesn't hit this, which is why generation works.

Expected behavior

  • A 0% category appears in the depreciation report with its assets: original cost / report-year additions, 0 yearly depreciation, 0 accumulated depreciation, and net value equal to cost (the asset never depreciates).
  • The statutory rate shows 0%, and the claimed rate shows 0 (or -), never NaN.
  • The report totals and calculateDepreciationAmount (used for the tax report) stay correct, and 0% records contribute 0.

Suggested fix

  • In calculateDepreciation, handle a rate of 0 up front. Return yearlyDepreciationAmount: 0, yearlyDepreciationRate: 0 and pastDepreciationAmount: 0 (or 0 / activation checks as appropriate) before any division. Never compute 1 / normalizedRate or the x / annualDepreciationAmount ratio when the rate or annual amount is 0.
  • Guard the ratio in the returned yearlyDepreciationRate against annualDepreciationAmount === 0.
  • Check the client table (components/screens/reports/depreciation-report/) for assumptions that hide empty or zero-rate rows. Its claimedDepreciationRate ? ... : ... truthiness check is OK for 0 but worth a look.
  • Make sure rows aren't dropped silently: the resolver logs and returns when a category or charge is missing, so consider surfacing that.

Acceptance criteria

  • A 0% category with records appears in the depreciation report for the relevant year, with correct cost and net value.
  • No NaN / Infinity in any returned field.
  • Unit tests for calculateDepreciation with rate 0 (activated this year, in a past year, with and without an end date), and a resolver-level test with a 0% category.
  • Non-zero categories are unchanged.

Generated by Claude Code

Lingua principale
TypeScript
Stelle
30
Fork
10
Merge medio
2g 12h
PR unite (30g)
276

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di Urigo/accounter-fullstack

Tutte le issue di Urigo/accounter-fullstack

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.