Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Access order status by class only
Anna Siwik6cc70bca113f
diff --git a/saleor/core/utils/random_data.py b/saleor/core/utils/random_data.pyindex 63dfb74ca6..184ad28f8f 100644--- a/saleor/core/utils/random_data.py+++ b/saleor/core/utils/random_data.py@@ -404,7 +404,7 @@ def create_delivery_group(order):shipping_country = shipping_method.price_per_country.get_or_create(country_code=region, defaults={'price': fake.price()})[0]delivery_group = DeliveryGroup.objects.create(- status=random.choice(['new', 'shipped']),+ status=random.choice([OrderStatus.NEW, OrderStatus.SHIPPED]),order=order,shipping_method_name=str(shipping_country),shipping_price=shipping_country.price)diff --git a/saleor/dashboard/order/forms.py b/saleor/dashboard/order/forms.pyindex 4ec6c6e98f..0f9a9fde49 100644--- a/saleor/dashboard/order/forms.py+++ b/saleor/dashboard/order/forms.py@@ -133,7 +133,7 @@ class MoveLinesForm(forms.Form):def get_delivery_group_choices(self):group = self.line.delivery_groupgroups = group.order.groups.exclude(pk=group.pk).exclude(- status='cancelled')+ status=OrderStatus.CANCELLED)choices = [(self.NEW_SHIPMENT, pgettext_lazy('Delivery group value for `target_group` field','New shipment'))]@@ -404,7 +404,6 @@ class AddVariantToOrderForm(forms.Form):quantity = self.cleaned_data.get('quantity')target_group = self.cleaned_data.get('target_group')if not target_group:- target_group = self.order.groups.create(- status=OrderStatus.NEW)+ target_group = self.order.groups.create(status=OrderStatus.NEW)add_variant_to_delivery_group(target_group, variant, quantity)Order.objects.recalculate_order(self.order)diff --git a/templates/dashboard/order/detail.html b/templates/dashboard/order/detail.htmlindex b83cdd4421..79d6f54d33 100644--- a/templates/dashboard/order/detail.html+++ b/templates/dashboard/order/detail.html@@ -304,66 +304,66 @@</tr>{% endif %}</tfoot>- <tbody>- {% for item in group.items.all %}- <tr>- <td>- {{ item.product_name }}<br>- </td>- <td class="right-align">- {% if group.can_edit_items %}- <a class="dropdown-button" href="#" data-activates="line-stock-actions-{{ item.pk }}" data-constrainwidth="false">- {{ item.stock_location|default:"-" }}- <svg data-src="{% static "dashboard/images/arrow_drop_down.svg" %}" width="24" height="24" />- </a>- <ul id="line-stock-actions-{{ item.pk }}" class="dropdown-content">- <li>- <a href="#base-modal" data-href="{% url 'dashboard:orderline-change-stock' order_pk=order.pk line_pk=item.pk %}" class="modal-trigger-custom" {% if group.status != 'new' %} disabled{% endif %} title="{% trans "Change stock location" context "Shipment group table row action" %}">- {% trans "Change stock" context "Shipment group table row action" %}- </a>- </li>- </ul>- {% else %}+ <tbody>+ {% for item in group.items.all %}+ <tr>+ <td>+ {{ item.product_name }}<br>+ </td>+ <td class="right-align">+ {% if group.can_edit_items %}+ <a class="dropdown-button" href="#" data-activates="line-stock-actions-{{ item.pk }}" data-constrainwidth="false">{{ item.stock_location|default:"-" }}- {% endif %}- </td>- <td>- {{ item.product_sku }}- </td>- <td class="right-align">- {% gross item.get_price_per_item html=True %}- </td>- <td class="right-align">- {% if group.can_edit_items %}- <a class="dropdown-button" href="#" data-activates="line-actions-{{ item.pk }}" data-constrainwidth="false">- {{ item.quantity }}- <svg data-src="{% static "dashboard/images/arrow_drop_down.svg" %}" width="24" height="24" />- </a>- <ul id="line-actions-{{ item.pk }}" class="dropdown-content">- <li>- <a href="#base-modal" data-href="{% url 'dashboard:orderline-change-quantity' order_pk=order.pk line_pk=item.pk %}" class="modal-trigger-custom" {% if group.status != 'new' %} disabled{% endif %} title="{% trans "Change quantity" context "Shipment group table row action" %}">- {% trans "Change quantity" context "Shipment group table row action" %}- </a>- </li>- <li>- <a href="#base-modal" data-href="{% url 'dashboard:orderline-split' order_pk=order.pk line_pk=item.pk %}" class="modal-trigger-custom" {% if group.status != 'new' %} disabled{% endif %} title="{% trans "Split line" context "Shipment group table row action" %}">- {% trans "Split order line" context "Shipment group table row action" %}- </a>- </li>- <li>- <a href="#base-modal" data-href="{% url 'dashboard:orderline-cancel' order_pk=order.pk line_pk=item.pk %}" class="modal-trigger-custom" title="{% trans "Remove line" context "Shipment group table row action" %}">- {% trans "Remove line" context "Shipment group table row action" %}- </a>- </li>- </ul>- {% else %}- {{ item.quantity }}- {% endif %}- </td>- <td class="right-align">- {% gross item.get_total html=True %}- </td>- </tr>+ <svg data-src="{% static "dashboard/images/arrow_drop_down.svg" %}" width="24" height="24" />+ </a>+ <ul id="line-stock-actions-{{ item.pk }}" class="dropdown-content">+ <li>+ <a href="#base-modal" data-href="{% url 'dashboard:orderline-change-stock' order_pk=order.pk line_pk=item.pk %}" class="modal-trigger-custom" title="{% trans "Change stock location" context "Shipment group table row action" %}">+ {% trans "Change stock" context "Shipment group table row action" %}+ </a>+ </li>+ </ul>+ {% else %}+ {{ item.stock_location|default:"-" }}+ {% endif %}+ </td>+ <td>+ {{ item.product_sku }}+ </td>+ <td class="right-align">+ {% gross item.get_price_per_item html=True %}+ </td>+ <td class="right-align">+ {% if group.can_edit_items %}+ <a class="dropdown-button" href="#" data-activates="line-actions-{{ item.pk }}" data-constrainwidth="false">+ {{ item.quantity }}+ <svg data-src="{% static "dashboard/images/arrow_drop_down.svg" %}" width="24" height="24" />+ </a>+ <ul id="line-actions-{{ item.pk }}" class="dropdown-content">+ <li>+ <a href="#base-modal" data-href="{% url 'dashboard:orderline-change-quantity' order_pk=order.pk line_pk=item.pk %}" class="modal-trigger-custom" title="{% trans "Change quantity" context "Shipment group table row action" %}">+ {% trans "Change quantity" context "Shipment group table row action" %}+ </a>+ </li>+ <li>+ <a href="#base-modal" data-href="{% url 'dashboard:orderline-split' order_pk=order.pk line_pk=item.pk %}" class="modal-trigger-custom" title="{% trans "Split line" context "Shipment group table row action" %}">+ {% trans "Split order line" context "Shipment group table row action" %}+ </a>+ </li>+ <li>+ <a href="#base-modal" data-href="{% url 'dashboard:orderline-cancel' order_pk=order.pk line_pk=item.pk %}" class="modal-trigger-custom" title="{% trans "Remove line" context "Shipment group table row action" %}">+ {% trans "Remove line" context "Shipment group table row action" %}+ </a>+ </li>+ </ul>+ {% else %}+ {{ item.quantity }}+ {% endif %}+ </td>+ <td class="right-align">+ {% gross item.get_total html=True %}+ </td>+ </tr>{% endfor %}</tbody></table>diff --git a/tests/dashboard/test_order.py b/tests/dashboard/test_order.pyindex 6d1102251f..df5e963b57 100644--- a/tests/dashboard/test_order.py+++ b/tests/dashboard/test_order.py@@ -6,6 +6,7 @@ import pytestfrom django.urls import reversefrom saleor.dashboard.order.forms import ChangeQuantityForm, MoveLinesForm+from saleor.order import OrderStatusfrom saleor.order.models import (DeliveryGroup, Order, OrderLine, OrderHistoryEntry)from saleor.order.utils import (@@ -277,7 +278,7 @@ def test_ordered_item_change_quantity(transactional_db, order_with_items):change_order_line_quantity(items[2], 0)history = list(order_with_items.history.all())assert len(history) == 1- assert history[0].status == 'cancelled'+ assert history[0].status == OrderStatus.CANCELLEDassert history[0].comment == 'Order cancelled. No items in order'@@ -288,7 +289,7 @@ def test_ordered_item_remove_empty_group_with_force(OrderLine.objects.remove_empty_groups(items[0], force=True)history = list(order_with_items.history.all())assert len(history) == 1- assert history[0].status == 'cancelled'+ assert history[0].status == OrderStatus.CANCELLEDassert history[0].comment == 'Order cancelled. No items in order'