Skip to content

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

Make sure empty string si not being added to order notes

akjanik20294464a684
diff --git a/saleor/checkout/core.py b/saleor/checkout/core.py
index 6029eb4b1e..0e51ca7a50 100644
--- a/saleor/checkout/core.py
+++ b/saleor/checkout/core.py
@@ -341,7 +341,7 @@ class Checkout:
if voucher is not None:
increase_voucher_usage(voucher)
- if self.note is not None:
+ if self.note is not None and self.note:
order.notes.create(user=order.user, content=self.note)
return order
diff --git a/saleor/checkout/forms.py b/saleor/checkout/forms.py
index 7fae10f3b1..beb892ce0f 100644
--- a/saleor/checkout/forms.py
+++ b/saleor/checkout/forms.py
@@ -118,7 +118,7 @@ class AnonymousUserBillingForm(forms.Form):
class NoteForm(forms.Form):
""" Form to add a note to an order as it is
created for shop staff to see """
- note = forms.CharField(max_length=250, required=False)
+ note = forms.CharField(max_length=250, required=False, strip=True)
def __init__(self, *args, **kwargs):
self.checkout = kwargs.pop('checkout', None)
diff --git a/tests/test_checkout.py b/tests/test_checkout.py
index 10ab70bace..7c63e69573 100644
--- a/tests/test_checkout.py
+++ b/tests/test_checkout.py
@@ -229,6 +229,22 @@ def test_checkout_create_order_insufficient_stock(
def test_note_form():
+ checkout = Checkout(Mock(), AnonymousUser(), 'tracking_code')
+ form = NoteForm({'note': ''}, checkout=checkout)
+ form.is_valid()
+ form.set_checkout_note()
+ assert checkout.note == ''
+
+ form = NoteForm({'note': ' '}, checkout=checkout)
+ form.is_valid()
+ form.set_checkout_note()
+ assert checkout.note == ''
+
+ form = NoteForm({'note': ' test_note '}, checkout=checkout)
+ form.is_valid()
+ form.set_checkout_note()
+ assert checkout.note == 'test_note'
+
checkout = Checkout(Mock(), AnonymousUser(), 'tracking_code')
form = NoteForm({'note': 'test_note'}, checkout=checkout)
form.is_valid()