CSV extract, sessie 2
This commit is contained in:
@@ -24,25 +24,40 @@ class MyCSVImporter(importer.ImporterProtocol):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
def extract(self, file, existing_entries=None):
|
def extract(self, file, existing_entries=None):
|
||||||
|
"""Extracts entries from a files."""
|
||||||
entries = []
|
entries = []
|
||||||
|
|
||||||
print(f"Start extracting from: {file.name}")
|
with open(file.contents, encoding='utf-8')
|
||||||
print(f"Content will be processed from: {file.contents}")
|
as f:
|
||||||
|
reader = csv.reader(f, delimiter=',')
|
||||||
|
next(reader, None)
|
||||||
|
|
||||||
|
for index, row in enumerate(reader):
|
||||||
|
if not row or not row[0]:
|
||||||
|
continue
|
||||||
|
|
||||||
meta = data.new_metadata(file.name, 0)
|
datum_str = row[0]
|
||||||
transaction = data.Transaction(
|
omschrijving = row[1]
|
||||||
meta=meta,
|
bedrag_str = row[2]
|
||||||
date=data.D(2025, 7, 29),
|
|
||||||
flag='*',
|
|
||||||
payee="Dummy Payee",
|
|
||||||
narration="Dummy narration - REPLACE this",
|
|
||||||
tags=data.frozenset(['test']),
|
|
||||||
links=data.frozenset(),
|
|
||||||
postings=[
|
|
||||||
data.Postings("Assets:Bank:POSTBANK", D("-100.00"), data.get_currency_meta('EUR'), None, None, None),
|
|
||||||
data.Postings("Expenses:Food", D("100.00"), data.get_currency_meta('EUR'), None, None, None),
|
|
||||||
]
|
|
||||||
)
|
|
||||||
entries.append(transaction)
|
|
||||||
|
|
||||||
|
dag, maand, jaar = datum_str.split('.')
|
||||||
|
transactie_datum = data.D(int(jaar)), int(maand), int(dag))
|
||||||
|
bedrag = D(bedrag_str)
|
||||||
|
|
||||||
|
meta = data.new_metadata(file.name, index)
|
||||||
|
|
||||||
|
transaction = data.Transaction(
|
||||||
|
meta=meta,
|
||||||
|
date=transactie_datum,
|
||||||
|
flag='*',
|
||||||
|
payee=omschrijving,
|
||||||
|
narration="",
|
||||||
|
tags=data.frozenset(),
|
||||||
|
links=data.frozenset(),
|
||||||
|
postings=[
|
||||||
|
data.Posting(self.file_account(file)), - bedrag, data.get_currency_meta('EUR'), None, None, None),
|
||||||
|
data.Posting("Expenses:Uncategorized", bedrag, data.get_currency_meta('EUR'), None, None, None),
|
||||||
|
]
|
||||||
|
)
|
||||||
|
entries.append(transaction)
|
||||||
return entries
|
return entries
|
||||||
Reference in New Issue
Block a user