Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Remove apply to one case with percentage discount
Michał Ociepka6bef0bd0d1ad
diff --git a/saleor/dashboard/discount/forms.py b/saleor/dashboard/discount/forms.pyindex ff7ac240aa..ace509e574 100644--- a/saleor/dashboard/discount/forms.py+++ b/saleor/dashboard/discount/forms.py@@ -111,6 +111,13 @@ class ProductVoucherForm(forms.ModelForm):def save(self, commit=True):self.instance.category = Noneself.instance.limit = None+ # Apply to one with percentage discount is more complicated case.+ # On which product we should apply it? On first, last or cheapest?+ # Percentage case is limited to the all value and the apply_to field+ # is not used in this case so we set it to None.+ if (self.instance.discount_value_type+ == Voucher.DISCOUNT_VALUE_PERCENTAGE):+ self.instance.apply_to = Nonereturn super(ProductVoucherForm, self).save(commit)@@ -130,4 +137,11 @@ class CategoryVoucherForm(forms.ModelForm):def save(self, commit=True):self.instance.limit = Noneself.instance.product = None+ # Apply to one with percentage discount is more complicated case.+ # On which product we should apply it? On first, last or cheapest?+ # Percentage case is limited to the all value and the apply_to field+ # is not used in this case so we set it to None.+ if (self.instance.discount_value_type+ == Voucher.DISCOUNT_VALUE_PERCENTAGE):+ self.instance.apply_to = Nonereturn super(CategoryVoucherForm, self).save(commit)diff --git a/saleor/static/js_src/dashboard.jsx b/saleor/static/js_src/dashboard.jsxindex 25f8a7c7bf..cdfb3b911b 100644--- a/saleor/static/js_src/dashboard.jsx+++ b/saleor/static/js_src/dashboard.jsx@@ -188,14 +188,24 @@ $(document).ready(() => {if ($voucherTypeInput.length) {let $discountValueType = $('[name="discount_value_type"]');let $voucherForms = $('.voucher-form');- $voucherTypeInput.on('change', () => {+ let $applyToProduct = $('[name="product-apply_to"]').parents('.input');+ let $applyToCategory = $('[name="category-apply_to"]').parents('.input');+ let onChange = () => {+ let discountValueType = $discountValueType.val();let type = $voucherTypeInput.val();+ let hide = discountValueType === 'percentage';+ $applyToProduct.toggleClass('hide', hide);+ $applyToCategory.toggleClass('hide', hide);+$voucherForms.each((index, form) => {let $form = $(form);let hideForm = $form.data('type') !== type;$form.toggleClass('hide', hideForm);});- });+ };++ $discountValueType.on('change', onChange);+ $voucherTypeInput.on('change', onChange);$voucherTypeInput.trigger('change');}});