Skip to content

Commit

Permalink
fix: uobbank importer: add unit tests, fix several issues #70
Browse files Browse the repository at this point in the history
- decimal places
  - still needs a full solution. The problem is, petel uses xlwt/xlrd to
    read excel, which use excel datatypes, which we don't want, as we
    want just the string, which we can then pass on to decimal.decimal
  - not sure exactly how decimals are stored in excel

- don't end up with long floats
  • Loading branch information
redstreet committed Jul 5, 2023
1 parent f38a905 commit b715d97
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 3 deletions.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
2023-05-02 * "NETS Debit-Consumer xxxxxxYYYY"
Assets:Banks:UOB:UNIPLUS -27.9 SGD

2023-05-08 * "Cash Withdrawal-ATM NFC Mobile WDL"
Assets:Banks:UOB:UNIPLUS -60.0 SGD

2023-05-31 * "Interest Credit"
Assets:Banks:UOB:UNIPLUS 0.13 SGD

2023-06-05 * "Cheque Deposit"
Assets:Banks:UOB:UNIPLUS 545.05 SGD

2023-06-05 * "Cash Withdrawal-ATM NFC Mobile WDL"
Assets:Banks:UOB:UNIPLUS -80.0 SGD

2023-06-14 * "Cash Withdrawal-ATM NFC Mobile WDL"
Assets:Banks:UOB:UNIPLUS -300.0 SGD

2023-06-16 * "Cash Withdrawal-ATM NFC Mobile WDL"
Assets:Banks:UOB:UNIPLUS -800.0 SGD

2023-06-30 * "Interest Credit"
Assets:Banks:UOB:UNIPLUS 0.12 SGD

2023-07-01 balance Assets:Banks:UOB:UNIPLUS 0.0 SGD
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Assets:Banks:UOB:UNIPLUS
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2023-06-30
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ACC_TXN_History_1234_clean.xls
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from os import path
from beancount.ingest import regression_pytest as regtest
from beancount_reds_importers.importers.unitedoverseas import uobbank


@regtest.with_importer(
uobbank.Importer({
'main_account': 'Assets:Banks:UOB:UNIPLUS',
'account_number': '1234567890',
'currency': 'SGD',
'rounding_error': 'Equity:Rounding-Errors:Imports',
})
)
@regtest.with_testdir(path.dirname(__file__))
class TestUOB(regtest.ImporterTestBase):
pass
4 changes: 3 additions & 1 deletion beancount_reds_importers/importers/unitedoverseas/uobbank.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@ def prepare_table(self, rdr):
# Remove carriage returns in description
rdr = rdr.convert('Transaction Description', lambda x: x.replace('\n', ' '))

def Ds(x):
return D(str(x))
rdr = rdr.addfield('amount',
lambda x: -1 * D(x['Withdrawal']) if x['Withdrawal'] != 0 else D(x['Deposit']))
lambda x: -1 * Ds(x['Withdrawal']) if x['Withdrawal'] != 0 else Ds(x['Deposit']))
rdr = rdr.addfield('memo', lambda x: '')
return rdr

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def prepare_table(self, rdr):
return rdr

def prepare_processed_table(self, rdr):
return rdr.convert('amount', lambda x: -1 * D(x))
return rdr.convert('amount', lambda x: -1 * D(str(x)))

def prepare_raw_file(self, rdr):
# Strip tabs and spaces around each field in the entire file
Expand Down
4 changes: 3 additions & 1 deletion beancount_reds_importers/importers/unitedoverseas/uobsrs.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@ def prepare_table(self, rdr):
# Remove carriage returns in description
rdr = rdr.convert('Transaction Description', lambda x: x.replace('\n', ' '))

def Ds(x):
return D(str(x))
rdr = rdr.addfield('amount',
lambda x: -1 * D(x['Withdrawal']) if x['Withdrawal'] != '' else D(x['Deposit']))
lambda x: -1 * Ds(x['Withdrawal']) if x['Withdrawal'] != '' else Ds(x['Deposit']))
rdr = rdr.addfield('memo', lambda x: '')
return rdr

Expand Down

0 comments on commit b715d97

Please sign in to comment.