Skip to content

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

Enable order edition only if draft

Anna Siwik4a783e40dd36
diff --git a/saleor/dashboard/order/views.py b/saleor/dashboard/order/views.py
index a602769429..1207d29645 100644
--- a/saleor/dashboard/order/views.py
+++ b/saleor/dashboard/order/views.py
@@ -98,7 +98,7 @@ def order_details(request, order_pk):
if payment:
can_capture = (
payment.status == PaymentStatus.PREAUTH and
- order.status != OrderStatus.CANCELED)
+ order.status not in {OrderStatus.DRAFT, OrderStatus.CANCELED})
can_release = payment.status == PaymentStatus.PREAUTH
can_refund = payment.status == PaymentStatus.CONFIRMED
preauthorized = payment.get_total_price()
diff --git a/saleor/order/models.py b/saleor/order/models.py
index b06cc76ede..0e6e2b4149 100644
--- a/saleor/order/models.py
+++ b/saleor/order/models.py
@@ -143,10 +143,10 @@ class Order(models.Model):
def get_total_quantity(self):
return sum([line.quantity for line in self])
- def can_edit(self):
+ def is_draft(self):
return self.status == OrderStatus.DRAFT
- def can_fulfill(self):
+ def is_open(self):
statuses = {OrderStatus.UNFULFILLED, OrderStatus.PARTIALLY_FULFILLED}
return self.status in statuses
diff --git a/templates/dashboard/order/detail.html b/templates/dashboard/order/detail.html
index 336e9c08e5..984f31416a 100644
--- a/templates/dashboard/order/detail.html
+++ b/templates/dashboard/order/detail.html
@@ -279,7 +279,7 @@
{{ line.unit_price.gross|amount:'html' }}
</td>
<td class="right-align">
- {% if order.can_edit %}
+ {% if order.is_draft %}
<a class="dropdown-button" href="#" data-activates="line-actions-{{ line.pk }}" data-constrainwidth="false">
{{ line.quantity }} {% if line.stock_location and is_many_stock_locations %} ({{ line.stock_location|truncatechars:10 }}) {% endif %}
<svg data-src="{% static "dashboard/images/arrow-drop-down.svg" %}" width="24" height="24" />
@@ -316,12 +316,16 @@
<td class="right-align" colspan="3">
<p>{% trans "Subtotal" context "Order subtotal" %}</p>
<p>{% trans "Shipping" context "Order totals header" %} ({{ order.shipping_method_name|default:"-" }})</p>
- {% if order.discount_amount %}
+ {% if order.is_draft or order.discount_amount %}
<p>
<a class="dropdown-button" href="#" data-activates="voucher-actions" data-constrainwidth="false">
- {% blocktrans trimmed with voucher=order.discount_name context "Order totals header" %}
- Voucher {{ voucher }}
- {% endblocktrans %}
+ {% if order.discount_name %}
+ {% blocktrans trimmed with voucher=order.discount_name context "Order totals header" %}
+ Discount ({{ voucher }})
+ {% endblocktrans %}
+ {% else %}
+ {% trans "Discount" context "Order totals header" %}
+ {% endif %}
<svg data-src="{% static "dashboard/images/arrow-drop-down.svg" %}" />
</a>
</p>
@@ -348,22 +352,24 @@
</tbody>
</table>
</div>
- {% if perms.order.edit_order and order.can_edit or order.can_fulfill %}
- <div class="data-table-action">
- {% if order.can_fulfill %}
- <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>
- {% endif %}
- {% if order.can_edit %}
- <a href="#base-modal" data-href="{% url 'dashboard:add-variant-to-order' order_pk=order.pk %}" class="btn-flat waves-effect modal-trigger-custom" title="{% trans "Add product to order" context "Order summary card action title" %}">
- {% trans "Add product" context "Order summary card action" %}
- </a>
- <a href="#base-modal" data-href="{% url 'dashboard:draft-order-confirm' order_pk=order.pk %}" class="btn-flat waves-effect modal-trigger-custom" title="{% trans "Confirm order" context "Order summary card action title" %}">
- {% trans "Confirm" context "Order summary card action" %}
- </a>
- {% endif %}
- </div>
+ {% if perms.order.edit_order %}
+ {% if order.is_draft or order.is_open %}
+ <div class="data-table-action">
+ {% if order.is_open %}
+ <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>
+ {% endif %}
+ {% if order.is_draft %}
+ <a href="#base-modal" data-href="{% url 'dashboard:add-variant-to-order' order_pk=order.pk %}" class="btn-flat waves-effect modal-trigger-custom" title="{% trans "Add product to order" context "Order summary card action title" %}">
+ {% trans "Add product" context "Order summary card action" %}
+ </a>
+ <a href="#base-modal" data-href="{% url 'dashboard:draft-order-confirm' order_pk=order.pk %}" class="btn-flat waves-effect modal-trigger-custom" title="{% trans "Confirm order" context "Order summary card action title" %}">
+ {% trans "Confirm" context "Order summary card action" %}
+ </a>
+ {% endif %}
+ </div>
+ {% endif %}
{% endif %}
</div>
{% for fulfillment in order.fulfillments.all %}
diff --git a/templates/order/details.html b/templates/order/details.html
index 11d57ee974..372acf5cc4 100644
--- a/templates/order/details.html
+++ b/templates/order/details.html
@@ -91,7 +91,7 @@
<p>{{ note.content }}</p>
{% endfor %}
{% endif %}
- {% if order.can_edit %}
+ {% if order.is_open %}
<form method="post" class="form-group">
{% csrf_token %}
{% bootstrap_form note_form display_labels=False %}