Skip to content

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

Change name to promo code

fowczarek2be99a33767e
diff --git a/saleor/core/utils/promotional_code.py b/saleor/core/utils/promo_code.py
similarity index 76%
rename from saleor/core/utils/promotional_code.py
rename to saleor/core/utils/promo_code.py
index 5dd69edfa1..a941f9015f 100644
--- a/saleor/core/utils/promotional_code.py
+++ b/saleor/core/utils/promo_code.py
@@ -4,15 +4,15 @@ from ...discount.models import Voucher
from ...giftcard.models import GiftCard
-def generate_promotional_code(length=12):
+def generate_promo_code(length=12):
"""Generate new unique gift card code."""
code = str(uuid.uuid4()).replace("-", "").upper()[:length]
- while not is_avaible_promotional_code(code):
+ while not is_avaible_promo_code(code):
code = str(uuid.uuid4()).replace("-", "").upper()[:length]
return code
-def is_avaible_promotional_code(code):
+def is_avaible_promo_code(code):
return not (
GiftCard.objects.filter(code=code).exists()
or Voucher.objects.filter(code=code).exists()
diff --git a/saleor/dashboard/discount/forms.py b/saleor/dashboard/discount/forms.py
index 4d3321b204..a7cc59194c 100644
--- a/saleor/dashboard/discount/forms.py
+++ b/saleor/dashboard/discount/forms.py
@@ -9,7 +9,7 @@ from mptt.forms import TreeNodeMultipleChoiceField
from ...core.utils.taxes import ZERO_MONEY
from ...discount import DiscountValueType
from ...discount.models import Sale, Voucher
-from ...core.utils.promotional_code import generate_promotional_code
+from ...core.utils.promo_code import generate_promo_code
from ...product.models import Category, Product
from ..forms import AjaxSelect2MultipleChoiceField
@@ -107,7 +107,7 @@ class VoucherForm(forms.ModelForm):
initial = kwargs.get("initial", {})
instance = kwargs.get("instance")
if instance and instance.id is None and not initial.get("code"):
- initial["code"] = generate_promotional_code()
+ initial["code"] = generate_promo_code()
kwargs["initial"] = initial
super().__init__(*args, **kwargs)
diff --git a/saleor/graphql/discount/mutations.py b/saleor/graphql/discount/mutations.py
index 0317b92a4b..9d56407a88 100644
--- a/saleor/graphql/discount/mutations.py
+++ b/saleor/graphql/discount/mutations.py
@@ -1,10 +1,7 @@
import graphene
from django.core.exceptions import ObjectDoesNotExist, ValidationError
-from ...core.utils.promotional_code import (
- generate_promotional_code,
- is_avaible_promotional_code,
-)
+from ...core.utils.promo_code import generate_promo_code, is_avaible_promo_code
from ...discount import models
from ..core.mutations import BaseMutation, ModelDeleteMutation, ModelMutation
from ..core.scalars import Decimal
@@ -117,8 +114,8 @@ class VoucherCreate(ModelMutation):
def clean_input(cls, info, instance, data):
code = data.get("code", None)
if code == "":
- data["code"] = generate_promotional_code()
- elif not is_avaible_promotional_code(code):
+ data["code"] = generate_promo_code()
+ elif not is_avaible_promo_code(code):
raise ValidationError({"code": "Voucher with this code is not avaible."})
cleaned_input = super().clean_input(info, instance, data)
return cleaned_input
diff --git a/saleor/graphql/giftcard/mutations.py b/saleor/graphql/giftcard/mutations.py
index ed1e03f541..9332bfea14 100644
--- a/saleor/graphql/giftcard/mutations.py
+++ b/saleor/graphql/giftcard/mutations.py
@@ -4,10 +4,7 @@ import graphene
from django.core.exceptions import ObjectDoesNotExist, ValidationError
from ...account.models import User
-from ...core.utils.promotional_code import (
- generate_promotional_code,
- is_avaible_promotional_code,
-)
+from ...core.utils.promo_code import generate_promo_code, is_avaible_promo_code
from ...giftcard import models
from ..core.mutations import BaseMutation, ModelMutation
from ..core.scalars import Decimal
@@ -43,8 +40,8 @@ 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_promotional_code(16)
- elif not is_avaible_promotional_code(code):
+ data["code"] = generate_promo_code(16)
+ elif not is_avaible_promo_code(code):
raise ValidationError({"code": "Gift card with this code is not avaible."})
cleaned_input = super().clean_input(info, instance, data)
balance = cleaned_input.get("balance", None)