Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Fix vouchers and improve checkout
Patryk Zawadzki0e91951e21a4
diff --git a/saleor/checkout/templates/checkout/details.html b/saleor/checkout/templates/checkout/details.htmlindex 898d58081e..797989ba1b 100644--- a/saleor/checkout/templates/checkout/details.html+++ b/saleor/checkout/templates/checkout/details.html@@ -73,6 +73,27 @@{% endfor %}{% endfor %}+ <tr>+ <td>+ {% trans "Subtotal" %}+ </td>+ <td class="text-right">+ {% net checkout.get_subtotal %}+ </td>+ </tr>+ <tr>+ <td>+ {% trans "Shipping" %}+ </td>+ <td class="text-right">+ {% if checkout.shipping_method %}+ {% net checkout.get_total_shipping %}+ {% else %}+ —+ {% endif %}+ </td>+ </tr>+{% if voucher_form %}<tr>{% if voucher %}@@ -104,26 +125,6 @@{% endif %}{% with total=checkout.get_total %}- <tr>- <td>- {% trans "Subtotal" %}- </td>- <td class="text-right">- {% net checkout.get_subtotal %}- </td>- </tr>- <tr>- <td>- {% trans "Shipping" %}- </td>- <td class="text-right">- {% if checkout.shipping_method %}- {% net checkout.get_total_shipping %}- {% else %}- —- {% endif %}- </td>- </tr>{% if total.tax or True %}<tr><td>diff --git a/saleor/dashboard/discount/forms.py b/saleor/dashboard/discount/forms.pyindex c8649c1158..45572335fe 100644--- a/saleor/dashboard/discount/forms.py+++ b/saleor/dashboard/discount/forms.py@@ -28,14 +28,6 @@ class SaleForm(forms.ModelForm):class VoucherForm(forms.ModelForm):- ALL_PURCHASES = 'all_purchases'- DISCOUNT_TYPES = (- (ALL_PURCHASES, pgettext_lazy('voucher', 'All purchases')),- ) + Voucher.TYPE_CHOICES- type = forms.ChoiceField(- choices=DISCOUNT_TYPES, initial=ALL_PURCHASES,- label=pgettext_lazy('voucher', 'Discount for'))-class Meta:model = Voucherexclude = ['limit', 'apply_to', 'product', 'category']@@ -43,9 +35,6 @@ class VoucherForm(forms.ModelForm):def __init__(self, *args, **kwargs):initial = kwargs.get('initial', {})instance = kwargs.get('instance')- if (instance and instance.type == Voucher.VALUE_TYPE and- instance.limit is None):- initial['type'] = VoucherForm.ALL_PURCHASESif instance and instance.id is None and not initial.get('code'):initial['code'] = self._generate_codekwargs['initial'] = initial@@ -57,12 +46,6 @@ class VoucherForm(forms.ModelForm):if not Voucher.objects.filter(code=code).exists():return code- def clean(self):- cleaned_data = super(VoucherForm, self).clean()- if cleaned_data['type'] == VoucherForm.ALL_PURCHASES:- cleaned_data['type'] = Voucher.VALUE_TYPE- return cleaned_data-def country_choices():country_codes = ShippingMethodCountry.objects.all()@@ -96,9 +79,9 @@ class ShippingVoucherForm(forms.ModelForm):class ValueVoucherForm(forms.ModelForm):limit = PriceField(- min_value=0, required=True, currency=settings.DEFAULT_CURRENCY,+ min_value=0, required=False, currency=settings.DEFAULT_CURRENCY,label=pgettext_lazy(- 'voucher', 'Purchase value greater than or equal to'))+ 'voucher', 'Only if purchase value is greater than or equal to'))class Meta:model = Voucher@@ -106,7 +89,7 @@ class ValueVoucherForm(forms.ModelForm):def save(self, commit=True):self.instance.category = None- self.instance.limit = None+ self.instance.apply_to = Noneself.instance.product = Nonereturn super(ValueVoucherForm, self).save(commit)diff --git a/saleor/dashboard/discount/views.py b/saleor/dashboard/discount/views.pyindex e6948bf22f..3d9acd817e 100644--- a/saleor/dashboard/discount/views.py+++ b/saleor/dashboard/discount/views.py@@ -73,8 +73,7 @@ def voucher_edit(request, pk=None):prefix=Voucher.PRODUCT_TYPE),Voucher.CATEGORY_TYPE: forms.CategoryVoucherForm(request.POST or None, instance=instance,- prefix=Voucher.CATEGORY_TYPE),- }+ prefix=Voucher.CATEGORY_TYPE)}if voucher_form.is_valid():voucher_type = voucher_form.cleaned_data['type']form_type = type_base_forms.get(voucher_type)diff --git a/saleor/discount/models.py b/saleor/discount/models.pyindex 4dd7b0accb..c97e7e3544 100644--- a/saleor/discount/models.py+++ b/saleor/discount/models.py@@ -41,12 +41,14 @@ class Voucher(models.Model):VALUE_TYPE = 'value'TYPE_CHOICES = (+ (VALUE_TYPE, pgettext_lazy('voucher', 'All purchases')),(PRODUCT_TYPE, pgettext_lazy('voucher', 'One product')),- (CATEGORY_TYPE, pgettext_lazy('voucherl', 'Category of products')),- (SHIPPING_TYPE, pgettext_lazy('voucher', 'Shipping')),- (VALUE_TYPE, pgettext_lazy('voucher', 'Purchases over certain value')))+ (CATEGORY_TYPE, pgettext_lazy('voucherl', 'A category of products')),+ (SHIPPING_TYPE, pgettext_lazy('voucher', 'Shipping')))- type = models.CharField(max_length=20, choices=TYPE_CHOICES)+ type = models.CharField(+ pgettext_lazy('voucher', 'discount for'), max_length=20,+ choices=TYPE_CHOICES, default=VALUE_TYPE)name = models.CharField(pgettext_lazy('voucher', 'name'), max_length=255, null=True,blank=True)