delete requirements (see requirements.txt) & working script for beancount 2.3.4
This commit is contained in:
@@ -3,6 +3,7 @@ from beancount.core import data
|
||||
from beancount.core.number import D
|
||||
|
||||
import csv
|
||||
import datetime
|
||||
|
||||
class MyCSVImporter(importer.ImporterProtocol):
|
||||
"""A Beancount importer for CSV files"""
|
||||
@@ -27,14 +28,12 @@ class MyCSVImporter(importer.ImporterProtocol):
|
||||
"""Extracts entries from a files."""
|
||||
entries = []
|
||||
|
||||
with open(file.contents, encoding='utf-8')
|
||||
as f:
|
||||
reader = csv.reader(f, delimiter=';')
|
||||
for skip in range(0,8):
|
||||
next(reader, None)
|
||||
|
||||
for index, row in enumerate(reader):
|
||||
if not row or not row[0]:
|
||||
# file.contents
|
||||
with open(file.name, encoding='utf-8') as f:
|
||||
csv_reader = csv.reader(f, delimiter=';')
|
||||
# Gebruik enumerate() om een teller (index) te krijgen
|
||||
for index, row in enumerate(csv_reader):
|
||||
if len(row) < 18 or row[17] != "EUR":
|
||||
continue
|
||||
|
||||
# De index begint bij 0, dus de 12e kolom is index 11.
|
||||
@@ -50,11 +49,15 @@ class MyCSVImporter(importer.ImporterProtocol):
|
||||
valuta = row[17]
|
||||
|
||||
dag, maand, jaar = datum_str.split('.')
|
||||
transactie_datum = data.D(int(jaar)), int(maand), int(dag))
|
||||
|
||||
transactie_datum = datetime.date(int(jaar), int(maand), int(dag))
|
||||
|
||||
payee = ontvanger
|
||||
narration = omschrijving_str
|
||||
bedrag = D(bedrag_str).replace(',','.')
|
||||
# Verwijder eerst de duizendtallen-scheidingstekens (de punten)
|
||||
bedrag_str = bedrag_str.replace('.', '')
|
||||
# Vervang daarna de komma door een punt
|
||||
bedrag_str = bedrag_str.replace(',', '.')
|
||||
bedrag = D(bedrag_str)
|
||||
currency = valuta
|
||||
|
||||
meta = data.new_metadata(file.name, index)
|
||||
@@ -64,17 +67,25 @@ class MyCSVImporter(importer.ImporterProtocol):
|
||||
# Uitgave: bedrag is negatief.
|
||||
# Geld gaat van de bankrekening naar een uitgavenrekening.
|
||||
tegenrekening = self._map_payee_to_account(payee + " " + omschrijving_str)
|
||||
|
||||
#FORMAT: data.Posting(account, units, cost=None, price=None, flag=None, meta=None)
|
||||
postings = [
|
||||
data.Posting(self.file_account(file), bedrag, data.get_currency_meta(currency), None, None, None),
|
||||
data.Posting(tegenrekening, -bedrag, data.get_currency_meta(currency), None, None, None),
|
||||
#data.Posting(self.file_account(file), bedrag, currency, None, None, None),
|
||||
data.Posting(self.file_account(file), data.Amount(bedrag, currency), None, None, None, None),
|
||||
#data.Posting(tegenrekening, -bedrag, currency, None, None, None),
|
||||
data.Posting(tegenrekening, data.Amount(bedrag, currency), None, None, None, None),
|
||||
]
|
||||
else:
|
||||
# Inkomsten: bedrag is positief.
|
||||
# Geld gaat van een inkomstenrekening naar de bankrekening.
|
||||
tegenrekening = self._map_payee_to_account(payee + " " + omschrijving_str)
|
||||
|
||||
#FORMAT: data.Posting(account, units, cost=None, price=None, flag=None, meta=None)
|
||||
postings = [
|
||||
data.Posting(tegenrekening, -bedrag, data.get_currency_meta(currency), None, None, None),
|
||||
data.Posting(self.file_account(file), bedrag, data.get_currency_meta(currency), None, None, None),
|
||||
#data.Posting(tegenrekening, -bedrag, currency, None, None, None),
|
||||
data.Posting(tegenrekening, data.Amount(-bedrag, currency), None, None, None, None),
|
||||
#data.Posting(self.file_account(file), bedrag, currency, None, None, None),
|
||||
data.Posting(self.file_account(file), data.Amount(bedrag, currency), None, None, None, None),
|
||||
]
|
||||
|
||||
transaction = data.Transaction(
|
||||
@@ -83,8 +94,8 @@ class MyCSVImporter(importer.ImporterProtocol):
|
||||
flag='*',
|
||||
payee=payee,
|
||||
narration=narration,
|
||||
tags=data.frozenset(),
|
||||
links=data.frozenset(),
|
||||
tags=frozenset(),
|
||||
links=frozenset(),
|
||||
postings=postings
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user