siddhantgoel / beancount-dkb

Beancount Importers for DKB (Deutsche Kredit Bank) CSV Exports
MIT License
36 stars 13 forks source link

decimal.InvalidOperation: [<class 'decimal.ConversionSyntax'>] - beancount_dkb/credit.py", line 204, in _update_meta #190

Open mh182 opened 1 day ago

mh182 commented 1 day ago

Foremost, thanks for your work on this importer. I use it since a couple of years and it never failed me.

I recently switched my computer and had to reinstall beancount with the DKB-Importer. With the new install, I switched to beancount 3. I changed the configuration to use pyproject.toml. The use of beancount-dkb-ec work on my first try, but extracting my credit card information fails with an error.

I created a minimal example by deleting all transactions, except one (see below).

✦ ➜ beancount-dkb-credit --version
beancount-dkb-credit, version 0.1.1
# Identification works
✦ ➜ beancount-dkb-credit identify test-cc.csv
* /home/max/Documents/accounting/haushalt/test-cc.csv ... OK
  <bound method CreditImporter.name of <beancount_dkb.credit.CreditImporter object at 0x7fd12edd3c20>>
✦ ➜ beancount-dkb-credit extract test-cc.csv
* /home/max/Documents/accounting/haushalt/test-cc.csv ...  ERROR
  Exception in importer code.
  Traceback (most recent call last):
    File "/home/max/.local/share/uv/tools/beancount-dkb/lib/python3.12/site-packages/beangulp/__init__.py", line 86, in _extract
      entries = extract.extract_from_file(importer, filename, existing_entries)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/home/max/.local/share/uv/tools/beancount-dkb/lib/python3.12/site-packages/beangulp/extract.py", line 40, in extract_from_file
      entries = importer.extract(filename, existing_entries)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/home/max/.local/share/uv/tools/beancount-dkb/lib/python3.12/site-packages/beancount_dkb/credit.py", line 102, in extract
      return self._extract(filepath, extractor)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/home/max/.local/share/uv/tools/beancount-dkb/lib/python3.12/site-packages/beancount_dkb/credit.py", line 131, in _extract
      self._update_meta(metadata)
    File "/home/max/.local/share/uv/tools/beancount-dkb/lib/python3.12/site-packages/beancount_dkb/credit.py", line 204, in _update_meta
      Decimal(amount.rstrip(" EUR")), self.currency
      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  decimal.InvalidOperation: [<class 'decimal.ConversionSyntax'>]

✦ ➜ cat test-cc.csv
"Karte","Visa Kreditkarte","4930 •••• •••• 0284"
""
"Saldo vom 12.10.2024:","-428,84 EUR"
""
"Belegdatum","Wertstellung","Status","Beschreibung","Umsatztyp","Betrag (€)","Fremdwährungsbetrag"
"09.10.24","11.10.24","Gebucht","RESTAURANT Foo","Im Geschäft","-21",""

System Information:

siddhantgoel commented 1 day ago

It sounds like DKB has changed their CSV format again. They have been particularly finicky in the past few months, constantly changing their CSV exports in all sorts of subtle ways.

In any case, the culprit in this case is the balance entry.

"Saldo vom 12.10.2024:","-428,84 EUR"

If you replace -428,84 with -428.84 (which is how it has been so far) the importer should work correctly.

I'll check if there's a better way to detect the number separator in Python. If you have ideas on that, please feel free to make suggestions.