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.91k stars 315 forks source link

Unable to convert CSV with zeroes in both in and out fields #1733

Closed sclel016 closed 2 years ago

sclel016 commented 2 years ago

Hi,

I'm a total beginner to hledger with a minimal accounting background. The first thing I tried to do was import a csv dump of my chequing transactions. I followed the tutorial but ran into a slight snag. My bank doesn't charge fees and likes to remind me in my transactions. I have transactions chequing.csv such as:

Date;Description;Category;Debit;Credit;Balance
"2020-01-21";"Client card point of sale fee";Fees;"0";"0";"1068.94"

My chequing.csv.rules are pretty simple for now:

skip 1
fields date, description, category, amount-out, amount-in, balance
separator ;
currency $
account1 assets:bank:checking

When I print the transactions, I get an error related to these $0 transactions.

❯ hledger -f chequing.csv print
hledger: multiple non-zero amounts or multiple zero amounts assigned,
please ensure just one. (https://hledger.org/csv.html#amount)
  record values: "2020-01-21","Transaction fees","Fees","0","0","1068.94"
  for posting: 1
  assignment: amount-in %5  => value: 0
  assignment: amount-out %4 => value: 0

My expectation would be for $0 transaction to either be ignored or parsed like any other transaction. I don't know whether this is an issue in hledger or my understanding of accounting principals. Here's my install info

Thanks for the great software!

simonmichael commented 2 years ago

Welcome, and thanks for the report! I too would expect it to ignore the two zeroes there. https://github.com/simonmichael/hledger/blob/4b1919de0/hledger-lib/Hledger/Read/CsvReader.hs#L1006:L1027 needs more study.

sclel016 commented 2 years ago

I'd love to help by submitting a PR but my Haskell knowledge is non-existent. The code in the link looks totally foreign to my object oriented eyes!

simonmichael commented 2 years ago

Another example: https://www.reddit.com/r/plaintextaccounting/comments/qkvl4z/hledger_csv_rule_for_handling_empty_amounts. It's usually possible to work around but we should handle two zeroes out of the box.

simonmichael commented 2 years ago

Fixed by @Xitian9. Thanks!