mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Create UI elements to cancel an order
- View - Form - Template - Button - Javascript
This commit is contained in:
parent
6f54091354
commit
fcbf0e6e93
@ -6,6 +6,7 @@ Django Forms for interacting with Order objects
|
|||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from django import forms
|
from django import forms
|
||||||
|
from django.utils.translation import ugettext as _
|
||||||
|
|
||||||
from InvenTree.forms import HelperForm
|
from InvenTree.forms import HelperForm
|
||||||
|
|
||||||
@ -14,7 +15,18 @@ from .models import PurchaseOrder, PurchaseOrderLineItem
|
|||||||
|
|
||||||
class IssuePurchaseOrderForm(HelperForm):
|
class IssuePurchaseOrderForm(HelperForm):
|
||||||
|
|
||||||
confirm = forms.BooleanField(required=False, help_text='Place order')
|
confirm = forms.BooleanField(required=False, help_text=_('Place order'))
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = PurchaseOrder
|
||||||
|
fields = [
|
||||||
|
'confirm',
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
class CancelPurchaseOrderForm(HelperForm):
|
||||||
|
|
||||||
|
confirm = forms.BooleanField(required=False, help_text=_('Cancel order'))
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = PurchaseOrder
|
model = PurchaseOrder
|
||||||
|
@ -98,6 +98,13 @@ class Order(models.Model):
|
|||||||
self.complete_date = datetime.now().date()
|
self.complete_date = datetime.now().date()
|
||||||
self.save()
|
self.save()
|
||||||
|
|
||||||
|
def cancel_order(self):
|
||||||
|
""" Marks the order as CANCELLED. """
|
||||||
|
|
||||||
|
if self.status in [OrderStatus.PLACED, OrderStatus.PENDING]:
|
||||||
|
self.status = OrderStatus.CANCELLED
|
||||||
|
self.save()
|
||||||
|
|
||||||
|
|
||||||
class PurchaseOrder(Order):
|
class PurchaseOrder(Order):
|
||||||
""" A PurchaseOrder represents goods shipped inwards from an external supplier.
|
""" A PurchaseOrder represents goods shipped inwards from an external supplier.
|
||||||
|
7
InvenTree/order/templates/order/order_cancel.html
Normal file
7
InvenTree/order/templates/order/order_cancel.html
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
{% extends "modal_form.html" %}
|
||||||
|
|
||||||
|
{% block pre_form_content %}
|
||||||
|
|
||||||
|
Cancelling this order means that the order will no longer be editable.
|
||||||
|
|
||||||
|
{% endblock %}
|
@ -43,6 +43,11 @@ InvenTree | {{ order }}
|
|||||||
<span class='glyphicon glyphicon-check'></span>
|
<span class='glyphicon glyphicon-check'></span>
|
||||||
</button>
|
</button>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
{% if order.status == OrderStatus.PENDING or order.status == OrderStatus.PLACED %}
|
||||||
|
<button type='button' class='btn btn-default btn-glyph' id='cancel-order' title='Cancel order'>
|
||||||
|
<span class='glyphicon glyphicon-remove'></span>
|
||||||
|
</button>
|
||||||
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</p>
|
</p>
|
||||||
@ -176,6 +181,12 @@ $("#edit-order").click(function() {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$("#cancel-order").click(function() {
|
||||||
|
launchModalForm("{% url 'purchase-order-cancel' order.id %}", {
|
||||||
|
reload: true,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
$("#receive-order").click(function() {
|
$("#receive-order").click(function() {
|
||||||
launchModalForm("{% url 'purchase-order-receive' order.id %}", {
|
launchModalForm("{% url 'purchase-order-receive' order.id %}", {
|
||||||
reload: true,
|
reload: true,
|
||||||
|
@ -11,6 +11,7 @@ from . import views
|
|||||||
|
|
||||||
purchase_order_detail_urls = [
|
purchase_order_detail_urls = [
|
||||||
|
|
||||||
|
url(r'^cancel/?', views.PurchaseOrderCancel.as_view(), name='purchase-order-cancel'),
|
||||||
url(r'^edit/?', views.PurchaseOrderEdit.as_view(), name='purchase-order-edit'),
|
url(r'^edit/?', views.PurchaseOrderEdit.as_view(), name='purchase-order-edit'),
|
||||||
url(r'^issue/?', views.PurchaseOrderIssue.as_view(), name='purchase-order-issue'),
|
url(r'^issue/?', views.PurchaseOrderIssue.as_view(), name='purchase-order-issue'),
|
||||||
url(r'^receive/?', views.PurchaseOrderReceive.as_view(), name='purchase-order-receive'),
|
url(r'^receive/?', views.PurchaseOrderReceive.as_view(), name='purchase-order-receive'),
|
||||||
|
@ -112,6 +112,39 @@ class PurchaseOrderEdit(AjaxUpdateView):
|
|||||||
return form
|
return form
|
||||||
|
|
||||||
|
|
||||||
|
class PurchaseOrderCancel(AjaxUpdateView):
|
||||||
|
""" View for cancelling a purchase order """
|
||||||
|
|
||||||
|
model = PurchaseOrder
|
||||||
|
ajax_form_title = 'Cancel Order'
|
||||||
|
ajax_template_name = 'order/order_cancel.html'
|
||||||
|
form_class = order_forms.CancelPurchaseOrderForm
|
||||||
|
|
||||||
|
def post(self, request, *args, **kwargs):
|
||||||
|
""" Mark the PO as 'CANCELLED' """
|
||||||
|
|
||||||
|
order = self.get_object()
|
||||||
|
form = self.get_form()
|
||||||
|
|
||||||
|
confirm = str2bool(request.POST.get('confirm', False))
|
||||||
|
|
||||||
|
valid = False
|
||||||
|
|
||||||
|
if not confirm:
|
||||||
|
form.errors['confirm'] = [_('Confirm order cancellation')]
|
||||||
|
else:
|
||||||
|
valid = True
|
||||||
|
|
||||||
|
data = {
|
||||||
|
'form_valid': valid
|
||||||
|
}
|
||||||
|
|
||||||
|
if valid:
|
||||||
|
order.cancel_order()
|
||||||
|
|
||||||
|
return self.renderJsonResponse(request, form, data)
|
||||||
|
|
||||||
|
|
||||||
class PurchaseOrderIssue(AjaxUpdateView):
|
class PurchaseOrderIssue(AjaxUpdateView):
|
||||||
""" View for changing a purchase order from 'PENDING' to 'ISSUED' """
|
""" View for changing a purchase order from 'PENDING' to 'ISSUED' """
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user