Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Add specific products form to old dashboard
fowczarek32e00e524d8a
diff --git a/saleor/dashboard/discount/forms.py b/saleor/dashboard/discount/forms.pyindex 9a879b3ea9..11fef4bd15 100644--- a/saleor/dashboard/discount/forms.py+++ b/saleor/dashboard/discount/forms.py@@ -159,6 +159,38 @@ class CommonVoucherForm(forms.ModelForm):)+class SpecificProductVoucherForm(CommonVoucherForm):+ products = AjaxSelect2MultipleChoiceField(+ queryset=Product.objects.all(),+ fetch_data_url=reverse_lazy("dashboard:ajax-products"),+ required=True,+ label=pgettext_lazy("Product", "Products"),+ )+ categories = TreeNodeMultipleChoiceField(+ queryset=Category.objects.all(),+ required=True,+ label=pgettext_lazy("Categories", "Categories"),+ )++ class Meta:+ model = Voucher+ fields = [+ "products",+ "collections",+ "categories",+ "apply_once_per_order",+ "min_amount_spent",+ ]+ labels = {"collections": pgettext_lazy("Collections", "Collections")}++ def __init__(self, *args, **kwargs):+ super().__init__(*args, **kwargs)+ if self.instance.pk:+ self.fields["products"].set_initial(self.instance.products.all())+ self.fields["categories"].required = False+ self.fields["products"].required = False++class ProductVoucherForm(CommonVoucherForm):products = AjaxSelect2MultipleChoiceField(queryset=Product.objects.all(),diff --git a/saleor/dashboard/discount/views.py b/saleor/dashboard/discount/views.pyindex 181c690722..2ddc653200 100644--- a/saleor/dashboard/discount/views.py+++ b/saleor/dashboard/discount/views.py@@ -25,6 +25,9 @@ def get_voucher_type_forms(voucher, data):VoucherType.ENTIRE_ORDER: forms.ValueVoucherForm(data or None, instance=voucher, prefix=VoucherType.ENTIRE_ORDER),+ VoucherType.SPECIFIC_PRODUCT: forms.SpecificProductVoucherForm(+ data or None, instance=voucher, prefix=VoucherType.SPECIFIC_PRODUCT+ ),VoucherType.PRODUCT: forms.ProductVoucherForm(data or None, instance=voucher, prefix=VoucherType.PRODUCT),