add operation real date as metadata

This commit is contained in:
Antoine Martin 2022-11-01 23:25:59 +01:00
parent 46b2e632b6
commit 0d3db7811b

View file

@ -16,6 +16,7 @@ COL_LABEL = "Libelle simplifie"
COL_DEBIT = "Debit" COL_DEBIT = "Debit"
COL_CREDIT = "Credit" COL_CREDIT = "Credit"
COL_DETAIL = "Informations complementaires" COL_DETAIL = "Informations complementaires"
COL_DATE_OP = "Date operation"
END_DATE_REGEX = "Date de fin de téléchargement : ([0-3][0-9]/[0-1][0-9]/[0-9]{4})" END_DATE_REGEX = "Date de fin de téléchargement : ([0-3][0-9]/[0-1][0-9]/[0-9]{4})"
START_DATE_REGEX = "Date de début de téléchargement : ([0-3][0-9]/[0-1][0-9]/[0-9]{4})" START_DATE_REGEX = "Date de début de téléchargement : ([0-3][0-9]/[0-1][0-9]/[0-9]{4})"
@ -58,9 +59,7 @@ class CDEImporter(importer.ImporterProtocol):
if row is None: if row is None:
return None return None
return datetime.strptime( return datetime.strptime(row[COL_DATE], "%d/%m/%Y").date()
row[COL_DATE], "%d/%m/%Y"
).date()
def extract(self, file: cache._FileMemo, existing_entries=None) -> list[Any]: def extract(self, file: cache._FileMemo, existing_entries=None) -> list[Any]:
directives: list[Any] = [] directives: list[Any] = []
@ -74,9 +73,8 @@ class CDEImporter(importer.ImporterProtocol):
lineno: int = index + 2 # entries start at line 2 lineno: int = index + 2 # entries start at line 2
meta = data.new_metadata(file.name, lineno) meta = data.new_metadata(file.name, lineno)
transaction_date: date = datetime.strptime( transaction_date: date = datetime.strptime(row[COL_DATE], "%d/%m/%Y").date()
row[COL_DATE], "%d/%m/%Y" op_date: date = datetime.strptime(row[COL_DATE_OP], "%d/%m/%Y").date()
).date()
label: str = row[COL_LABEL] label: str = row[COL_LABEL]
debit: str = row[COL_DEBIT] debit: str = row[COL_DEBIT]
credit: str = row[COL_CREDIT] credit: str = row[COL_CREDIT]
@ -88,7 +86,12 @@ class CDEImporter(importer.ImporterProtocol):
amount = Decimal(debit.replace(",", ".")) amount = Decimal(debit.replace(",", "."))
postings.append( postings.append(
data.Posting( data.Posting(
self.account, Amount(amount, "EUR"), None, None, None, None self.account,
Amount(amount, "EUR"),
None,
None,
None,
None,
) )
) )
@ -96,10 +99,17 @@ class CDEImporter(importer.ImporterProtocol):
amount = Decimal(credit.replace(",", ".")) amount = Decimal(credit.replace(",", "."))
postings.append( postings.append(
data.Posting( data.Posting(
self.account, Amount(amount, "EUR"), None, None, None, None self.account,
Amount(amount, "EUR"),
None,
None,
None,
None,
) )
) )
meta["op_date"] = op_date
directives.append( directives.append(
data.Transaction( data.Transaction(
meta, meta,