0001-lingo-accept-french-amount-format-35052.patch
combo/apps/lingo/models.py | ||
---|---|---|
20 | 20 |
import json |
21 | 21 |
import logging |
22 | 22 | |
23 |
from decimal import Decimal |
|
24 | ||
25 | 23 |
from dateutil import parser |
26 | 24 |
import eopayment |
27 | 25 |
from jsonfield import JSONField |
... | ... | |
46 | 44 |
from combo.data.fields import RichTextField |
47 | 45 |
from combo.data.models import CellBase |
48 | 46 |
from combo.data.library import register_cell_class |
49 |
from combo.utils import NothingInCacheException, aes_hex_encrypt, requests |
|
47 |
from combo.utils import NothingInCacheException, aes_hex_encrypt, requests, Decimal
|
|
50 | 48 |
from combo.apps.notifications.models import Notification |
51 | 49 | |
52 | 50 |
try: |
combo/apps/lingo/views.py | ||
---|---|---|
15 | 15 |
# You should have received a copy of the GNU Affero General Public License |
16 | 16 |
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | |
18 |
from decimal import Decimal, ROUND_HALF_UP
|
|
18 |
from decimal import ROUND_HALF_UP |
|
19 | 19 |
import json |
20 | 20 |
import logging |
21 | 21 |
import requests |
... | ... | |
39 | 39 |
import eopayment |
40 | 40 | |
41 | 41 |
from combo.data.models import Page |
42 |
from combo.utils import check_request_signature, aes_hex_decrypt, DecryptionError |
|
42 |
from combo.utils import check_request_signature, aes_hex_decrypt, DecryptionError, Decimal
|
|
43 | 43 |
from combo.profile.utils import get_user_from_name_id |
44 | 44 | |
45 | 45 |
from .models import (Regie, BasketItem, Transaction, TransactionOperation, |
combo/utils/__init__.py | ||
---|---|---|
14 | 14 |
# You should have received a copy of the GNU Affero General Public License |
15 | 15 |
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
16 | 16 | |
17 |
from decimal import Decimal as PythonDecimal |
|
18 | ||
19 |
from django.utils import six |
|
20 | ||
17 | 21 |
# import specific symbols for compatibility |
18 | 22 |
from .cache import cache_during_request |
19 | 23 |
from .crypto import aes_hex_decrypt, aes_hex_encrypt, DecryptionError |
... | ... | |
21 | 25 |
from .requests_wrapper import requests, NothingInCacheException |
22 | 26 |
from .signature import check_query, check_request_signature, sign_url |
23 | 27 |
from .urls import get_templated_url, TemplateError |
28 | ||
29 | ||
30 |
class Decimal(PythonDecimal): |
|
31 | ||
32 |
def __new__(cls, value="0", *args, **kwargs): |
|
33 |
if isinstance(value, six.string_types): |
|
34 |
# replace , by . for French users comfort |
|
35 |
value = value.replace(',', '.') |
|
36 |
return super(Decimal, cls).__new__(cls, value, *args, **kwargs) |
tests/test_lingo_payment.py | ||
---|---|---|
236 | 236 |
assert json.loads(resp.content)['result'] == 'success' |
237 | 237 |
assert BasketItem.objects.filter(amount=Decimal('81.22')).exists() |
238 | 238 | |
239 |
data['amount'] = '11,11' # french notation |
|
240 |
data['extra'] = {} |
|
241 |
url = '%s?email=%s&orig=wcs' % (reverse('api-add-basket-item'), user_email) |
|
242 |
url = sign_url(url, key) |
|
243 |
resp = app.post_json(url, params=data) |
|
244 |
assert resp.status_code == 200 |
|
245 |
assert json.loads(resp.content)['result'] == 'success' |
|
246 |
assert BasketItem.objects.filter(amount=Decimal('11.11')).exists() |
|
247 | ||
239 | 248 |
other_regie.is_default = True |
240 | 249 |
other_regie.save() |
241 | 250 |
data['amount'] = [] |
... | ... | |
406 | 415 |
resp = resp.forms[0].submit() |
407 | 416 |
assert resp.location.startswith('http://dummy-payment.demo.entrouvert.com/') |
408 | 417 |
qs = urlparse.parse_qs(urlparse.urlparse(resp.location).query) |
409 |
assert qs['amount'] == ['223.35']
|
|
418 |
assert qs['amount'] == ['234.46']
|
|
410 | 419 | |
411 | 420 |
resp = login(app).get(page.get_online_url()) |
412 | 421 |
resp = resp.forms[1].submit() |
413 |
- |