Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Pass decimal amount for order items to payment, add extra assertions for validity

Rafał Pitoń90659e4be962
diff --git a/saleor/order/models.py b/saleor/order/models.py
index e115fe7211..e6bbe52efb 100644
--- a/saleor/order/models.py
+++ b/saleor/order/models.py
@@ -296,7 +296,7 @@ class Payment(BasePayment):
PurchasedItem(
name=line.product_name, sku=line.product_sku,
quantity=line.quantity,
- price=line.unit_price_gross.quantize(Decimal('0.01')),
+ price=line.unit_price_gross.quantize(Decimal('0.01')).amount,
currency=settings.DEFAULT_CURRENCY)
for line in self.order.get_lines()]
diff --git a/tests/test_checkout_integration.py b/tests/test_checkout_integration.py
index 7c8dc4a438..e9b0f45413 100644
--- a/tests/test_checkout_integration.py
+++ b/tests/test_checkout_integration.py
@@ -125,6 +125,12 @@ def test_checkout_flow_authenticated_user(
'order:checkout-success', kwargs={'token': order.token})
assert get_redirect_location(payment_response) == order_password
+ # Assert that payment object was created and contains correct data
+ payment = order.payments.all()[0]
+ assert payment.total == order.total.gross.amount
+ assert payment.tax == order.total.tax.amount
+ assert len(payment.get_purchased_items()) == len(order.get_lines())
+
def test_address_without_shipping(request_cart_with_item, client, monkeypatch):
monkeypatch.setattr(
diff --git a/tests/test_payment.py b/tests/test_payment.py
index 0307c87edb..7f3a5c4862 100644
--- a/tests/test_payment.py
+++ b/tests/test_payment.py
@@ -1,10 +1,11 @@
+from decimal import Decimal
+
from prices import Money
from saleor.order.models import Payment
def test_get_purchased_items(order_with_lines, settings, voucher):
-
payment = Payment.objects.create(order=order_with_lines, variant='paypal')
discount = Money('10.0', currency=settings.DEFAULT_CURRENCY)
@@ -15,6 +16,7 @@ def test_get_purchased_items(order_with_lines, settings, voucher):
payment.get_purchased_items(), order_with_lines.get_lines()):
assert p.sku == o.product_sku
assert p.quantity == o.quantity
+ assert p.price == o.unit_price_gross.quantize(Decimal('0.01')).amount
order_with_lines.discount_name = 'Test'
order_with_lines.discount_amount = discount
@@ -30,6 +32,7 @@ def test_get_purchased_items(order_with_lines, settings, voucher):
payment.get_purchased_items()[:-1], order_with_lines.get_lines()):
assert p.sku == o.product_sku
assert p.quantity == o.quantity
+ assert p.price == o.unit_price_gross.quantize(Decimal('0.01')).amount
discounted = payment.get_purchased_items()[-1]