Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Set default order total amounting to zero
Rafał Pitoń7ab6dd699423
diff --git a/saleor/core/utils/random_data.py b/saleor/core/utils/random_data.pyindex 03588bbbd1..9a47c5a337 100644--- a/saleor/core/utils/random_data.py+++ b/saleor/core/utils/random_data.py@@ -440,9 +440,7 @@ def create_fake_order():'shipping_address': address,'user_email': get_email(address.first_name, address.last_name)}- order = Order.objects.create(- total=TaxedMoney(net=Money(0, 'USD'), gross=Money(0, 'USD')),- **user_data)+ order = Order.objects.create(**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_20180312_1203.pysimilarity index 68%rename from saleor/order/migrations/0039_auto_20180309_1022.pyrename to saleor/order/migrations/0039_auto_20180312_1203.pyindex 091ff87faa..bf28d8bbbf 100644--- a/saleor/order/migrations/0039_auto_20180309_1022.py+++ b/saleor/order/migrations/0039_auto_20180312_1203.py@@ -1,7 +1,9 @@-# Generated by Django 2.0.2 on 2018-03-09 16:22+# Generated by Django 2.0.2 on 2018-03-12 17:03+from decimal import Decimalfrom django.db import migrationsimport django_prices.models+import pricesclass Migration(migrations.Migration):@@ -14,11 +16,11 @@ class Migration(migrations.Migration):migrations.AlterField(model_name='order',name='total_gross',- field=django_prices.models.MoneyField(currency='USD', decimal_places=2, max_digits=12),+ field=django_prices.models.MoneyField(currency='USD', decimal_places=2, default=prices.Money('0', currency='USD'), max_digits=12),),migrations.AlterField(model_name='order',name='total_net',- field=django_prices.models.MoneyField(currency='USD', decimal_places=2, max_digits=12),+ field=django_prices.models.MoneyField(currency='USD', decimal_places=2, default=prices.Money('0', currency='USD'), max_digits=12),),]diff --git a/saleor/order/models.py b/saleor/order/models.pyindex f05bf0096c..1c935d7bbd 100644--- a/saleor/order/models.py+++ b/saleor/order/models.py@@ -65,9 +65,11 @@ 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)+ currency=settings.DEFAULT_CURRENCY, max_digits=12, decimal_places=2,+ default=Money(0, settings.DEFAULT_CURRENCY))total_gross = MoneyField(- currency=settings.DEFAULT_CURRENCY, max_digits=12, decimal_places=2)+ currency=settings.DEFAULT_CURRENCY, max_digits=12, decimal_places=2,+ default=Money(0, settings.DEFAULT_CURRENCY))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 63ba5db7f7..a72cad628f 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, TaxedMoney+from prices import Moneyfrom saleor.account.models import Address, Userfrom saleor.cart import utils@@ -72,9 +72,7 @@ def request_cart_with_item(product_in_stock, request_cart):@pytest.fixturedef order(billing_address):- return Order.objects.create(- billing_address=billing_address,- total=TaxedMoney(net=Money(0, 'USD'), gross=Money(0, 'USD')))+ return Order.objects.create(billing_address=billing_address)@pytest.fixture()@@ -600,30 +598,18 @@ def open_orders(billing_address):orders = []- orders.append(- Order.objects.create(- billing_address=billing_address,- total=TaxedMoney(net=Money(0, 'USD'), gross=Money(0, 'USD'))))+ orders.append(Order.objects.create(billing_address=billing_address))DeliveryGroup.objects.create(**group_data(orders, GroupStatus.NEW))- orders.append(- Order.objects.create(- billing_address=billing_address,- total=TaxedMoney(net=Money(0, 'USD'), gross=Money(0, 'USD'))))+ orders.append(Order.objects.create(billing_address=billing_address))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,- total=TaxedMoney(net=Money(0, 'USD'), gross=Money(0, 'USD'))))+ orders.append(Order.objects.create(billing_address=billing_address))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,- total=TaxedMoney(net=Money(0, 'USD'), gross=Money(0, 'USD'))))+ orders.append(Order.objects.create(billing_address=billing_address))DeliveryGroup.objects.create(**group_data(orders, GroupStatus.NEW))DeliveryGroup.objects.create(**group_data(orders, GroupStatus.SHIPPED))DeliveryGroup.objects.create(**group_data(orders, GroupStatus.CANCELLED))@@ -638,30 +624,18 @@ def closed_orders(billing_address):orders = []- orders.append(- Order.objects.create(- billing_address=billing_address,- total=TaxedMoney(net=Money(0, 'USD'), gross=Money(0, 'USD'))))+ orders.append(Order.objects.create(billing_address=billing_address))DeliveryGroup.objects.create(**group_data(orders, GroupStatus.SHIPPED))- orders.append(- Order.objects.create(- billing_address=billing_address,- total=TaxedMoney(net=Money(0, 'USD'), gross=Money(0, 'USD'))))+ orders.append(Order.objects.create(billing_address=billing_address))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,- total=TaxedMoney(net=Money(0, 'USD'), gross=Money(0, 'USD'))))+ orders.append(Order.objects.create(billing_address=billing_address))DeliveryGroup.objects.create(**group_data(orders, GroupStatus.CANCELLED))# empty order is considered as closed- orders.append(- Order.objects.create(- billing_address=billing_address,- total=TaxedMoney(net=Money(0, 'USD'), gross=Money(0, 'USD'))))+ orders.append(Order.objects.create(billing_address=billing_address))return ordersdiff --git a/tests/dashboard/test_order.py b/tests/dashboard/test_order.pyindex bd176c79ea..7ee2fd3a90 100644--- a/tests/dashboard/test_order.py+++ b/tests/dashboard/test_order.py@@ -657,9 +657,7 @@ 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,- total=TaxedMoney(net=Money(0, 'USD'), gross=Money(0, 'USD')))+ order = Order.objects.create(billing_address=billing_address)group = DeliveryGroup.objects.create(order=order)group.process(cart.lines.all())diff --git a/tests/test_elasticsearch.py b/tests/test_elasticsearch.pyindex a898cfb508..755af1f865 100644--- a/tests/test_elasticsearch.py+++ b/tests/test_elasticsearch.py@@ -3,7 +3,6 @@ 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@@ -166,8 +165,7 @@ 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,- total=TaxedMoney(net=Money(0, 'USD'), gross=Money(0, 'USD')))+ billing_address=billing_address, user_email=email, pk=pk)all_pks = all_pks | pksreturn all_pksdiff --git a/tests/test_postgresql_search.py b/tests/test_postgresql_search.pyindex fbef714877..280791bef0 100644--- a/tests/test_postgresql_search.py+++ b/tests/test_postgresql_search.py@@ -2,7 +2,6 @@ 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@@ -126,9 +125,7 @@ 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,- total=TaxedMoney(net=Money(0, 'USD'), gross=Money(0, 'USD')))+ order = Order.objects.create(user=user, billing_address=addr, pk=pk)orders.append(order)return orders