Transaction amounts cleaner helper for american banks.
Signed-off-by: Oleg Plakhotniuk <olegus8@gmail.com>
This commit is contained in:
parent
449ea03f68
commit
649d777ac5
2 changed files with 25 additions and 0 deletions
|
|
@ -4,6 +4,7 @@ detailed-errors = 1
|
||||||
with-doctest = 1
|
with-doctest = 1
|
||||||
where = weboob
|
where = weboob
|
||||||
tests = weboob.capabilities.bank,
|
tests = weboob.capabilities.bank,
|
||||||
|
weboob.tools.capabilities.bank.transactions,
|
||||||
weboob.tools.capabilities.paste,
|
weboob.tools.capabilities.paste,
|
||||||
weboob.tools.application.formatters.json,
|
weboob.tools.application.formatters.json,
|
||||||
weboob.tools.application.formatters.table,
|
weboob.tools.application.formatters.table,
|
||||||
|
|
|
||||||
|
|
@ -315,3 +315,27 @@ class FrenchTransaction(Transaction):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
return Decimal('0')
|
return Decimal('0')
|
||||||
|
|
||||||
|
|
||||||
|
class AmericanTransaction(Transaction):
|
||||||
|
"""
|
||||||
|
Transaction with some helpers for american bank websites.
|
||||||
|
"""
|
||||||
|
@classmethod
|
||||||
|
def clean_amount(klass, text):
|
||||||
|
"""
|
||||||
|
Clean a string containing an amount.
|
||||||
|
"""
|
||||||
|
# Convert "American" UUU.CC format to "French" UUU,CC format
|
||||||
|
if re.search(r'\d\.\d\d(?: [A-Z]+)?$', text):
|
||||||
|
text = text.replace(',', ' ').replace('.', ',')
|
||||||
|
return FrenchTransaction.clean_amount(text)
|
||||||
|
|
||||||
|
def test():
|
||||||
|
clean_amount = AmericanTransaction.clean_amount
|
||||||
|
assert clean_amount('42') == '42'
|
||||||
|
assert clean_amount('42,12') == '42.12'
|
||||||
|
assert clean_amount('42.12') == '42.12'
|
||||||
|
assert clean_amount('$42.12 USD') == '42.12'
|
||||||
|
assert clean_amount('$12.442,12 USD') == '12442.12'
|
||||||
|
assert clean_amount('$12,442.12 USD') == '12442.12'
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue