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

CSV import rules, define commodity style #2161

Open PSLLSP opened 8 months ago

PSLLSP commented 8 months ago

I would like to have an option to define commodity style in CSV import rules, to support keyword commodity.

Example:

$ cat demo-eur.csv
2023-01-23,test,1 234.56,EUR
$ cat demo-eur.csv.rules
# hledger import rules, test

date  %1
description DEMO|%2

amount %3 %4

account1 expenses:assorted
account2 assets:cash

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

When I create journal with hledger print then hledger uses amount format from CSV file and there is no way to overwrite commodity format in CSV import rules file.

$ hledger -f demo-eur.csv print
2023-01-23 DEMO|test
    ; 2023-01-23,test,1 234.56,EUR
    expenses:assorted     1 234.56 EUR
    assets:cash          -1 234.56 EUR

I can use command line option to define "commodity", that is a current solution:

$ hledger -f demo-eur.csv print -c "1.00 EUR"
2023-01-23 DEMO|test
    ; 2023-01-23,test,1 234.56,EUR
    expenses:assorted     1234.56 EUR
    assets:cash          -1234.56 EUR

or

$ hledger -f demo-eur.csv print -c "1,000.00 EUR"
2023-01-23 DEMO|test
    ; 2023-01-23,test,1 234.56,EUR
    expenses:assorted     1,234.56 EUR
    assets:cash          -1,234.56 EUR

Is it possible to add support for keyword commodity to CSV import file rules?

When CSV file has several currencies, it starts to be complicated, each currency has to be defined on command line. I do not store details here, just output (csv file and import rules evolved...). I prefer to define default commodity formats in CSV import rules...

$ hledger -f demo-eur.csv print
2023-01-24 DEMO|test2
    ; 2023-01-24,test2,2 345.56,USD,2 456.78,EUR
    expenses:assorted      2 345.56 USD @@ 2 456.78 EUR
    assets:cash          -2 345.56 USD @@ -2 456.78 EUR
    equity:conversion
$ hledger -f demo-eur.csv print -c "1.00 EUR" -c "1.00 USD"
2023-01-24 DEMO|test2
    ; 2023-01-24,test2,2 345.56,USD,2 456.78,EUR
    expenses:assorted      2345.56 USD @@ 2456.78 EUR
    assets:cash          -2345.56 USD @@ -2456.78 EUR
    equity:conversion