Skip to content

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

Revert "Paypal discounts moved to django-payments"

Krzysztof Wolskid1112762b5f2
diff --git a/saleor/order/models.py b/saleor/order/models.py
index f18917b307..3d36db8fb5 100644
--- a/saleor/order/models.py
+++ b/saleor/order/models.py
@@ -4,26 +4,26 @@ from decimal import Decimal
from uuid import uuid4
import emailit.api
-import payments
from django.conf import settings
from django.core.exceptions import ObjectDoesNotExist
from django.core.urlresolvers import reverse
from django.core.validators import MaxValueValidator, MinValueValidator
from django.db import models
-from django.utils.encoding import python_2_unicode_compatible
+from django.utils.encoding import python_2_unicode_compatible, smart_text
from django.utils.timezone import now
from django.utils.translation import pgettext_lazy
from django_prices.models import PriceField
+from payments import PurchasedItem
from payments.models import BasePayment
-from prices import FixedDiscount, Price
+from prices import Price, FixedDiscount
from satchless.item import ItemLine, ItemSet
-from . import Status
from ..core.utils import build_absolute_uri
from ..discount.models import Voucher
from ..product.models import Product, Stock
-from ..search import index
from ..userprofile.models import Address
+from ..search import index
+from . import Status
class OrderManager(models.Manager):
@@ -431,21 +431,24 @@ class Payment(BasePayment):
from_email=settings.ORDER_FROM_EMAIL)
def get_purchased_items(self):
- return [payments.PurchasedItem(
+ items = [PurchasedItem(
name=item.product_name, sku=item.product_sku,
quantity=item.quantity,
price=item.unit_price_gross.quantize(Decimal('0.01')),
currency=settings.DEFAULT_CURRENCY)
for item in self.order.get_items()]
- def get_discounts(self):
+ # PayPal require discount info as item with negative price.
+ provider, _ = settings.PAYMENT_VARIANTS.get(self.variant, (None, None))
voucher = self.order.voucher
- if voucher is None:
- return []
- return [payments.Discount(
- name=self.order.discount_name,
- amount=self.order.discount_amount.net.quantize(Decimal('0.01')),
- currency=self.currency)]
+ if provider and 'PaypalProvider' in provider and voucher is not None:
+ items.append(PurchasedItem(
+ name=self.order.discount_name,
+ sku='DISCOUNT',
+ quantity=1,
+ price=-1 * self.order.discount_amount.net,
+ currency=self.currency))
+ return items
def get_total_price(self):
net = self.total - self.tax
diff --git a/tests/test_payment.py b/tests/test_payment.py
index 013785a2e3..a4c7c59845 100644
--- a/tests/test_payment.py
+++ b/tests/test_payment.py
@@ -3,24 +3,33 @@ from prices import Price
from saleor.order.models import Payment
-def test_get_purchased_items_and_discounts(order_with_items, settings, voucher):
- settings.PAYMENT_VARIANTS = {'paypal': ('PaypalProvider', {})}
+def test_get_purchased_items(order_with_items, settings, voucher):
payment = Payment.objects.create(order=order_with_items, variant='paypal')
discount = Price('10.0', currency=settings.DEFAULT_CURRENCY)
- payment_items = payment.get_purchased_items()
+
+ assert len(payment.get_purchased_items()) == len(order_with_items.get_items())
+
+ for p, o in zip(payment.get_purchased_items(), order_with_items.get_items()):
+ assert p.sku == o.product_sku
+ assert p.quantity == o.quantity
order_with_items.discount_name = 'Test'
order_with_items.discount_amount = discount
order_with_items.voucher = voucher
order_with_items.save()
- assert len(payment_items) == len(order_with_items.get_items())
- pairs = zip(payment_items, order_with_items.get_items())
- for payment_item, order_item in pairs:
- assert payment_item.sku == order_item.product_sku
- assert payment_item.quantity == order_item.quantity
+ settings.PAYMENT_VARIANTS = { 'paypal': ('PaypalProvider', {})}
+
+ assert len(payment.get_purchased_items()) == len(order_with_items.get_items()) + 1
+
+ for p, o in zip(payment.get_purchased_items()[:-1], order_with_items.get_items()):
+ assert p.sku == o.product_sku
+ assert p.quantity == o.quantity
+
+ discounted = payment.get_purchased_items()[-1]
- discounted = payment.get_discounts()[0]
assert discounted.name == order_with_items.discount_name
- assert discounted.amount == order_with_items.discount_amount.net
+ assert discounted.sku == 'DISCOUNT'
+ assert discounted.price == -1 * order_with_items.discount_amount.net
+ assert discounted.quantity == 1