Skip to content

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

Fixes after rebase with latest naster

Pacu23ec32281b74c
diff --git a/saleor/dashboard/discount/forms.py b/saleor/dashboard/discount/forms.py
index 0df42a1943..09cd2266ad 100644
--- a/saleor/dashboard/discount/forms.py
+++ b/saleor/dashboard/discount/forms.py
@@ -165,9 +165,6 @@ class CommonVoucherForm(forms.ModelForm):
apply_to = forms.ChoiceField(
choices=VoucherApplyToProduct.CHOICES, required=False)
- def __init__(self, *args, **kwargs):
- super().__init__(*args, **kwargs)
-
def save(self, commit=True):
self.instance.limit = None
# Apply to one with percentage discount is more complicated case.
diff --git a/saleor/dashboard/order/urls.py b/saleor/dashboard/order/urls.py
index 9308cc21dc..d1bd755560 100644
--- a/saleor/dashboard/order/urls.py
+++ b/saleor/dashboard/order/urls.py
@@ -43,8 +43,6 @@ urlpatterns = [
views.orderline_change_quantity, name='orderline-change-quantity'),
url(r'^(?P<order_pk>\d+)/line/(?P<line_pk>\d+)/cancel/$',
views.orderline_cancel, name='orderline-cancel'),
- url(r'^(?P<order_pk>\d+)/remove-voucher/$',
- views.remove_order_voucher, name='order-remove-voucher'),
url(r'^(?P<order_pk>\d+)/add-variant/$',
views.add_variant_to_order, name='add-variant-to-order'),
url(r'^(?P<order_pk>\d+)/fulfill/$',
diff --git a/saleor/dashboard/order/views.py b/saleor/dashboard/order/views.py
index b5ee82210b..47848ee803 100644
--- a/saleor/dashboard/order/views.py
+++ b/saleor/dashboard/order/views.py
@@ -27,12 +27,12 @@ from .filters import OrderFilter
from .forms import (
AddressForm, AddVariantToOrderForm, BaseFulfillmentLineFormSet,
CancelFulfillmentForm, CancelOrderForm, CancelOrderLineForm,
- CapturePaymentForm, ChangeQuantityForm,
- CreateOrderFromDraftForm, FulfillmentForm, FulfillmentLineForm,
- FulfillmentTrackingNumberForm, OrderCustomerForm, OrderEditDiscountForm,
- OrderEditVoucherForm, OrderMarkAsPaidForm, OrderNoteForm,
- OrderRemoveCustomerForm, OrderRemoveShippingForm, OrderRemoveVoucherForm,
- OrderShippingForm, RefundPaymentForm, ReleasePaymentForm)
+ CapturePaymentForm, ChangeQuantityForm, CreateOrderFromDraftForm,
+ FulfillmentForm, FulfillmentLineForm, FulfillmentTrackingNumberForm,
+ OrderCustomerForm, OrderEditDiscountForm, OrderEditVoucherForm,
+ OrderMarkAsPaidForm, OrderNoteForm, OrderRemoveCustomerForm,
+ OrderRemoveShippingForm, OrderRemoveVoucherForm, OrderShippingForm,
+ RefundPaymentForm, ReleasePaymentForm)
from .utils import (
create_invoice_pdf, create_packing_slip_pdf, get_statics_absolute_url,
save_address_in_order)
diff --git a/saleor/order/migrations/0044_auto_20180329_0142.py b/saleor/order/migrations/0045_auto_20180329_0142.py
similarity index 62%
rename from saleor/order/migrations/0044_auto_20180329_0142.py
rename to saleor/order/migrations/0045_auto_20180329_0142.py
index 4dfdc5d4c6..d22b1664f9 100644
--- a/saleor/order/migrations/0044_auto_20180329_0142.py
+++ b/saleor/order/migrations/0045_auto_20180329_0142.py
@@ -2,13 +2,14 @@
from django.db import migrations, models
import django.db.models.deletion
+import django_prices.models
class Migration(migrations.Migration):
dependencies = [
('product', '0054_merge_20180320_1108'),
- ('order', '0043_auto_20180322_0655'),
+ ('order', '0044_auto_20180326_1055'),
]
operations = [
@@ -29,4 +30,14 @@ class Migration(migrations.Migration):
model_name='orderline',
name='product',
),
+ migrations.AlterField(
+ model_name='orderline',
+ name='unit_price_gross',
+ field=django_prices.models.MoneyField(currency='USD', decimal_places=2, max_digits=12),
+ ),
+ migrations.AlterField(
+ model_name='orderline',
+ name='unit_price_net',
+ field=django_prices.models.MoneyField(currency='USD', decimal_places=2, max_digits=12),
+ ),
]
diff --git a/saleor/order/models.py b/saleor/order/models.py
index a6102b157a..2b6ac69a20 100644
--- a/saleor/order/models.py
+++ b/saleor/order/models.py
@@ -188,9 +188,9 @@ class OrderLine(models.Model):
quantity_fulfilled = models.IntegerField(
validators=[MinValueValidator(0), MaxValueValidator(999)], default=0)
unit_price_net = MoneyField(
- currency=settings.DEFAULT_CURRENCY, max_digits=12, decimal_places=4)
+ currency=settings.DEFAULT_CURRENCY, max_digits=12, decimal_places=2)
unit_price_gross = MoneyField(
- currency=settings.DEFAULT_CURRENCY, max_digits=12, decimal_places=4)
+ currency=settings.DEFAULT_CURRENCY, max_digits=12, decimal_places=2)
unit_price = TaxedMoneyField(
net_field='unit_price_net', gross_field='unit_price_gross')
diff --git a/saleor/product/migrations/0057_auto_20180329_0142.py b/saleor/product/migrations/0057_auto_20180329_0142.py
index d432b3818a..26613ceacf 100644
--- a/saleor/product/migrations/0057_auto_20180329_0142.py
+++ b/saleor/product/migrations/0057_auto_20180329_0142.py
@@ -9,7 +9,7 @@ import django_prices.models
class Migration(migrations.Migration):
dependencies = [
- ('order', '0044_auto_20180329_0142'),
+ ('order', '0045_auto_20180329_0142'),
('product', '0056_auto_20180330_0321'),
]
diff --git a/tests/conftest.py b/tests/conftest.py
index fae5333c92..d1dc6d059f 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -367,7 +367,7 @@ def voucher(db): # pylint: disable=W0613
@pytest.fixture()
-def order_with_lines(order, product_type, default_category):
+def order_with_lines(order, product_type, default_category, shipping_method):
product = Product.objects.create(
name='Test product', price=Money('10.00', 'USD'),
product_type=product_type, category=default_category)
@@ -400,20 +400,22 @@ def order_with_lines(order, product_type, default_category):
name='Test product 3', price=Money('30.00', 'USD'),
product_type=product_type, category=default_category)
- order.lines.create(
- product_name=product.name,
- product_sku='SKU_%d' % (product.pk,),
- is_shipping_required=product.product_type.is_shipping_required,
- quantity=1,
- unit_price_net=Decimal('30.00'),
- unit_price_gross=Decimal('30.00'))
+ order.shipping_address = order.billing_address.get_copy()
+ order.shipping_method_name = shipping_method.name
+ method = shipping_method.price_per_country.get()
+ order.shipping_method = method
+ order.shipping_price = method.get_total_price()
+ order.save()
+ recalculate_order(order)
+ order.refresh_from_db()
recalculate_order(order)
return order
@pytest.fixture()
-def order_with_lines_and_stock(order, product_type, default_category):
+def order_with_lines_and_stock(
+ order, product_type, default_category, shipping_method):
product = Product.objects.create(
name='Test product', price=Money('10.00', 'USD'),
product_type=product_type, category=default_category)
@@ -478,6 +480,13 @@ def draft_order(order_with_lines):
return order_with_lines
+def draft_order_with_stock(order_with_lines_and_stock):
+ order_with_lines_and_stock.status = OrderStatus.DRAFT
+ order_with_lines_and_stock.save(update_fields=['status'])
+ return order_with_lines_and_stock
+
+
@pytest.fixture()
def payment_waiting(order_with_lines):
return order_with_lines.payments.create(
diff --git a/tests/dashboard/test_discount.py b/tests/dashboard/test_discount.py
deleted file mode 100644
index 22448726f9..0000000000
--- a/tests/dashboard/test_discount.py
+++ /dev/null
@@ -1,91 +0,0 @@
-from datetime import date
-from decimal import Decimal
-
-from django.urls import reverse
-from prices import Money
-
-from saleor.discount import DiscountValueType, VoucherType
-from saleor.discount.models import Sale, Voucher
-
-
-def test_sales_list(admin_client, sale):
- url = reverse('dashboard:sale-list')
- response = admin_client.get(url)
- assert response.status_code == 200
-
-
-def test_vouchers_list(admin_client, voucher):
- url = reverse('dashboard:voucher-list')
- response = admin_client.get(url)
- assert response.status_code == 200
-
-
-def test_voucher_shipping_add(admin_client):
- assert len(Voucher.objects.all()) == 0
- url = reverse('dashboard:voucher-add')
- data = {
- 'code': 'TESTVOUCHER', 'name': 'Test Voucher',
- 'start_date': '2018-01-01', 'end_date': '2018-06-01',
- 'type': VoucherType.SHIPPING, 'discount_value': '15.99',
- 'discount_value_type': DiscountValueType.FIXED,
- 'shipping-limit': '59.99'}
- response = admin_client.post(url, data, follow=True)
- assert response.status_code == 200
- assert len(Voucher.objects.all()) == 1
-
- voucher = Voucher.objects.all()[0]
- assert voucher.type == VoucherType.SHIPPING
- assert voucher.code == data['code']
- assert voucher.name == data['name']
- assert voucher.start_date == date(2018, 1, 1)
- assert voucher.end_date == date(2018, 6, 1)
- assert voucher.discount_value_type == DiscountValueType.FIXED
- assert voucher.discount_value == Decimal('15.99')
- assert voucher.limit == Money('59.99', 'USD')
-
-
-def test_view_sale_add(admin_client, default_category):
- url = reverse('dashboard:sale-add')
- data = {
- 'name': 'Free products',
- 'type': DiscountValueType.PERCENTAGE,
- 'value': 100,
- 'categories': [default_category.id]}
-
- response = admin_client.post(url, data)
-
- assert response.status_code == 302
- assert Sale.objects.count() == 1
- sale = Sale.objects.first()
- assert sale.name == data['name']
- assert default_category in sale.categories.all()
-
-
-def test_view_sale_add_requires_product_or_category(
- admin_client, default_category, product):
- url = reverse('dashboard:sale-add')
- data = {
- 'name': 'Free products',
- 'type': DiscountValueType.PERCENTAGE,
- 'value': 100}
-
- response = admin_client.post(url, data)
-
- assert response.status_code == 200
- assert Sale.objects.count() == 0
-
- data_with_category = data.copy()
- data_with_category.update({'categories': [default_category.id]})
-
- response = admin_client.post(url, data_with_category)
-
- assert response.status_code == 302
- assert Sale.objects.count() == 1
-
- data_with_product = data.copy()
- data_with_product.update({'products': [product.id]})
-
- response = admin_client.post(url, data_with_product)
-
- assert response.status_code == 302
- assert Sale.objects.count() == 2
diff --git a/tests/dashboard/test_discounts.py b/tests/dashboard/test_discounts.py
index 9afbf2e4f5..0a71f113bb 100644
--- a/tests/dashboard/test_discounts.py
+++ b/tests/dashboard/test_discounts.py
@@ -66,7 +66,7 @@ def test_view_sale_add(admin_client, default_category):
def test_view_sale_add_requires_product_or_category(
- admin_client, default_category, product_in_stock):
+ admin_client, default_category, product):
url = reverse('dashboard:sale-add')
data = {
'name': 'Free products',
@@ -87,7 +87,7 @@ def test_view_sale_add_requires_product_or_category(
assert Sale.objects.count() == 1
data_with_product = data.copy()
- data_with_product.update({'products': [product_in_stock.id]})
+ data_with_product.update({'products': [product.id]})
response = admin_client.post(url, data_with_product)
diff --git a/tests/dashboard/test_order.py b/tests/dashboard/test_order.py
index 543be968f2..4bf5811f6e 100644
--- a/tests/dashboard/test_order.py
+++ b/tests/dashboard/test_order.py
@@ -442,24 +442,23 @@ def test_view_cancel_order_line(admin_client, draft_order):
@pytest.mark.integration
@pytest.mark.django_db
-def test_view_change_order_line_quantity(admin_client, draft_order):
- lines_before_quantity_change = draft_order.lines.all()
+def test_view_change_order_line_quantity(admin_client, draft_order_with_stock):
+ order = draft_order_with_stock
+ lines_before_quantity_change = order.lines.all()
lines_before_quantity_change_count = lines_before_quantity_change.count()
line = lines_before_quantity_change.first()
url = reverse(
- 'dashboard:orderline-change-quantity', kwargs={
- 'order_pk': draft_order.pk,
- 'line_pk': line.pk})
+ 'dashboard:orderline-change-quantity',
+ kwargs={'order_pk': order.pk, 'line_pk': line.pk})
response = admin_client.get(url)
assert response.status_code == 200
- response = admin_client.post(
- url, {'quantity': 2}, follow=True)
+ response = admin_client.post(url, {'quantity': 2}, follow=True)
redirected_to, redirect_status_code = response.redirect_chain[-1]
# check redirection
assert redirect_status_code == 302
assert redirected_to == reverse(
- 'dashboard:order-details', kwargs={'order_pk': draft_order.id})
+ 'dashboard:order-details', kwargs={'order_pk': order.id})
# success messages should appear after redirect
assert response.context['messages']
lines_after = Order.objects.get().lines.all()
@@ -536,7 +535,7 @@ def test_dashboard_change_quantity_form(request_cart_with_item, order):
def test_ordered_item_change_quantity(transactional_db, order_with_lines):
- assert list(order_with_lines.history.all()) == []
+ assert not order_with_lines.history.count()
lines = order_with_lines.lines.all()
change_order_line_quantity(lines[1], 0)
change_order_line_quantity(lines[0], 0)
@@ -619,8 +618,9 @@ def test_add_variant_to_existing_lines_one_line(
def test_view_add_variant_to_order(
admin_client, order_with_lines_and_stock):
- order.status = OrderStatus.DRAFT
order = order_with_lines_and_stock
+ order.status = OrderStatus.DRAFT
+ order.save()
variant = ProductVariant.objects.get(sku='SKU_A')
line = OrderLine.objects.get(product_sku='SKU_A')
line_quantity_before = line.quantity
diff --git a/tests/test_order.py b/tests/test_order.py
index c5e99267ff..ef7589a79f 100644
--- a/tests/test_order.py
+++ b/tests/test_order.py
@@ -51,8 +51,8 @@ def test_add_variant_to_order_adds_line_for_new_variant(
def test_add_variant_to_order_allocates_stock_for_new_variant(
- order_with_lines, product):
- order = order_with_lines
+ order_with_lines_and_stock, product):
+ order = order_with_lines_and_stock
variant = product.variants.get()
stock_before = variant.quantity_allocated
@@ -63,8 +63,8 @@ def test_add_variant_to_order_allocates_stock_for_new_variant(
def test_add_variant_to_order_edits_line_for_existing_variant(
- order_with_lines):
- order = order_with_lines
+ order_with_lines_and_stock):
+ order = order_with_lines_and_stock
existing_line = order.lines.first()
variant = existing_line.variant
lines_before = order.lines.count()
@@ -79,8 +79,8 @@ def test_add_variant_to_order_edits_line_for_existing_variant(
def test_add_variant_to_order_allocates_stock_for_existing_variant(
- order_with_lines):
- order = order_with_lines
+ order_with_lines_and_stock):
+ order = order_with_lines_and_stock
existing_line = order.lines.first()
variant = existing_line.variant
stock_before = variant.quantity_allocated