mirror of
https://github.com/inventree/InvenTree.git
synced 2025-06-18 04:55:44 +00:00
Add confirmation field for incomplete purchase orders (#3615)
* Add confirmation field for incomplete purchase orders * Add similar functionality for SalesOrder - Complete form is now context sensitive - Allow user to specify if order should be closed with incomplete lines * Update API version * JS linting * Updated unit tests
This commit is contained in:
@ -328,8 +328,6 @@ function constructForm(url, options) {
|
||||
constructFormBody({}, options);
|
||||
}
|
||||
|
||||
options.fields = options.fields || {};
|
||||
|
||||
// Save the URL
|
||||
options.url = url;
|
||||
|
||||
@ -351,6 +349,13 @@ function constructForm(url, options) {
|
||||
// Extract any custom 'context' information from the OPTIONS data
|
||||
options.context = OPTIONS.context || {};
|
||||
|
||||
// Construct fields (can be a static parameter or a function)
|
||||
if (options.fieldsFunction) {
|
||||
options.fields = options.fieldsFunction(options);
|
||||
} else {
|
||||
options.fields = options.fields || {};
|
||||
}
|
||||
|
||||
/*
|
||||
* Determine what "type" of form we want to construct,
|
||||
* based on the requested action.
|
||||
|
@ -24,6 +24,7 @@
|
||||
cancelPurchaseOrder,
|
||||
cancelSalesOrder,
|
||||
completePurchaseOrder,
|
||||
completeSalesOrder,
|
||||
completeShipment,
|
||||
completePendingShipments,
|
||||
createPurchaseOrder,
|
||||
@ -282,6 +283,17 @@ function completePurchaseOrder(order_id, options={}) {
|
||||
method: 'POST',
|
||||
title: '{% trans "Complete Purchase Order" %}',
|
||||
confirm: true,
|
||||
fieldsFunction: function(opts) {
|
||||
var fields = {
|
||||
accept_incomplete: {},
|
||||
};
|
||||
|
||||
if (opts.context.is_complete) {
|
||||
delete fields['accept_incomplete'];
|
||||
}
|
||||
|
||||
return fields;
|
||||
},
|
||||
preFormContent: function(opts) {
|
||||
|
||||
var html = `
|
||||
@ -373,6 +385,59 @@ function issuePurchaseOrder(order_id, options={}) {
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Launches a modal form to mark a SalesOrder as "complete"
|
||||
*/
|
||||
function completeSalesOrder(order_id, options={}) {
|
||||
|
||||
constructForm(
|
||||
`/api/order/so/${order_id}/complete/`,
|
||||
{
|
||||
method: 'POST',
|
||||
title: '{% trans "Complete Sales Order" %}',
|
||||
confirm: true,
|
||||
fieldsFunction: function(opts) {
|
||||
var fields = {
|
||||
accept_incomplete: {},
|
||||
};
|
||||
|
||||
if (opts.context.is_complete) {
|
||||
delete fields['accept_incomplete'];
|
||||
}
|
||||
|
||||
return fields;
|
||||
},
|
||||
preFormContent: function(opts) {
|
||||
var html = `
|
||||
<div class='alert alert-block alert-info'>
|
||||
{% trans "Mark this order as complete?" %}
|
||||
</div>`;
|
||||
|
||||
if (opts.context.pending_shipments) {
|
||||
html += `
|
||||
<div class='alert alert-block alert-danger'>
|
||||
{% trans "Order cannot be completed as there are incomplete shipments" %}<br>
|
||||
</div>`;
|
||||
}
|
||||
|
||||
if (!opts.context.is_complete) {
|
||||
html += `
|
||||
<div class='alert alert-block alert-warning'>
|
||||
{% trans "This order has line items which have not been completed." %}<br>
|
||||
{% trans "Completing this order means that the order and line items will no longer be editable." %}
|
||||
</div>`;
|
||||
}
|
||||
|
||||
return html;
|
||||
},
|
||||
onSuccess: function(response) {
|
||||
handleFormSuccess(response, options);
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Launches a modal form to mark a SalesOrder as "cancelled"
|
||||
*/
|
||||
|
Reference in New Issue
Block a user