2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-07-15 01:11:27 +00:00

Merge branch 'master' of https://github.com/inventree/InvenTree into style-fixes

This commit is contained in:
Matthias Mair
2022-05-21 23:57:41 +02:00
28 changed files with 296 additions and 483 deletions

View File

@ -24,6 +24,7 @@
cancelSalesOrder,
completePurchaseOrder,
completeShipment,
completePendingShipments,
createSalesOrder,
createSalesOrderShipment,
editPurchaseOrderLineItem,
@ -69,7 +70,7 @@ function salesOrderShipmentFields(options={}) {
/*
* Complete a shipment
*/
function completeShipment(shipment_id) {
function completeShipment(shipment_id, options={}) {
// Request the list of stock items which will be shipped
inventreeGet(`/api/order/so/shipment/${shipment_id}/`, {}, {
@ -126,28 +127,128 @@ function completeShipment(shipment_id) {
constructForm(`/api/order/so/shipment/${shipment_id}/ship/`, {
method: 'POST',
title: '{% trans "Complete Shipment" %}',
title: `{% trans "Complete Shipment" %} ${shipment.reference}`,
fields: {
tracking_number: {},
},
preFormContent: html,
confirm: true,
confirmMessage: '{% trans "Confirm Shipment" %}',
buttons: options.buttons,
onSuccess: function(data) {
// Reload tables
$('#so-lines-table').bootstrapTable('refresh');
$('#pending-shipments-table').bootstrapTable('refresh');
$('#completed-shipments-table').bootstrapTable('refresh');
if (options.onSuccess instanceof Function) {
options.onSuccess(data);
}
},
reload: true
reload: options.reload
});
}
});
}
/*
* Launches a modal to mark all allocated pending shipments as complete
*/
function completePendingShipments(order_id, options={}) {
var pending_shipments = null;
// Request the list of stock items which will be shipped
inventreeGet(`/api/order/so/shipment/.*`,
{
order: order_id,
shipped: false
},
{
async: false,
success: function(shipments) {
pending_shipments = shipments;
}
}
);
var allocated_shipments = [];
for (var idx = 0; idx < pending_shipments.length; idx++) {
if (pending_shipments[idx].allocations.length > 0) {
allocated_shipments.push(pending_shipments[idx]);
}
}
if (allocated_shipments.length > 0) {
completePendingShipmentsHelper(allocated_shipments, 0, options);
} else {
html = `
<div class='alert alert-block alert-danger'>
`;
if (!pending_shipments.length) {
html += `
{% trans "No pending shipments found" %}
`;
} else {
html += `
{% trans "No stock items have been allocated to pending shipments" %}
`;
}
html += `
</div>
`;
constructForm(`/api/order/so/shipment/0/ship/`, {
method: 'POST',
title: '{% trans "Complete Shipments" %}',
preFormContent: html,
onSubmit: function(fields, options) {
handleFormSuccess(fields, options);
},
closeText: 'Close',
hideSubmitButton: true,
});
}
}
/*
* Recursive helper for opening shipment completion modals
*/
function completePendingShipmentsHelper(shipments, shipment_idx, options={}) {
if (shipment_idx < shipments.length) {
completeShipment(shipments[shipment_idx].pk,
{
buttons: [
{
name: 'skip',
title: `{% trans "Skip" %}`,
onClick: function(form_options) {
if (form_options.modal) {
$(form_options.modal).modal('hide');
}
completePendingShipmentsHelper(shipments, shipment_idx + 1, options);
}
}
],
onSuccess: function(data) {
completePendingShipmentsHelper(shipments, shipment_idx + 1, options);
},
}
);
} else if (options.reload) {
location.reload();
}
}
/*
* Launches a modal form to mark a PurchaseOrder as "complete"
*/
*/
function completePurchaseOrder(order_id, options={}) {
constructForm(