2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-06-18 13:05:42 +00:00

Merge branch 'inventree:master' into matmair/issue2385

This commit is contained in:
Matthias Mair
2022-05-05 11:26:25 +02:00
committed by GitHub
48 changed files with 933 additions and 1767 deletions

View File

@ -21,6 +21,7 @@
/* exported
allocateStockToBuild,
autoAllocateStockToBuild,
cancelBuildOrder,
completeBuildOrder,
createBuildOutput,
editBuildOrder,
@ -123,6 +124,49 @@ function newBuildOrder(options={}) {
}
/* Construct a form to cancel a build order */
function cancelBuildOrder(build_id, options={}) {
constructForm(
`/api/build/${build_id}/cancel/`,
{
method: 'POST',
title: '{% trans "Cancel Build Order" %}',
confirm: true,
fields: {
remove_allocated_stock: {},
remove_incomplete_outputs: {},
},
preFormContent: function(opts) {
var html = `
<div class='alert alert-block alert-info'>
{% trans "Are you sure you wish to cancel this build?" %}
</div>`;
if (opts.context.has_allocated_stock) {
html += `
<div class='alert alert-block alert-warning'>
{% trans "Stock items have been allocated to this build order" %}
</div>`;
}
if (opts.context.incomplete_outputs) {
html += `
<div class='alert alert-block alert-warning'>
{% trans "There are incomplete outputs remaining for this build order" %}
</div>`;
}
return html;
},
onSuccess: function(response) {
handleFormSuccess(response, options);
}
}
);
}
/* Construct a form to "complete" (finish) a build order */
function completeBuildOrder(build_id, options={}) {

View File

@ -123,6 +123,9 @@ function getApiEndpointOptions(url, callback) {
return;
}
// Include extra context information in the request
url += '?context=true';
// Return the ajax request object
$.ajax({
url: url,
@ -335,6 +338,9 @@ function constructForm(url, options) {
// Request OPTIONS endpoint from the API
getApiEndpointOptions(url, function(OPTIONS) {
// Extract any custom 'context' information from the OPTIONS data
options.context = OPTIONS.context || {};
/*
* Determine what "type" of form we want to construct,
* based on the requested action.
@ -527,7 +533,14 @@ function constructFormBody(fields, options) {
$(modal).find('#form-content').html(html);
if (options.preFormContent) {
$(modal).find('#pre-form-content').html(options.preFormContent);
if (typeof(options.preFormContent) === 'function') {
var content = options.preFormContent(options);
} else {
var content = options.preFormContent;
}
$(modal).find('#pre-form-content').html(content);
}
if (options.postFormContent) {

View File

@ -81,7 +81,7 @@ function renderStockItem(name, data, parameters={}, options={}) {
var part_detail = '';
if (render_part_detail) {
if (render_part_detail && data.part_detail) {
part_detail = `<img src='${image}' class='select2-thumbnail'><span>${data.part_detail.full_name}</span> - `;
}

View File

@ -20,11 +20,15 @@
/* exported
allocateStockToSalesOrder,
cancelPurchaseOrder,
cancelSalesOrder,
completePurchaseOrder,
completeShipment,
createSalesOrder,
createSalesOrderShipment,
editPurchaseOrderLineItem,
exportOrder,
issuePurchaseOrder,
loadPurchaseOrderLineItemTable,
loadPurchaseOrderExtraLineTable
loadPurchaseOrderTable,
@ -140,6 +144,133 @@ function completeShipment(shipment_id) {
});
}
/*
* Launches a modal form to mark a PurchaseOrder as "complete"
*/
function completePurchaseOrder(order_id, options={}) {
constructForm(
`/api/order/po/${order_id}/complete/`,
{
method: 'POST',
title: '{% trans "Complete Purchase Order" %}',
confirm: true,
preFormContent: function(opts) {
var html = `
<div class='alert alert-block alert-info'>
{% trans "Mark this order as complete?" %}
</div>`;
if (opts.context.is_complete) {
html += `
<div class='alert alert-block alert-success'>
{% trans "All line items have been received" %}
</div>`;
} else {
html += `
<div class='alert alert-block alert-warning'>
{% trans 'This order has line items which have not been marked as received.' %}</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 PurchaseOrder as 'cancelled'
*/
function cancelPurchaseOrder(order_id, options={}) {
constructForm(
`/api/order/po/${order_id}/cancel/`,
{
method: 'POST',
title: '{% trans "Cancel Purchase Order" %}',
confirm: true,
preFormContent: function(opts) {
var html = `
<div class='alert alert-info alert-block'>
{% trans "Are you sure you wish to cancel this purchase order?" %}
</div>`;
if (!opts.context.can_cancel) {
html += `
<div class='alert alert-danger alert-block'>
{% trans "This purchase order can not be cancelled" %}
</div>`;
}
return html;
},
onSuccess: function(response) {
handleFormSuccess(response, options);
}
}
);
}
/*
* Launches a modal form to mark a PurchaseOrder as "issued"
*/
function issuePurchaseOrder(order_id, options={}) {
constructForm(
`/api/order/po/${order_id}/issue/`,
{
method: 'POST',
title: '{% trans "Issue Purchase Order" %}',
confirm: true,
preFormContent: function(opts) {
var html = `
<div class='alert alert-block alert-warning'>
{% trans 'After placing this purchase order, 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"
*/
function cancelSalesOrder(order_id, options={}) {
constructForm(
`/api/order/so/${order_id}/cancel/`,
{
method: 'POST',
title: '{% trans "Cancel Sales Order" %}',
confirm: true,
preFormContent: function(opts) {
var html = `
<div class='alert alert-block alert-warning'>
{% trans "Cancelling this order means that the order will no longer be editable." %}
</div>`;
return html;
},
onSuccess: function(response) {
handleFormSuccess(response, options);
}
}
);
}
// Open a dialog to create a new sales order shipment
function createSalesOrderShipment(options={}) {

View File

@ -57,6 +57,7 @@
stockItemFields,
stockLocationFields,
stockStatusCodes,
uninstallStockItem,
*/
@ -2630,13 +2631,10 @@ function loadInstalledInTable(table, options) {
table.find('.button-uninstall').click(function() {
var pk = $(this).attr('pk');
launchModalForm(
'{% url "stock-item-uninstall" %}',
uninstallStockItem(
pk,
{
data: {
'items[]': pk,
},
success: function() {
onSuccess: function(response) {
table.bootstrapTable('refresh');
}
}
@ -2647,6 +2645,43 @@ function loadInstalledInTable(table, options) {
}
/*
* Launch a dialog to uninstall a stock item from another stock item
*/
function uninstallStockItem(installed_item_id, options={}) {
constructForm(
`/api/stock/${installed_item_id}/uninstall/`,
{
confirm: true,
method: 'POST',
title: '{% trans "Uninstall Stock Item" %}',
fields: {
location: {
icon: 'fa-sitemap',
},
note: {},
},
preFormContent: function(opts) {
var html = '';
if (installed_item_id == null) {
html += `
<div class='alert alert-block alert-info'>
{% trans "Select stock item to uninstall" %}
</div>`;
}
return html;
},
onSuccess: function(response) {
handleFormSuccess(response, options);
}
}
);
}
/*
* Launch a dialog to install a stock item into another stock item
*/