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):
|
||||
if isinstance(amount, list):
|
||||
d = sum([Decimal(a) for a in amount])
|
||||
d = Decimal(sum([Decimal(a) for a in amount]))
|
||||
else:
|
||||
d = Decimal(amount)
|
||||
return d.quantize(Decimal('0.01'), ROUND_HALF_UP)
|
||||
|
@ -69,7 +69,7 @@ class AddBasketItemApiView(View):
|
|||
extra = request_body.get('extra', {})
|
||||
|
||||
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'):
|
||||
item.amount += self.get_amount(request_body['amount'])
|
||||
|
|
|
@ -103,10 +103,11 @@ def test_add_amount_to_basket(regie, user):
|
|||
|
||||
data['amount'] = [amount]
|
||||
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 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):
|
||||
|
|
Reference in New Issue