Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Change name to promo code
fowczarek2be99a33767e
diff --git a/saleor/core/utils/promotional_code.py b/saleor/core/utils/promo_code.pysimilarity index 76%rename from saleor/core/utils/promotional_code.pyrename to saleor/core/utils/promo_code.pyindex 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 Voucherfrom ...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.pyindex 4d3321b204..a7cc59194c 100644--- a/saleor/dashboard/discount/forms.py+++ b/saleor/dashboard/discount/forms.py@@ -9,7 +9,7 @@ from mptt.forms import TreeNodeMultipleChoiceFieldfrom ...core.utils.taxes import ZERO_MONEYfrom ...discount import DiscountValueTypefrom ...discount.models import Sale, Voucher-from ...core.utils.promotional_code import generate_promotional_code+from ...core.utils.promo_code import generate_promo_codefrom ...product.models import Category, Productfrom ..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"] = initialsuper().__init__(*args, **kwargs)diff --git a/saleor/graphql/discount/mutations.py b/saleor/graphql/discount/mutations.pyindex 0317b92a4b..9d56407a88 100644--- a/saleor/graphql/discount/mutations.py+++ b/saleor/graphql/discount/mutations.py@@ -1,10 +1,7 @@import graphenefrom 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_codefrom ...discount import modelsfrom ..core.mutations import BaseMutation, ModelDeleteMutation, ModelMutationfrom ..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_inputdiff --git a/saleor/graphql/giftcard/mutations.py b/saleor/graphql/giftcard/mutations.pyindex ed1e03f541..9332bfea14 100644--- a/saleor/graphql/giftcard/mutations.py+++ b/saleor/graphql/giftcard/mutations.py@@ -4,10 +4,7 @@ import graphenefrom django.core.exceptions import ObjectDoesNotExist, ValidationErrorfrom ...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_codefrom ...giftcard import modelsfrom ..core.mutations import BaseMutation, ModelMutationfrom ..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)