siddhantgoel / beancount-dkb

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

Importer picks Belegdatum instead of Wertstellung, which may result in failing balance assertions #93

Closed nils-werner closed 2 years ago

nils-werner commented 3 years ago

Sometimes, if the Saldo Datum of a CSV export is between the Wertstellung and the Belegdatum (for credit cards) or Wertstellung and Buchungstag (for checking accounts) of one or more transactions you will have a failing balance statement.

Note that in the following example the Datum is on 02.07.2021 and the two transaction Wertstellung are on 05.07.2021 and 01.07.2021:

"Kreditkarte:";"xxxxxxxxxxxxxxxxx";

"Zeitraum:";"seit der letzten Abrechnung";
"Saldo:";"-18.63 EUR";
"Datum:";"02.07.2021";

"Umsatz abgerechnet und nicht im Saldo enthalten";"Wertstellung";"Belegdatum";"Beschreibung";"Betrag (EUR)";"Urspr�nglicher Betrag";
"Nein";"05.07.2021";"01.07.2021";"KAUFLAND";"-9,56";"";
"Nein";"01.07.2021";"01.07.2021";"ALDI";"-18,63";"";

this becomes the following ledger

2021-07-01 * "ALDI"
  Assets:DE:DKB:Creditcard                   -18.63 EUR
  Expenses:Food:Groceries

2021-07-01 * "KAUFLAND"
  Assets:DE:DKB:Creditcard                    -9.56 EUR
  Expenses:Food:Groceries

2021-07-02 balance Assets:DE:DKB:Creditcard     -18.63 EUR

Which will fail balance checks.

I believe the correct export should be to pick the Werstellung field for a transaction date instead, which results in

2021-07-01 * "ALDI"
  Assets:DE:DKB:Creditcard                   -18.63 EUR
  Expenses:Food:Groceries

2021-07-02 balance Assets:DE:DKB:Creditcard     -18.63 EUR

2021-07-05 * "KAUFLAND"
  Assets:DE:DKB:Creditcard                    -9.56 EUR
  Expenses:Food:Groceries

which is correct.

siddhantgoel commented 2 years ago

Interesting catch. Also, thanks for the associated PR!

Looks like this behavior can also be confirmed from the following statement on the DKB website:

Es lohnt, einen Blick auf beide Daten zu werfen. Das Buchungsdatum sagt aus, wann der Umsatz im System der Bank eingegangen ist und bearbeitet wurde. Das Belegdatum gibt an, wann du den Umsatz getätigt hast.