Commit d307b819 authored by Patrick's avatar Patrick
Browse files

Add the possibility to "unconfirm" an order into the admin

parent 36f12755
......@@ -216,6 +216,7 @@ class PurchaseAdmin(ExportMixin, admin.ModelAdmin):
urls = super(PurchaseAdmin, self).get_urls()
my_urls = [
url(r'^is_order_confirm_send/$', self.is_order_confirm_send),
url(r'^is_order_confirm_not_send/$', self.is_order_confirm_not_send),
]
return my_urls + urls
......@@ -264,6 +265,40 @@ class PurchaseAdmin(ExportMixin, admin.ModelAdmin):
self.message_user(request, user_message, user_message_level)
return HttpResponseRedirect(redirect_to)
def is_order_confirm_not_send(self, request):
permanence_id = request.GET.get('permanence', None)
customer_id = request.GET.get('customer', None)
user_message_level = messages.ERROR
user_message = _("Action canceled by the system.")
if permanence_id is not None and customer_id is not None:
customer = Customer.objects.filter(id=customer_id).order_by('?').first()
permanence = Permanence.objects.filter(id=permanence_id).order_by('?').first()
if permanence is not None and customer is not None:
customer_invoice = CustomerInvoice.objects.filter(
customer_id=customer_id,
permanence_id=permanence_id,
).order_by('?').first()
if customer_invoice is not None \
and customer_invoice.status == PERMANENCE_OPENED \
and customer_invoice.is_order_confirm_send:
user_message_level = messages.INFO
user_message = _('Order not confirmed')
customer_invoice.is_order_confirm_send = False
customer_invoice.save(update_fields=['is_order_confirm_send'])
else:
user_message_level = messages.INFO
user_message = _('Nothing to unconfirm')
redirect_to = "%s?permanence=%s&customer=%s" % (
urlresolvers.reverse('admin:repanier_purchase_changelist', ), permanence_id, customer_id)
elif permanence_id is not None:
redirect_to = "%s?permanence=%s" % (
urlresolvers.reverse('admin:repanier_purchase_changelist', ), permanence_id)
else:
redirect_to = urlresolvers.reverse('admin:repanier_purchase_changelist', )
self.message_user(request, user_message, user_message_level)
return HttpResponseRedirect(redirect_to)
def get_fieldsets(self, request, purchase=None):
permanence_id = None
preserved_filters = request.GET.get('_changelist_filters', None)
......
(function($) {
$(document).ready(function($) {
if(location.pathname.indexOf('change') <= -1) {
$(".object-tools").append('<li><a href="./is_order_confirm_send/' + location.search + '">&nbsp;&nbsp;🔐&nbsp;&nbsp;</a></li>');
$(".object-tools").append('<li><a href="./is_order_confirm_not_send/' + location.search + '">&nbsp;&nbsp;✗🔓&nbsp;&nbsp;</a></li>');
$(".object-tools").append('<li><a href="./is_order_confirm_send/' + location.search + '">&nbsp;&nbsp;✓🔐&nbsp;&nbsp;</a></li>');
}
// $(".object-tools").append('<li><a href="./is_order_confirm_send/' + location.search + '" class="addlink">&nbsp;&nbsp;🔐&nbsp;&nbsp;</a></li>');
});
......
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