simonmichael / hledger

Robust, fast, intuitive plain text accounting tool with CLI, TUI and web interfaces.
https://hledger.org
GNU General Public License v3.0
2.97k stars 317 forks source link

Inconsistent Decimal Mark Handling after CSV Import with Rules #2195

Closed yse closed 5 months ago

yse commented 5 months ago

Environment:

Steps to Reproduce:

  1. Obtain the sample.csv and sample.csv.rules files from the examples directory on GitHub.
  2. Import transactions from sample.csv using the command:
    hledger import --rules-file=sample.csv.rules --file transaction.ledger sample.csv
  3. Append a transaction with higher precision decimals to sample.csv:
    echo '"2024/4/1","blah","-10000.00"' >> sample.csv
  4. Verify the transaction in transaction.ledger. The decimal mark appears correctly:
    2024-04-01 blah
    assets:bank:checking      $-10000.00
    expenses:unknown           $10000.00
  5. Manually add a transaction with a comma as the thousand separator in transaction.ledger:
    cat <<EOF >> transaction.ledger
    2024-04-14 blahblah blah
    assets:bank:checking    \$2,000.00
    income:unknown          \$-2,000.00
    EOF
  6. Append another transaction to sample.csv:
    echo '"2024/4/15","blah blah","-2000.00"' >> sample.csv
  7. Re-import the updated CSV:
    hledger import --rules-file=sample.csv.rules --file transaction.ledger sample.csv
  8. Review the latest transaction in transaction.ledger and observe the incorrect and unexpected use of a comma as the thousand separator:
    2024-04-15 blah blah
    assets:bank:checking      $-2,000.00
    expenses:unknown           $2,000.00

Expected Behavior:

The decimal mark handling should remain consistent across manual entries and CSV imports, respecting the formatting defined in the rules file or the default behavior of the system.

Actual Behavior:

Transactions imported from the CSV file after manually appending entries with a different decimal format in the ledger file show an unexpected change in the decimal mark format (introduction of a comma as the thousand separator).

simonmichael commented 5 months ago

Thanks for reporting!

Is the behaviour explained and justified by this:

import tries to follow the journal's existing commodity styles when it creates new entries. During the first import, the journal contains no thousand commas, so the style for $ is no commas. During the second import, because of the one thousand comma you added to the journal, the style with thousand commas is inferred for $, and used for the new entry.

Either avoiding adding unwanted thousand commas in the journal, or declaring the desired style explicitly in the journal with

commodity $1000.00

will prevent it.

yse commented 5 months ago

Thanks a lot for clarifying. I've just used only D directive. Commodity also specify style for reporting which is impressive.

Thank you for this remarkably beautiful and useful tool.