Skip to content

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

Empty order order improvements

Anna Siwik0a5aec82709d
diff --git a/saleor/dashboard/order/forms.py b/saleor/dashboard/order/forms.py
index c78055670c..c24092e9bc 100644
--- a/saleor/dashboard/order/forms.py
+++ b/saleor/dashboard/order/forms.py
@@ -15,12 +15,13 @@ from ...order import OrderStatus
from ...order.emails import send_note_confirmation
from ...order.models import Fulfillment, FulfillmentLine, OrderLine, OrderNote
from ...order.utils import (
- add_variant_to_order, change_order_line_quantity, fulfill_order_line,
+ add_variant_to_order, change_order_line_quantity,
merge_duplicates_into_order_line, recalculate_order, restock_order_lines)
from ...product.models import Product, ProductVariant, Stock
from ...product.utils import allocate_stock, deallocate_stock
from ..forms import AjaxSelect2ChoiceField
from ..widgets import PhonePrefixWidget
+from .utils import fulfill_order_line
class OrderNoteForm(forms.ModelForm):
@@ -112,11 +113,6 @@ class CancelOrderLineForm(forms.Form):
deallocate_stock(self.line.stock, self.line.quantity)
order = self.line.order
self.line.delete()
- if not order.lines.exists():
- order.create_history_entry(
- content=pgettext_lazy(
- 'Order status history entry',
- 'Order cancelled. No items in order'))
recalculate_order(order)
diff --git a/saleor/order/utils.py b/saleor/order/utils.py
index c34706deea..271186e470 100644
--- a/saleor/order/utils.py
+++ b/saleor/order/utils.py
@@ -3,10 +3,7 @@ from functools import wraps
from django.conf import settings
from django.db.models import F
from django.shortcuts import get_object_or_404, redirect
-from django.utils.translation import pgettext_lazy
-from prices import Money, TaxedMoney, fixed_discount
-from . import GroupStatus
from ..account.utils import store_user_address
from ..core.exceptions import InsufficientStock
from ..product.utils import allocate_stock, deallocate_stock, increase_stock
diff --git a/templates/dashboard/order/detail.html b/templates/dashboard/order/detail.html
index 891e15d045..c9c7eecfb3 100644
--- a/templates/dashboard/order/detail.html
+++ b/templates/dashboard/order/detail.html
@@ -330,7 +330,7 @@
</div>
{% if perms.order.edit_order and order.can_edit or order.can_fulfill %}
<div class="data-table-action">
- {% if order.can_fulfill %}
+ {% if order.can_fulfill and order.get_total_quantity %}
<a href="{% url 'dashboard:fulfill-order-lines' order_pk=order.pk %}" class="btn-flat waves-effect" title="{% trans "Fulfill order" context "Order summary card action title" %}">
{% trans "Fulfill" context "Order summary card action" %}
</a>
diff --git a/tests/dashboard/test_order.py b/tests/dashboard/test_order.py
index 31c5091f86..8b2d995c8e 100644
--- a/tests/dashboard/test_order.py
+++ b/tests/dashboard/test_order.py
@@ -10,8 +10,7 @@ from tests.utils import get_redirect_location, get_url_path
from saleor.dashboard.order.forms import ChangeQuantityForm, OrderNoteForm
from saleor.dashboard.order.utils import fulfill_order_line
-from saleor.order.models import (
- Fulfillment, Order, OrderHistoryEntry, OrderLine, OrderNote)
+from saleor.order.models import Order, OrderHistoryEntry, OrderLine, OrderNote
from saleor.order.utils import (
add_variant_to_existing_lines, add_variant_to_order,
change_order_line_quantity)
@@ -213,9 +212,7 @@ def test_ordered_item_change_quantity(transactional_db, order_with_lines):
change_order_line_quantity(lines[2], 0)
change_order_line_quantity(lines[1], 0)
change_order_line_quantity(lines[0], 0)
- history = list(order_with_lines.history.all())
- assert len(history) == 1
- assert history[0].content == 'Order cancelled. No items in order'
+ assert order_with_lines.get_total_quantity() == 0
@pytest.mark.integration