round amount computed from query string (#9174)
This commit is contained in:
parent
2a31f515cd
commit
227e37a8f7
|
@ -57,7 +57,7 @@ class AddBasketItemApiView(View):
|
||||||
|
|
||||||
def get_amount(self, amount):
|
def get_amount(self, amount):
|
||||||
if isinstance(amount, list):
|
if isinstance(amount, list):
|
||||||
d = sum([Decimal(a) for a in amount])
|
d = Decimal(sum([Decimal(a) for a in amount]))
|
||||||
else:
|
else:
|
||||||
d = Decimal(amount)
|
d = Decimal(amount)
|
||||||
return d.quantize(Decimal('0.01'), ROUND_HALF_UP)
|
return d.quantize(Decimal('0.01'), ROUND_HALF_UP)
|
||||||
|
@ -69,7 +69,7 @@ class AddBasketItemApiView(View):
|
||||||
extra = request_body.get('extra', {})
|
extra = request_body.get('extra', {})
|
||||||
|
|
||||||
item = BasketItem(amount=0)
|
item = BasketItem(amount=0)
|
||||||
item.amount = sum([Decimal(x) for x in request.GET.getlist('amount')])
|
item.amount = self.get_amount(request.GET.getlist('amount'))
|
||||||
|
|
||||||
if request_body.get('amount'):
|
if request_body.get('amount'):
|
||||||
item.amount += self.get_amount(request_body['amount'])
|
item.amount += self.get_amount(request_body['amount'])
|
||||||
|
|
|
@ -103,10 +103,11 @@ def test_add_amount_to_basket(regie, user):
|
||||||
|
|
||||||
data['amount'] = [amount]
|
data['amount'] = [amount]
|
||||||
data['extra'] = {'amount': ['22.22', '12']}
|
data['extra'] = {'amount': ['22.22', '12']}
|
||||||
resp = client.post(url, json.dumps(data), content_type='application/json')
|
resp = client.post('%s&amount=5' % url, json.dumps(data),
|
||||||
|
content_type='application/json')
|
||||||
assert resp.status_code == 200
|
assert resp.status_code == 200
|
||||||
assert json.loads(resp.content) == {'result': 'success'}
|
assert json.loads(resp.content) == {'result': 'success'}
|
||||||
assert BasketItem.objects.filter(amount=Decimal('76.22')).exists()
|
assert BasketItem.objects.filter(amount=Decimal('81.22')).exists()
|
||||||
|
|
||||||
|
|
||||||
def test_payment_callback(regie, user):
|
def test_payment_callback(regie, user):
|
||||||
|
|
Reference in New Issue