Commit 649d777a authored by Oleg Plakhotniuk's avatar Oleg Plakhotniuk Committed by Romain Bignon

Transaction amounts cleaner helper for american banks.

Signed-off-by: default avatarOleg Plakhotniuk <olegus8@gmail.com>
parent 449ea03f
......@@ -4,6 +4,7 @@ detailed-errors = 1
with-doctest = 1
where = weboob
tests = weboob.capabilities.bank,
weboob.tools.capabilities.bank.transactions,
weboob.tools.capabilities.paste,
weboob.tools.application.formatters.json,
weboob.tools.application.formatters.table,
......
......@@ -315,3 +315,27 @@ class FrenchTransaction(Transaction):
pass
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'
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment