Skip to content

Commit

Permalink
feat: enable price conversions in banking transaction builder. See re…
Browse files Browse the repository at this point in the history
  • Loading branch information
redstreet authored and scanta2 committed Oct 13, 2023
1 parent b06bca3 commit ab3d849
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion beancount_reds_importers/libtransactionbuilder/banking.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from beancount.core import data
from beancount.core import amount
from beancount.ingest import importer
from beancount_reds_importers.libtransactionbuilder import common


class Importer(importer.ImporterProtocol):
Expand Down Expand Up @@ -57,6 +58,10 @@ def custom_init(self):
# # Not needed for accounts using smart_importer
# return self.target_account_map.get(transaction.type, None)

@staticmethod
def fields_contain_data(ot, fields):
return all(hasattr(ot, f) and getattr(ot, f) for f in fields)

# --------------------------------------------------------------------------------

def extract_balance(self, file, counter):
Expand Down Expand Up @@ -110,10 +115,18 @@ def extract(self, file, existing_entries=None):
# narration, so keeping the order unchanged in the call below is important.

# Build transaction entry
# Banking transactions might include foreign currency transactions. TODO: figure out
# how ofx handles this and use the same interface for csv and other files
entry = data.Transaction(metadata, ot.date.date(), self.FLAG,
self.get_narration(ot), self.get_payee(ot),
data.EMPTY_SET, data.EMPTY_SET, [])
data.create_simple_posting(entry, config['main_account'], ot.amount, self.get_currency(ot))

if self.fields_contain_data(ot, ['foreign_amount', 'foreign_currency']):
common.create_simple_posting_with_price(entry, config['main_account'],
ot.foreign_amount, ot.foreign_currency,
ot.amount, self.get_currency(ot))
else:
data.create_simple_posting(entry, config['main_account'], ot.amount, self.get_currency(ot))

# TODO: Commented out so smart_importer can fill this in
# target_acct = self.get_target_acct(ot)
Expand Down

0 comments on commit ab3d849

Please sign in to comment.