generated from felixm/defaultpy
Add tags to mapping
This commit is contained in:
@@ -5,7 +5,7 @@ from toldg.models import Config, Transaction
|
||||
from toldg.utils import category_to_bean
|
||||
|
||||
BEANCOUNT_TRANSACTION_TEMPLATE = """
|
||||
{t.date} * {t.description}
|
||||
{t.date} * {description}{tags}
|
||||
{t.account2:<40} {t.debit:<6} {t.currency}
|
||||
{t.account1:<40} {t.credit:<6} {t.currency}
|
||||
"""
|
||||
@@ -13,28 +13,41 @@ BEANCOUNT_TRANSACTION_TEMPLATE = """
|
||||
|
||||
def format(t):
|
||||
t.date = t.date.replace("/", "-")
|
||||
if t.narration and t.payee:
|
||||
# A transaction may have an optional “payee” and/or a “narration.”
|
||||
t.description = f'"{t.payee}" "{t.narration}"'
|
||||
elif t.narration:
|
||||
# If you place a single string on a transaction line, it becomes its narration:
|
||||
t.description = f'"{t.narration}"'
|
||||
elif t.payee:
|
||||
# If you want to set just a payee, put an empty narration string:
|
||||
t.description = f'"{t.payee}" ""'
|
||||
else:
|
||||
t.description = f'"{t.description}"'
|
||||
|
||||
tags = ""
|
||||
description = None
|
||||
if t.mapping:
|
||||
m = t.mapping
|
||||
t.account2 = m.account2
|
||||
|
||||
if m.narration and m.payee:
|
||||
# A transaction may have an optional “payee” and/or a “narration.”
|
||||
description = f'"{m.payee}" "{m.narration}"'
|
||||
elif m.narration:
|
||||
# If you place a single string on a transaction line, it becomes its narration:
|
||||
description = f'"{m.narration}"'
|
||||
elif m.payee:
|
||||
# If you want to set just a payee, put an empty narration string:
|
||||
description = f'"{m.payee}" ""'
|
||||
if m.tags:
|
||||
tags = " #" + " #".join(m.tags)
|
||||
|
||||
if description is None:
|
||||
description = f'"{t.description}"'
|
||||
|
||||
if not t.debit.startswith("-"):
|
||||
t.debit = " " + t.debit
|
||||
if not t.credit.startswith("-"):
|
||||
t.credit = " " + t.credit
|
||||
|
||||
t.account1 = category_to_bean(t.account1)
|
||||
t.account2 = category_to_bean(t.account2)
|
||||
if t.currency == "EUR":
|
||||
t.debit = t.debit.replace(".", "|").replace(",", ".").replace("|", ",")
|
||||
t.credit = t.credit.replace(".", "|").replace(",", ".").replace("|", ",")
|
||||
return BEANCOUNT_TRANSACTION_TEMPLATE.format(t=t)
|
||||
return BEANCOUNT_TRANSACTION_TEMPLATE.format(
|
||||
t=t, description=description, tags=tags
|
||||
)
|
||||
|
||||
|
||||
def render_to_file(transactions: List[Transaction], config: Config):
|
||||
|
||||
Reference in New Issue
Block a user