mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Replace the existing CancelPurchaseOrderForm with an API driven form
This commit is contained in:
parent
e920fc31e7
commit
62cd0f39c7
@ -41,17 +41,6 @@ class CompletePurchaseOrderForm(HelperForm):
|
|||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
class CancelPurchaseOrderForm(HelperForm):
|
|
||||||
|
|
||||||
confirm = forms.BooleanField(required=True, label=_('Confirm'), help_text=_('Cancel order'))
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
model = PurchaseOrder
|
|
||||||
fields = [
|
|
||||||
'confirm',
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
class CancelSalesOrderForm(HelperForm):
|
class CancelSalesOrderForm(HelperForm):
|
||||||
|
|
||||||
confirm = forms.BooleanField(required=True, label=_('Confirm'), help_text=_('Cancel order'))
|
confirm = forms.BooleanField(required=True, label=_('Confirm'), help_text=_('Cancel order'))
|
||||||
|
@ -258,9 +258,15 @@ $("#complete-order").click(function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
$("#cancel-order").click(function() {
|
$("#cancel-order").click(function() {
|
||||||
launchModalForm("{% url 'po-cancel' order.id %}", {
|
|
||||||
reload: true,
|
cancelPurchaseOrder(
|
||||||
});
|
{{ order.pk }},
|
||||||
|
{
|
||||||
|
onSuccess: function() {
|
||||||
|
window.location.reload();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
$("#export-order").click(function() {
|
$("#export-order").click(function() {
|
||||||
|
@ -1,11 +0,0 @@
|
|||||||
{% extends "modal_form.html" %}
|
|
||||||
|
|
||||||
{% load i18n %}
|
|
||||||
|
|
||||||
{% block pre_form_content %}
|
|
||||||
|
|
||||||
<div class='alert alert-danger alert-block'>
|
|
||||||
{% trans "Cancelling this order means that the order and line items will no longer be editable." %}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{% endblock %}
|
|
@ -11,7 +11,6 @@ from . import views
|
|||||||
|
|
||||||
purchase_order_detail_urls = [
|
purchase_order_detail_urls = [
|
||||||
|
|
||||||
re_path(r'^cancel/', views.PurchaseOrderCancel.as_view(), name='po-cancel'),
|
|
||||||
re_path(r'^issue/', views.PurchaseOrderIssue.as_view(), name='po-issue'),
|
re_path(r'^issue/', views.PurchaseOrderIssue.as_view(), name='po-issue'),
|
||||||
re_path(r'^complete/', views.PurchaseOrderComplete.as_view(), name='po-complete'),
|
re_path(r'^complete/', views.PurchaseOrderComplete.as_view(), name='po-complete'),
|
||||||
|
|
||||||
|
@ -87,32 +87,6 @@ class SalesOrderDetail(InvenTreeRoleMixin, DetailView):
|
|||||||
template_name = 'order/sales_order_detail.html'
|
template_name = 'order/sales_order_detail.html'
|
||||||
|
|
||||||
|
|
||||||
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 validate(self, order, form, **kwargs):
|
|
||||||
|
|
||||||
confirm = str2bool(form.cleaned_data.get('confirm', False))
|
|
||||||
|
|
||||||
if not confirm:
|
|
||||||
form.add_error('confirm', _('Confirm order cancellation'))
|
|
||||||
|
|
||||||
if not order.can_cancel():
|
|
||||||
form.add_error(None, _('Order cannot be cancelled'))
|
|
||||||
|
|
||||||
def save(self, order, form, **kwargs):
|
|
||||||
"""
|
|
||||||
Cancel the PurchaseOrder
|
|
||||||
"""
|
|
||||||
|
|
||||||
order.cancel_order()
|
|
||||||
|
|
||||||
|
|
||||||
class SalesOrderCancel(AjaxUpdateView):
|
class SalesOrderCancel(AjaxUpdateView):
|
||||||
""" View for cancelling a sales order """
|
""" View for cancelling a sales order """
|
||||||
|
|
||||||
|
@ -123,6 +123,9 @@ function getApiEndpointOptions(url, callback) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Include extra context information in the request
|
||||||
|
url += '?context=true'
|
||||||
|
|
||||||
// Return the ajax request object
|
// Return the ajax request object
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: url,
|
url: url,
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
|
|
||||||
/* exported
|
/* exported
|
||||||
allocateStockToSalesOrder,
|
allocateStockToSalesOrder,
|
||||||
|
cancelPurchaseOrder,
|
||||||
completeShipment,
|
completeShipment,
|
||||||
createSalesOrder,
|
createSalesOrder,
|
||||||
createSalesOrderShipment,
|
createSalesOrderShipment,
|
||||||
@ -141,6 +142,30 @@ function completeShipment(shipment_id) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function cancelPurchaseOrder(order_id, options={}) {
|
||||||
|
|
||||||
|
var html = `
|
||||||
|
<div class='alert alert-info alert-block'>
|
||||||
|
{% trans "Are you sure you wish to cancel this purchase order?" %}
|
||||||
|
</div>`;
|
||||||
|
|
||||||
|
constructForm(
|
||||||
|
`/api/order/po/${order_id}/cancel/`,
|
||||||
|
{
|
||||||
|
method: 'POST',
|
||||||
|
title: '{% trans "Cancel Purchase Order" %}',
|
||||||
|
confirm: true,
|
||||||
|
preFormContent: html,
|
||||||
|
onSuccess: function(response) {
|
||||||
|
if (options.onSuccess) {
|
||||||
|
options.onSuccess(response);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Open a dialog to create a new sales order shipment
|
// Open a dialog to create a new sales order shipment
|
||||||
function createSalesOrderShipment(options={}) {
|
function createSalesOrderShipment(options={}) {
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user