Chris Moffitt committed 5d01ced

Fix for #1392. Restrict cascading deletes when using variation manager.

Comments (0)

Files changed (4)


 Bug Fixes
+ * Make variation manager more robust so that you can't delete an order when deleting the variation.
 Performance Improvements
 Additional Packages
 Migration Notes


     def _delete_variation(self, opts, request):
         variation = self.product.configurableproduct.get_product_from_options(opts)
         if variation:
+            variation.delete()
   "Deleting variation for [%s] %s", self.product.slug, opts)
             messages.add_message(request, messages.INFO, 'Deleted %s' % variation)
-            variation.delete()
 def _get_optiondict():
     site = Site.objects.get_current()


 from django.contrib.auth.decorators import user_passes_test
+from django.contrib import messages
 from django.core import urlresolvers
 from django.http import HttpResponseRedirect
 from django.shortcuts import render_to_response
 from django.template import RequestContext
 from django.utils.translation import ugettext as _
+from django.db import IntegrityError
 from product.forms import VariationManagerForm, InventoryForm, ProductExportForm, ProductImportForm
 from product.models import Product
 from product.modules.configurable.models import ConfigurableProduct
         form = VariationManagerForm(new_data, product=product)
         if form.is_valid():
             log.debug("Saving form")
+            try:
+            except IntegrityError:
+                messages.error(request, _('The product you are attempting to remove is linked to an order and can not be removed.'))
             # rebuild the form
             form = VariationManagerForm(product=product)


     A line item on an order.
     order = models.ForeignKey(Order, verbose_name=_("Order"))
-    product = models.ForeignKey(Product, verbose_name=_("Product"))
+    product = models.ForeignKey(Product, verbose_name=_("Product"), on_delete=models.PROTECT)
     quantity = models.DecimalField(_("Quantity"),  max_digits=18,  decimal_places=6)
     unit_price = CurrencyField(_("Unit price"),
         max_digits=18, decimal_places=10)