Repository: shuup/shuup

Issue:
Admin: Product delete returns 404



Discussion:

Resolving patch:
diff --git a/shuup/admin/modules/products/views/delete.py b/shuup/admin/modules/products/views/delete.py
--- a/shuup/admin/modules/products/views/delete.py
+++ b/shuup/admin/modules/products/views/delete.py
@@ -15,18 +15,19 @@
 from django.views.generic import DetailView
 
 from shuup.admin.utils.urls import get_model_url
-from shuup.core.models import Product
+from shuup.core.models import ShopProduct
 
 
 class ProductDeleteView(DetailView):
-    model = Product
+    model = ShopProduct
     context_object_name = "product"
 
     def get(self, request, *args, **kwargs):
-        return HttpResponseRedirect(get_model_url(self.get_object(), shop=self.request.shop))
+        product = self.get_object().product
+        return HttpResponseRedirect(get_model_url(product, shop=self.request.shop))
 
     def post(self, request, *args, **kwargs):
-        product = self.get_object()
+        product = self.get_object().product
         product.soft_delete(user=request.user)
         messages.success(request, _(u"%s has been marked deleted.") % product)
         return HttpResponseRedirect(reverse("shuup_admin:shop_product.list"))


Test patch:
diff --git a/shuup_tests/admin/test_product_module.py b/shuup_tests/admin/test_product_module.py
--- a/shuup_tests/admin/test_product_module.py
+++ b/shuup_tests/admin/test_product_module.py
@@ -14,7 +14,7 @@
 from shuup.admin.modules.product_types import ProductTypeModule
 from shuup.admin.modules.products import ProductModule
 from shuup.admin.modules.products.views import (
-    ProductEditView, ProductMediaBulkAdderView
+    ProductEditView, ProductMediaBulkAdderView, ProductDeleteView
 )
 from shuup.admin.modules.services import (
     PaymentMethodModule, ShippingMethodModule
@@ -22,7 +22,7 @@
 from shuup.admin.shop_provider import get_shop
 from shuup.admin.utils.urls import get_model_url
 from shuup.admin.views.search import get_search_results
-from shuup.core.models import ProductMedia, ProductMediaKind, ProductVisibility
+from shuup.core.models import ProductMedia, ProductMediaKind, ProductVisibility, ShopProduct
 from shuup.importer.admin_module import ImportAdminModule
 from shuup.testing.factories import (
     create_product, get_default_product, get_default_shop
@@ -83,6 +83,19 @@ def test_product_edit_view_with_params(rf, admin_user):
             assert (sku in response.rendered_content)  # it's probable the SKU is there
             assert (name in response.rendered_content)  # it's probable the name is there
 
+@pytest.mark.django_db
+def test_product_delete_view(rf, admin_user):
+    shop = get_default_shop()
+    prod = create_product("prod")
+    shop_product = ShopProduct.objects.create(product=prod, shop=shop)
+    shop_product.save()
+    assert shop_product.pk != shop_product.product.pk
+    request = apply_request_middleware(rf.post("/"), user=admin_user, shop=shop)
+    view_func = ProductDeleteView.as_view()
+    response = view_func(request, pk=shop_product.pk)
+    prod.refresh_from_db()
+    assert prod.deleted
+
 @pytest.mark.django_db
 def test_product_media_bulk_adder(rf, admin_user):
     shop = get_default_shop()