support currencies

This commit is contained in:
Romain Bignon 2012-12-06 12:18:26 +01:00
commit d91dad2b2b
17 changed files with 95 additions and 30 deletions

View file

@ -18,6 +18,7 @@
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
import re
from datetime import date, datetime
from .base import CapBaseObject, Field, StringField, DateField, DecimalField, IntField, UserError
@ -40,6 +41,25 @@ class TransferError(UserError):
A transfer has failed.
"""
class Currency:
CUR_UNKNOWN = 0
CUR_EUR = 1
CUR_CHF = 2
CUR_USD = 3
TXT2CUR = {u'': CUR_EUR,
u'EUR': CUR_EUR,
u'CHF': CUR_CHF,
u'$': CUR_USD,
u'USD': CUR_USD,
}
@classmethod
def get_currency(klass, text):
text = re.sub(u'[^A-Za-z€]', '', text)
return klass.TXT2CUR.get(text, klass.CUR_UNKNOWN)
class Recipient(CapBaseObject):
"""
Recipient of a transfer.
@ -50,7 +70,7 @@ class Recipient(CapBaseObject):
def __init__(self):
CapBaseObject.__init__(self, 0)
class Account(Recipient):
class Account(Recipient, Currency):
"""
Bank account.
@ -68,6 +88,7 @@ class Account(Recipient):
type = IntField('Type of account', default=TYPE_UNKNOWN)
balance = DecimalField('Balance on this bank account')
coming = DecimalField('Coming balance')
currency = IntField('Currency', default=Currency.CUR_UNKNOWN)
def __repr__(self):
return u"<Account id=%r label=%r>" % (self.id, self.label)

View file

@ -20,6 +20,7 @@
from decimal import Decimal
import datetime
import re
from weboob.capabilities.bank import Transaction
from weboob.capabilities import NotAvailable
@ -40,8 +41,8 @@ class FrenchTransaction(Transaction):
"""
Clean a string containing an amount.
"""
return text.replace(' ', '').replace('.','').replace(u'\xa0', '') \
.replace(',','.').strip(u' \t\u20ac\xa0\x80\n\rEUR')
text = text.replace('.','').replace(',','.')
return re.sub(u'[^\d\-\.]', '', text)
def set_amount(self, credit='', debit=''):
"""