From 62427db3e94277c13f12fddd831a5c90f8052d9d Mon Sep 17 00:00:00 2001 From: Raphael Gaschignard Date: Mon, 6 Jun 2016 16:31:46 +0900 Subject: [PATCH 1/3] fix a type error --- money/money.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/money/money.py b/money/money.py index 542574f..87d7225 100644 --- a/money/money.py +++ b/money/money.py @@ -91,10 +91,10 @@ def _from_string(cls, value): s = str(value).strip() try: amount = Decimal(s) - currency = DEFAULT_CURRENCY + currency = DEFAULT_CURRENCY.code except: try: - currency = CURRENCY[s[:3].upper()] + currency = CURRENCY[s[:3].upper()].code # assert that the substring is a correct currency amount = Decimal(s[3:].strip()) except: raise IncorrectMoneyInputError("The value '%s' is not properly formatted as 'XXX 123.45' " % s) From 6af145328f1a782a9c9dde9b3443a3fb8778dfcb Mon Sep 17 00:00:00 2001 From: Raphael Gaschignard Date: Mon, 6 Jun 2016 17:14:08 +0900 Subject: [PATCH 2/3] make sure to consistently set the _currency subfield as a string-like --- money/contrib/django/models/fields.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/money/contrib/django/models/fields.py b/money/contrib/django/models/fields.py index 9ed3933..2fb06f9 100644 --- a/money/contrib/django/models/fields.py +++ b/money/contrib/django/models/fields.py @@ -67,7 +67,7 @@ def __set__(self, obj, value): if value is None: # Money(0) is False self._set_values(obj, None, '') elif isinstance(value, Money): - self._set_values(obj, value.amount, value.currency) + self._set_values(obj, value.amount, value.currency.code) elif isinstance(value, Decimal): _, currency = self._get_values(obj) # use what is currently set self._set_values(obj, value, currency) From efbecc2c505e5928f36e2ee113de8120cf404c0a Mon Sep 17 00:00:00 2001 From: Raphael Gaschignard Date: Mon, 6 Jun 2016 17:30:11 +0900 Subject: [PATCH 3/3] revert previous type change --- money/money.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/money/money.py b/money/money.py index 87d7225..542574f 100644 --- a/money/money.py +++ b/money/money.py @@ -91,10 +91,10 @@ def _from_string(cls, value): s = str(value).strip() try: amount = Decimal(s) - currency = DEFAULT_CURRENCY.code + currency = DEFAULT_CURRENCY except: try: - currency = CURRENCY[s[:3].upper()].code # assert that the substring is a correct currency + currency = CURRENCY[s[:3].upper()] amount = Decimal(s[3:].strip()) except: raise IncorrectMoneyInputError("The value '%s' is not properly formatted as 'XXX 123.45' " % s)