Commit c43a83e6 authored by Patrick's avatar Patrick

Manual change of "is into offer" need to be disabled if the customer order

quantity of a product is limited by the stock. In this case, the stock
determines if the product is into offer, not a manual change of the switch.
parent c42741aa
......@@ -145,6 +145,9 @@ class Product(TranslatableModel):
def get_is_into_offer(self):
from django.contrib.admin.templatetags.admin_list import _boolean_icon
if self.limit_order_quantity_to_stock:
link = _boolean_icon(self.is_into_offer)
else:
switch_is_into_offer = urlresolvers.reverse(
'is_into_offer', args=(self.id,)
)
......@@ -167,7 +170,7 @@ class Product(TranslatableModel):
link = '<a id="is_into_offer_%d" href="#" onclick="%s" class="btn">%s</a>' % (
self.id,
javascript,
_boolean_icon(self.is_into_offer==True)
_boolean_icon(self.is_into_offer)
)
return link
......
......@@ -10,7 +10,7 @@ from repanier.tools import cap
def flip_flop_is_into_offer(queryset):
for product in queryset.order_by('?'):
if product.is_active:
if product.is_active and not product.limit_order_quantity_to_stock:
product.is_into_offer = not product.is_into_offer
product.save(update_fields=['is_into_offer'])
......
......@@ -20,8 +20,13 @@ def is_into_offer(request, product_id):
if request.is_ajax():
user = request.user
if user.is_staff or user.is_superuser:
is_into_offer = not(Product.objects.filter(id=product_id).order_by('?').only(
'is_into_offer').first().is_into_offer)
Product.objects.filter(id=product_id).update(is_into_offer=is_into_offer)
return HttpResponse(mark_safe(_boolean_icon(is_into_offer)))
product = Product.objects.filter(id=product_id).order_by('?').only(
'is_into_offer', 'limit_order_quantity_to_stock').first()
if product is not None:
if product.limit_order_quantity_to_stock:
new_is_into_offer = product.is_into_offer
else:
new_is_into_offer = not product.is_into_offer
Product.objects.filter(id=product_id).update(is_into_offer=new_is_into_offer)
return HttpResponse(mark_safe(_boolean_icon(new_is_into_offer)))
raise Http404
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment