Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

amount %amt @@ -%amt is not allowed when %amt is negative; CSV import #2162

Open
PSLLSP opened this issue Jan 30, 2024 · 0 comments
Open

amount %amt @@ -%amt is not allowed when %amt is negative; CSV import #2162

PSLLSP opened this issue Jan 30, 2024 · 0 comments

Comments

@PSLLSP
Copy link

PSLLSP commented Jan 30, 2024

$ hledger --version
hledger 1.32.3, linux-x86_64

@@ cannot parse negative amounts (@@ -%amt results in @@ --123.45 and that is a problem for a parser)

Error:

$ hledger -f demo-eur.csv print
hledger: Error: error: could not parse "--2 345.56 USD @@ --2 456.78 EUR" as an amount
CSV record: "2023-01-25","test3","-2 345.56","USD","-2 456.78","EUR"
the account3 rule is: equity:conversion
the account2 rule is: assets:cash
the amount2 rule is: -%3 %4 @@ -%5 %6
the account1 rule is: expenses:assorted
the amount1 rule is: %3 %4 @@ %5 %6
the amount rule is: %5 %6
the comment rule is: \n%1,%2,%3,%4,%5,%6
the date rule is: %1
the description rule is: DEMO|%2

the parse error is:      1:14:
  |
1 | 2 345.56 USD @@ --2 456.78 EUR
  |              ^
unexpected '@'
expecting end of input, ledger-style lot cost, ledger-style lot date, ledger-style lot note, or valuation expression

you may need to change your amount*, balance*, or currency* rules, or add or change your skip rule

CSV file to replicate the bug. The first 2 lines are imported without issue but third line is troublemaker because it has negative numbers:

$ cat demo-eur.csv
2023-01-23,test1,1 234.56,EUR,1 234.56,EUR
2023-01-24,test2,2 345.56,USD,2 456.78,EUR
2023-01-25,test3,-2 345.56,USD,-2 456.78,EUR
2023-01-26,test4,+2 345.56,USD,+2 456.78,EUR

CSV rules import file:

$ cat demo-eur.csv.rules 
# hledger import rules, test

date  %1
description DEMO|%2

amount %5 %6
#amount %6 %5    # to test other issue (-123 -> EUR --123)

amount1 %3 %4 @@ %5 %6
amount2 -%3 %4 @@ -%5 %6
#amount2 %4 -%3 @@ %6 -%5  # similar issue (-123 EUR -> EUR --123)

account1 expenses:assorted
account2 assets:cash
account3 equity:conversion

# debug
comment \n%1,%2,%3,%4,%5,%6

Even positive numbers could be troublemakers:

$ grep "test4" demo-eur.csv
2023-01-26,test4,+2 345.56,USD,+2 456.78,EUR
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant