Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Make order.total not nullable
Rafał Pitońd66298c3be99
diff --git a/saleor/core/utils/random_data.py b/saleor/core/utils/random_data.pyindex 9a47c5a337..03588bbbd1 100644--- a/saleor/core/utils/random_data.py+++ b/saleor/core/utils/random_data.py@@ -440,7 +440,9 @@ def create_fake_order():'shipping_address': address,'user_email': get_email(address.first_name, address.last_name)}- order = Order.objects.create(**user_data)+ order = Order.objects.create(+ total=TaxedMoney(net=Money(0, 'USD'), gross=Money(0, 'USD')),+ **user_data)delivery_group = create_delivery_group(order)lines = create_order_lines(delivery_group, random.randrange(1, 5))diff --git a/saleor/order/migrations/0039_auto_20180309_1022.py b/saleor/order/migrations/0039_auto_20180309_1022.pynew file mode 100644index 0000000000..091ff87faa--- /dev/null+++ b/saleor/order/migrations/0039_auto_20180309_1022.py@@ -0,0 +1,24 @@+# Generated by Django 2.0.2 on 2018-03-09 16:22++from django.db import migrations+import django_prices.models+++class Migration(migrations.Migration):++ dependencies = [+ ('order', '0038_auto_20180228_0451'),+ ]++ operations = [+ migrations.AlterField(+ model_name='order',+ name='total_gross',+ field=django_prices.models.MoneyField(currency='USD', decimal_places=2, max_digits=12),+ ),+ migrations.AlterField(+ model_name='order',+ name='total_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.pyindex c85b0b44a8..f05bf0096c 100644--- a/saleor/order/models.py+++ b/saleor/order/models.py@@ -65,11 +65,9 @@ class Order(models.Model):net_field='shipping_price_net', gross_field='shipping_price_gross')token = models.CharField(max_length=36, unique=True)total_net = MoneyField(- currency=settings.DEFAULT_CURRENCY, max_digits=12, decimal_places=2,- blank=True, null=True)+ currency=settings.DEFAULT_CURRENCY, max_digits=12, decimal_places=2)total_gross = MoneyField(- currency=settings.DEFAULT_CURRENCY, max_digits=12, decimal_places=2,- blank=True, null=True)+ currency=settings.DEFAULT_CURRENCY, max_digits=12, decimal_places=2)total = TaxedMoneyField(net_field='total_net', gross_field='total_gross')voucher = models.ForeignKey(Voucher, null=True, related_name='+', on_delete=models.SET_NULL)diff --git a/tests/conftest.py b/tests/conftest.pyindex a72cad628f..63ba5db7f7 100644--- a/tests/conftest.py+++ b/tests/conftest.py@@ -9,7 +9,7 @@ from django.core.files import Filefrom django.core.files.uploadedfile import SimpleUploadedFilefrom django.utils.encoding import smart_textfrom PIL import Image-from prices import Money+from prices import Money, TaxedMoneyfrom saleor.account.models import Address, Userfrom saleor.cart import utils@@ -72,7 +72,9 @@ def request_cart_with_item(product_in_stock, request_cart):@pytest.fixturedef order(billing_address):- return Order.objects.create(billing_address=billing_address)+ return Order.objects.create(+ billing_address=billing_address,+ total=TaxedMoney(net=Money(0, 'USD'), gross=Money(0, 'USD')))@pytest.fixture()@@ -598,18 +600,30 @@ def open_orders(billing_address):orders = []- orders.append(Order.objects.create(billing_address=billing_address))+ orders.append(+ Order.objects.create(+ billing_address=billing_address,+ total=TaxedMoney(net=Money(0, 'USD'), gross=Money(0, 'USD'))))DeliveryGroup.objects.create(**group_data(orders, GroupStatus.NEW))- orders.append(Order.objects.create(billing_address=billing_address))+ orders.append(+ Order.objects.create(+ billing_address=billing_address,+ total=TaxedMoney(net=Money(0, 'USD'), gross=Money(0, 'USD'))))DeliveryGroup.objects.create(**group_data(orders, GroupStatus.NEW))DeliveryGroup.objects.create(**group_data(orders, GroupStatus.CANCELLED))- orders.append(Order.objects.create(billing_address=billing_address))+ orders.append(+ Order.objects.create(+ billing_address=billing_address,+ total=TaxedMoney(net=Money(0, 'USD'), gross=Money(0, 'USD'))))DeliveryGroup.objects.create(**group_data(orders, GroupStatus.NEW))DeliveryGroup.objects.create(**group_data(orders, GroupStatus.SHIPPED))- orders.append(Order.objects.create(billing_address=billing_address))+ orders.append(+ Order.objects.create(+ billing_address=billing_address,+ total=TaxedMoney(net=Money(0, 'USD'), gross=Money(0, 'USD'))))DeliveryGroup.objects.create(**group_data(orders, GroupStatus.NEW))DeliveryGroup.objects.create(**group_data(orders, GroupStatus.SHIPPED))DeliveryGroup.objects.create(**group_data(orders, GroupStatus.CANCELLED))@@ -624,18 +638,30 @@ def closed_orders(billing_address):orders = []- orders.append(Order.objects.create(billing_address=billing_address))+ orders.append(+ Order.objects.create(+ billing_address=billing_address,+ total=TaxedMoney(net=Money(0, 'USD'), gross=Money(0, 'USD'))))DeliveryGroup.objects.create(**group_data(orders, GroupStatus.SHIPPED))- orders.append(Order.objects.create(billing_address=billing_address))+ orders.append(+ Order.objects.create(+ billing_address=billing_address,+ total=TaxedMoney(net=Money(0, 'USD'), gross=Money(0, 'USD'))))DeliveryGroup.objects.create(**group_data(orders, GroupStatus.SHIPPED))DeliveryGroup.objects.create(**group_data(orders, GroupStatus.CANCELLED))- orders.append(Order.objects.create(billing_address=billing_address))+ orders.append(+ Order.objects.create(+ billing_address=billing_address,+ total=TaxedMoney(net=Money(0, 'USD'), gross=Money(0, 'USD'))))DeliveryGroup.objects.create(**group_data(orders, GroupStatus.CANCELLED))# empty order is considered as closed- orders.append(Order.objects.create(billing_address=billing_address))+ orders.append(+ Order.objects.create(+ billing_address=billing_address,+ total=TaxedMoney(net=Money(0, 'USD'), gross=Money(0, 'USD'))))return ordersdiff --git a/tests/dashboard/test_order.py b/tests/dashboard/test_order.pyindex 7ee2fd3a90..bd176c79ea 100644--- a/tests/dashboard/test_order.py+++ b/tests/dashboard/test_order.py@@ -657,7 +657,9 @@ def test_process_new_delivery_group(billing_address, product_in_stock):cart = Cart()cart.save()cart.add(variant, quantity=2)- order = Order.objects.create(billing_address=billing_address)+ order = Order.objects.create(+ billing_address=billing_address,+ total=TaxedMoney(net=Money(0, 'USD'), gross=Money(0, 'USD')))group = DeliveryGroup.objects.create(order=order)group.process(cart.lines.all())diff --git a/tests/test_elasticsearch.py b/tests/test_elasticsearch.pyindex 755af1f865..a898cfb508 100644--- a/tests/test_elasticsearch.py+++ b/tests/test_elasticsearch.py@@ -3,6 +3,7 @@ from decimal import Decimalimport pytestfrom django.urls import reversefrom elasticsearch_dsl.connections import connections+from prices import Money, TaxedMoneyfrom saleor.account.models import Userfrom saleor.order.models import Order@@ -165,7 +166,8 @@ def orders(db, billing_address):for email, pks in ORDERS.items():for pk in pks:Order.objects.create(- billing_address=billing_address, user_email=email, pk=pk)+ billing_address=billing_address, user_email=email, pk=pk,+ total=TaxedMoney(net=Money(0, 'USD'), gross=Money(0, 'USD')))all_pks = all_pks | pksreturn all_pksdiff --git a/tests/test_postgresql_search.py b/tests/test_postgresql_search.pyindex 280791bef0..fbef714877 100644--- a/tests/test_postgresql_search.py+++ b/tests/test_postgresql_search.py@@ -2,6 +2,7 @@ from decimal import Decimalimport pytestfrom django.urls import reverse+from prices import Money, TaxedMoneyfrom saleor.account.models import Address, Userfrom saleor.order.models import Order@@ -125,7 +126,9 @@ def orders_with_addresses():for pk, name, lastname, email in ORDERS:addr = gen_address_for_user(name, lastname)user = User.objects.create(default_shipping_address=addr, email=email)- order = Order.objects.create(user=user, billing_address=addr, pk=pk)+ order = Order.objects.create(+ user=user, billing_address=addr, pk=pk,+ total=TaxedMoney(net=Money(0, 'USD'), gross=Money(0, 'USD')))orders.append(order)return orders