opcn1214-generator: cg.improvements.expense compares raw floats, so a valid report can fail to generate

Open Beginner friendly
#5,257 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 2 days

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
76/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
typescript
Domain
backend

Research direction

Start at packages/opcn1214-generator/src/validate/capital-gains-rules.ts:178 and inspect the existing hundredths comparison in shareholders.dividendRights.total. Update the depreciation test to include 14.46 + 49.59 + 35.95, then search src/validate/ for other raw double amount comparisons. Done means the regression passes and no other amount comparisons there use raw doubles.

Written by the indexing model from the issue text.

Description

1214 annual-audit-workflow

Problem

packages/opcn1214-generator/src/validate/capital-gains-rules.ts:178, in cg.improvements.expense:

if (typeof depreciation === 'number' && depreciation > expense) {

This compares raw doubles, so float residue decides the result. A depreciation summed in JS can land just above the expense: 14.46 + 49.59 + 35.95 is 100.00000000000001.

Repro: a 3077 improvement with expense: 100 and accumulatedDepreciation: 14.46 + 49.59 + 35.95.

  • field.decimals accepts the value. The file would hold 000000010000 for both amounts (10000 hundredths each).
  • validate1214 reports cg.improvements.expense: "Improvement 1 has an accumulated depreciation (100.00000000000001) above its expense (100)." So generate1214 throws Opcn1214ValidationError.
  • The file written for accumulatedDepreciation: 100 is byte-identical, and parse1214 of it reports nothing.

So validating the input and parsing the file disagree, and a fully depreciated improvement can block generation.

Fix

Compare in hundredths, as written to the file. shareholders.dividendRights.total already does this:

// Compared in hundredths, as written to the file: 14.46 + 49.59 + 35.95 is above 100.
if (
  typeof depreciation === 'number' &&
  Math.round(depreciation * 100) > Math.round(expense * 100)
) {

Done when

  • The comparison works in hundredths.
  • The test "accepts a depreciation equal to the expense…" includes the 14.46 + 49.59 + 35.95 vector.
  • No other amount comparison in src/validate/ compares raw doubles. The same kind of bug came up in several places during the stack review.

Raised in the review of #5081 (FIX-3), which added this rule. The review wasn't posted because the PR merged first. Re-checked on main at 31245bc7f.

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

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from Urigo/accounter-fullstack

All issues in Urigo/accounter-fullstack

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.