change currencies integer constants to ISO code strings

This commit is contained in:
Romain Bignon 2014-02-16 19:48:17 +01:00
commit 6099560b8c
11 changed files with 24 additions and 39 deletions

View file

@ -49,8 +49,8 @@ class Recipient(CapBaseObject, Currency):
Recipient of a transfer.
"""
label = StringField('Name')
currency = IntField('Currency', default=Currency.CUR_UNKNOWN)
label = StringField('Name')
currency = StringField('Currency', default=None)
def __init__(self):
CapBaseObject.__init__(self, 0)

View file

@ -428,17 +428,11 @@ class CapBaseObject(object):
class Currency(object):
CUR_UNKNOWN = 0
CUR_EUR = 1
CUR_CHF = 2
CUR_USD = 3
TXT2CUR = OrderedDict(((u'', CUR_EUR),
(u'EUR', CUR_EUR),
(u'CHF', CUR_CHF),
(u'$', CUR_USD),
(u'USD', CUR_USD),
))
CURRENCIES = {u'EUR': u'',
u'CHF': u'CHF',
u'USD': u'$',
u'GBP': u'£',
}
EXTRACTOR = re.compile(r'[\d\s,\.\-]', re.UNICODE)
@ -462,14 +456,11 @@ class Currency(object):
"""
curtexts = klass.EXTRACTOR.sub(' ', text.upper()).split()
for curtext in curtexts:
cur = klass.TXT2CUR.get(curtext)
if cur is not None:
return cur
return klass.CUR_UNKNOWN
for currency, symbol in klass.CURRENCIES.iteritems():
if curtext in (currency, symbol):
return currency
return None
@classmethod
def currency2txt(klass, currency):
for txt, value in klass.TXT2CUR.iteritems():
if value == currency:
return txt
return u''
return klass.CURRENCIES.get(currency, u'')

View file

@ -18,7 +18,7 @@
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
from .base import CapBaseObject, StringField, DateField, DecimalField, IntField, UserError, Currency
from .base import CapBaseObject, StringField, DateField, DecimalField, UserError
from .collection import ICapCollection
@ -50,7 +50,7 @@ class Detail(CapBaseObject):
datetime = DateField('date information')
price = DecimalField('Total price, taxes included')
vat = DecimalField('Value added Tax')
currency = IntField('Currency', default=Currency.CUR_UNKNOWN)
currency = StringField('Currency', default=None)
quantity = DecimalField('Number of units consumed')
unit = StringField('Unit of the consumption')
@ -67,7 +67,7 @@ class Bill(CapBaseObject):
label = StringField('label of bill')
idparent = StringField('id of the parent subscription')
price = DecimalField('Price to pay')
currency = IntField('Currency', default=Currency.CUR_UNKNOWN)
currency = StringField('Currency', default=None)
deadline = DateField('The latest day to pay')
startdate = DateField('The first day the bill applies to')
finishdate = DateField('The last day the bill applies to')

View file

@ -21,7 +21,7 @@
import datetime
from .base import IBaseCap, CapBaseObject, StringField, TimeField, DeltaField, \
DateField, DecimalField, IntField, Currency, UserError
DateField, DecimalField, UserError
__all__ = ['Station', 'Departure', 'RoadStep', 'RoadmapError', 'RoadmapFilters', 'ICapTravel']
@ -54,7 +54,7 @@ class Departure(CapBaseObject):
information = StringField('Informations')
plateform = StringField('Where the train will leave')
price = DecimalField('Price of ticket')
currency = IntField('Currency', default=Currency.CUR_UNKNOWN)
currency = StringField('Currency', default=None)
def __init__(self, id, _type, _time):
CapBaseObject.__init__(self, id)