Skip to content

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

More flexibility in creating orders from dashboard

Anna Siwikf39c038ab748
diff --git a/saleor/dashboard/order/forms.py b/saleor/dashboard/order/forms.py
index cbbd2cdaec..2cb818529b 100644
--- a/saleor/dashboard/order/forms.py
+++ b/saleor/dashboard/order/forms.py
@@ -50,18 +50,18 @@ class ConfirmDraftOrderForm(forms.ModelForm):
super().__init__(*args, **kwargs)
self.discount_amount = get_voucher_discount_for_order(self.instance)
if self.instance.discount_amount != self.discount_amount:
+ zero = Money(0, settings.DEFAULT_CURRENCY)
self.fields['reapply_voucher'].label = pgettext_lazy(
'Recalculate discount amount on draft order confirmation',
'Update discount amount from %(old_amount)s '
'to %(new_amount)s') % {
'old_amount': format_money(
- self.instance.discount_amount or
- Money(0, settings.DEFAULT_CURRENCY)),
- 'new_amount': format_money(
- self.discount_amount or
- Money(0, settings.DEFAULT_CURRENCY))}
+ self.instance.discount_amount or zero),
+ 'new_amount': format_money(self.discount_amount or zero)}
else:
self.fields.pop('reapply_voucher')
+ if not self.instance.user and not self.instance.user_email:
+ self.fields.pop('notify_customer')
def clean(self):
super().clean()
@@ -70,19 +70,7 @@ class ConfirmDraftOrderForm(forms.ModelForm):
errors.append(forms.ValidationError(pgettext_lazy(
'Confirm draft order form error',
'Could not confirm order without any products')))
- if not self.instance.billing_address:
- errors.append(forms.ValidationError(pgettext_lazy(
- 'Confirm draft order form error',
- 'Billing address is required to handle payment')))
if self.instance.is_shipping_required():
- if not self.instance.shipping_address:
- errors.append(forms.ValidationError(pgettext_lazy(
- 'Confirm draft order form error',
- 'Shipping address is required to handle shipping')))
- if not self.instance.shipping_method_name:
- errors.append(forms.ValidationError(pgettext_lazy(
- 'Confirm draft order form error',
- 'Shipping method is required to handle shipping')))
method = self.instance.shipping_method
shipping_address = self.instance.shipping_address
if (
diff --git a/saleor/order/utils.py b/saleor/order/utils.py
index 6790b6ee34..d5b172c96e 100644
--- a/saleor/order/utils.py
+++ b/saleor/order/utils.py
@@ -1,7 +1,9 @@
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 prices import Money
from ..account.utils import store_user_address
from ..core.exceptions import InsufficientStock
@@ -39,7 +41,8 @@ def recalculate_order(order, discount_amount=None):
total = sum(prices, order.shipping_price)
# discount amount can't be greater than order total
order.discount_amount = min(
- discount_amount or order.discount_amount, total.gross)
+ discount_amount or order.discount_amount or
+ Money(0, settings.DEFAULT_CURRENCY), total.gross)
if order.discount_amount:
total -= order.discount_amount
order.total = total
diff --git a/templates/dashboard/order/modal/confirm_order.html b/templates/dashboard/order/modal/confirm_order.html
index b00be1e869..4b2887696d 100644
--- a/templates/dashboard/order/modal/confirm_order.html
+++ b/templates/dashboard/order/modal/confirm_order.html
@@ -16,7 +16,9 @@
{% blocktrans trimmed with order=order context "Modal confirm order text" %}
Are you sure you want confirm order {{ order }}? Once the order has been confirmed, you will not be able to make changes.
{% endblocktrans %}
- {{ form.notify_customer|materializecss }}
+ {% if form.notify_customer %}
+ {{ form.notify_customer|materializecss }}
+ {% endif %}
{% if form.reapply_voucher %}
{{ form.reapply_voucher|materializecss }}
{% endif %}
diff --git a/tests/dashboard/test_order.py b/tests/dashboard/test_order.py
index 1cd9c982b4..fd31ab808a 100644
--- a/tests/dashboard/test_order.py
+++ b/tests/dashboard/test_order.py
@@ -899,41 +899,6 @@ def test_view_confirm_draft_order_not_draft_order(
assert response.status_code == 404
-def test_view_confirm_draft_order_no_billing_address(
- admin_client, draft_order):
- draft_order.billing_address.delete()
- url = reverse(
- 'dashboard:draft-order-confirm', kwargs={'order_pk': draft_order.pk})
- data = {'csrfmiddlewaretoken': 'hello'}
-
- response = admin_client.post(url, data)
-
- assert response.status_code == 400
- draft_order.refresh_from_db()
- assert draft_order.status == OrderStatus.DRAFT
- errors = get_form_errors(response)
- assert 'Billing address is required to handle payment' in errors
-
-
-def test_view_confirm_draft_order_no_shipping_address(
- admin_client, draft_order):
- draft_order.shipping_address = None
- draft_order.save()
- url = reverse(
- 'dashboard:draft-order-confirm', kwargs={'order_pk': draft_order.pk})
- data = {'csrfmiddlewaretoken': 'hello'}
-
- response = admin_client.post(url, data)
-
- assert response.status_code == 400
- draft_order.refresh_from_db()
- assert draft_order.status == OrderStatus.DRAFT
- errors = get_form_errors(response)
- assert 'Shipping address is required to handle shipping' in errors
-
-
@pytest.mark.django_db
def test_view_confirm_draft_order_shipping_method_not_valid(
admin_client, draft_order, shipping_method):