Skip to content

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

Remove length argument form generate promo code

fowczarek8bc4ade52126
diff --git a/saleor/checkout/utils.py b/saleor/checkout/utils.py
index bfbf515639..c6c353c88b 100644
--- a/saleor/checkout/utils.py
+++ b/saleor/checkout/utils.py
@@ -795,7 +795,7 @@ def add_promo_code_to_checkout(checkout: Checkout, promo_code: str):
elif promo_code_is_gift_card(promo_code):
add_gift_card_code_to_checkout(checkout, promo_code)
else:
- raise ValidationError({"promo_code": "Promo code does not exists."})
+ raise ValidationError({"promo_code": "Promo code does not exist."})
def add_voucher_code_to_checkout(checkout: Checkout, voucher_code: str):
@@ -968,7 +968,7 @@ def validate_gift_cards(checkout: Checkout):
):
msg = pgettext(
"Gift card not applicable",
- "Gift card expired in meantime. Order placement aborted.",
+ "Gift card has expired. Order placement cancelled.",
)
raise NotApplicable(msg)
diff --git a/saleor/core/utils/promo_code.py b/saleor/core/utils/promo_code.py
index d3e1df8ab0..a595de5437 100644
--- a/saleor/core/utils/promo_code.py
+++ b/saleor/core/utils/promo_code.py
@@ -4,11 +4,11 @@ from ...discount.models import Voucher
from ...giftcard.models import GiftCard
-def generate_promo_code(length=12):
- """Generate new unique gift card code."""
- code = str(uuid.uuid4()).replace("-", "").upper()[:length]
+def generate_promo_code():
+ """Generate a promo unique code that can be used as a voucher or gift card code."""
+ code = str(uuid.uuid4()).replace("-", "").upper()[:12]
while not is_available_promo_code(code):
- code = str(uuid.uuid4()).replace("-", "").upper()[:length]
+ code = str(uuid.uuid4()).replace("-", "").upper()[:12]
return code
diff --git a/saleor/graphql/giftcard/mutations.py b/saleor/graphql/giftcard/mutations.py
index 42d579dcce..30c466cff7 100644
--- a/saleor/graphql/giftcard/mutations.py
+++ b/saleor/graphql/giftcard/mutations.py
@@ -44,7 +44,7 @@ class GiftCardCreate(ModelMutation):
def clean_input(cls, info, instance, data):
code = data.get("code", None)
if not code and not instance.pk:
- data["code"] = generate_promo_code(16)
+ data["code"] = generate_promo_code()
elif not is_available_promo_code(code):
raise ValidationError(
{"code": "Gift card with this code is not available."}