mirror of
https://github.com/inventree/InvenTree.git
synced 2025-06-15 19:45:46 +00:00
Refactor report printing javascript code
- Replace all existing functions with 'printReports'
This commit is contained in:
@ -247,7 +247,11 @@ src="{% static 'img/blank_image.png' %}"
|
||||
|
||||
{% if report_enabled %}
|
||||
$('#print-build-report').click(function() {
|
||||
printBuildReports([{{ build.pk }}]);
|
||||
printReports({
|
||||
items: [{{ build.pk }}],
|
||||
key: 'build',
|
||||
url: '{% url "api-build-report-list" %}',
|
||||
});
|
||||
});
|
||||
{% endif %}
|
||||
|
||||
|
@ -71,7 +71,11 @@ $('#multi-build-print').click(function() {
|
||||
build_ids.push(row.pk);
|
||||
});
|
||||
|
||||
printBuildReports(build_ids);
|
||||
printReports({
|
||||
items: build_ids,
|
||||
key: 'build',
|
||||
url: '{% url "api-build-report-list" %}'
|
||||
});
|
||||
});
|
||||
{% endif %}
|
||||
|
||||
|
@ -229,7 +229,11 @@ $("#place-order").click(function() {
|
||||
|
||||
{% if report_enabled %}
|
||||
$('#print-order-report').click(function() {
|
||||
printPurchaseOrderReports([{{ order.pk }}]);
|
||||
printReports({
|
||||
items: [{{ order.pk }}],
|
||||
key: 'order',
|
||||
url: '{% url "api-po-report-list" %}',
|
||||
});
|
||||
});
|
||||
{% endif %}
|
||||
|
||||
|
@ -63,8 +63,12 @@ $("#order-print").click(function() {
|
||||
orders.push(row.pk);
|
||||
});
|
||||
|
||||
printPurchaseOrderReports(orders);
|
||||
})
|
||||
printReports({
|
||||
items: orders,
|
||||
key: 'order',
|
||||
url: '{% url "api-po-report-list" %}',
|
||||
});
|
||||
});
|
||||
{% endif %}
|
||||
|
||||
$("#po-create").click(function() {
|
||||
|
@ -54,7 +54,21 @@
|
||||
loadReturnOrderTable('#return-order-table', {});
|
||||
|
||||
{% if report_enabled %}
|
||||
<!-- TODO: report button callbacks -->
|
||||
$("#order-print").click(function() {
|
||||
var rows = getTableData('#return-order-table');
|
||||
|
||||
var orders = [];
|
||||
|
||||
rows.forEach(function(row) {
|
||||
orders.push(row.pk);
|
||||
});
|
||||
|
||||
printReports({
|
||||
url: '{% url "api-return-order-report-list" %}',
|
||||
key: 'order',
|
||||
items: orders,
|
||||
});
|
||||
});
|
||||
{% endif %}
|
||||
|
||||
$('#return-order-create').click(function() {
|
||||
|
@ -250,7 +250,11 @@ $("#complete-order").click(function() {
|
||||
|
||||
{% if report_enabled %}
|
||||
$('#print-order-report').click(function() {
|
||||
printSalesOrderReports([{{ order.pk }}]);
|
||||
printReports({
|
||||
items: [{{ order.pk }}],
|
||||
key: 'order',
|
||||
url: '{% url "api-so-report-list" %}',
|
||||
});
|
||||
});
|
||||
{% endif %}
|
||||
|
||||
|
@ -64,8 +64,12 @@ $("#order-print").click(function() {
|
||||
orders.push(row.pk);
|
||||
});
|
||||
|
||||
printSalesOrderReports(orders);
|
||||
})
|
||||
printReports({
|
||||
items: orders,
|
||||
key: 'order',
|
||||
url: '{% url "api-so-report-list" %}',
|
||||
});
|
||||
});
|
||||
{% endif %}
|
||||
|
||||
$("#so-create").click(function() {
|
||||
|
@ -677,7 +677,11 @@
|
||||
|
||||
{% if report_enabled %}
|
||||
$("#print-bom-report").click(function() {
|
||||
printBomReports([{{ part.pk }}]);
|
||||
printReports({
|
||||
items: [{{ part.pk }}],
|
||||
key: 'part',
|
||||
url: '{% url "api-bom-report-list" %}'
|
||||
});
|
||||
});
|
||||
{% endif %}
|
||||
});
|
||||
|
@ -261,7 +261,11 @@
|
||||
|
||||
{% if item.has_test_reports %}
|
||||
$("#test-report").click(function() {
|
||||
printTestReports([{{ item.pk }}]);
|
||||
printReports({
|
||||
items: [{{ item.pk }}],
|
||||
key: 'item',
|
||||
url: '{% url "api-stockitem-testreport-list" %}',
|
||||
});
|
||||
});
|
||||
{% endif %}
|
||||
|
||||
|
@ -493,7 +493,11 @@ $('#stock-uninstall').click(function() {
|
||||
});
|
||||
|
||||
$("#stock-test-report").click(function() {
|
||||
printTestReports([{{ item.pk }}]);
|
||||
printReports({
|
||||
items: [{{ item.pk }}],
|
||||
key: 'item',
|
||||
url: '{% url "api-stockitem-testreport-list" %}',
|
||||
});
|
||||
});
|
||||
|
||||
$("#print-label").click(function() {
|
||||
|
@ -14,11 +14,7 @@
|
||||
*/
|
||||
|
||||
/* exported
|
||||
printBomReports,
|
||||
printBuildReports,
|
||||
printPurchaseOrderReports,
|
||||
printSalesOrderReports,
|
||||
printTestReports,
|
||||
printReports,
|
||||
*/
|
||||
|
||||
function selectReport(reports, items, options={}) {
|
||||
@ -108,270 +104,57 @@ function selectReport(reports, items, options={}) {
|
||||
}
|
||||
|
||||
|
||||
function printTestReports(items) {
|
||||
/**
|
||||
* Print test reports for the provided stock item(s)
|
||||
*/
|
||||
/*
|
||||
* Print report(s) for the selected items:
|
||||
*
|
||||
* - Retrieve a list of matching report templates from the server
|
||||
* - Present the available templates to the user (if more than one available)
|
||||
* - Request printed document
|
||||
*
|
||||
* Required options:
|
||||
* - url: The list URL for the particular template
|
||||
* - items: The list of objects to print
|
||||
* - key: The key to use in the query parameters
|
||||
*/
|
||||
function printReports(options) {
|
||||
|
||||
if (items.length == 0) {
|
||||
if (!options.items || options.items.length == 0) {
|
||||
showAlertDialog(
|
||||
'{% trans "Select Stock Items" %}',
|
||||
'{% trans "Stock item(s) must be selected before printing reports" %}'
|
||||
'{% trans "Select Items" %}',
|
||||
'{% trans "No items selected for printing" }',
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// Request available reports from the server
|
||||
inventreeGet(
|
||||
'{% url "api-stockitem-testreport-list" %}',
|
||||
{
|
||||
enabled: true,
|
||||
items: items,
|
||||
},
|
||||
{
|
||||
success: function(response) {
|
||||
if (response.length == 0) {
|
||||
showAlertDialog(
|
||||
'{% trans "No Reports Found" %}',
|
||||
'{% trans "No report templates found which match selected stock item(s)" %}',
|
||||
);
|
||||
let params = {
|
||||
enabled: true,
|
||||
};
|
||||
|
||||
return;
|
||||
}
|
||||
params[options.key] = options.items;
|
||||
|
||||
// Select report template to print
|
||||
selectReport(
|
||||
response,
|
||||
items,
|
||||
{
|
||||
success: function(pk) {
|
||||
var href = `/api/report/test/${pk}/print/?`;
|
||||
|
||||
items.forEach(function(item) {
|
||||
href += `item=${item}&`;
|
||||
});
|
||||
|
||||
window.open(href);
|
||||
}
|
||||
}
|
||||
// Request a list of available reports
|
||||
inventreeGet(options.url, params, {
|
||||
success: function(response) {
|
||||
if (response.length == 0) {
|
||||
showAlertDialog(
|
||||
'{% trans "No Reports Found" %}',
|
||||
'{% trans "No report templates found which match the selected items" %}',
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
// Select report template for printing
|
||||
selectReport(response, options.items, {
|
||||
success: function(pk) {
|
||||
let href = `${options.url}${pk}/print/?`;
|
||||
|
||||
function printBuildReports(builds) {
|
||||
/**
|
||||
* Print Build report for the provided build(s)
|
||||
*/
|
||||
options.items.forEach(function(item) {
|
||||
href += `${options.key}=${item}&`;
|
||||
});
|
||||
|
||||
if (builds.length == 0) {
|
||||
showAlertDialog(
|
||||
'{% trans "Select Builds" %}',
|
||||
'{% trans "Build(s) must be selected before printing reports" %}',
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
inventreeGet(
|
||||
'{% url "api-build-report-list" %}',
|
||||
{
|
||||
enabled: true,
|
||||
builds: builds,
|
||||
},
|
||||
{
|
||||
success: function(response) {
|
||||
if (response.length == 0) {
|
||||
showAlertDialog(
|
||||
'{% trans "No Reports Found" %}',
|
||||
'{% trans "No report templates found which match selected build(s)" %}'
|
||||
);
|
||||
|
||||
return;
|
||||
window.open(href);
|
||||
}
|
||||
|
||||
// Select which report to print
|
||||
selectReport(
|
||||
response,
|
||||
builds,
|
||||
{
|
||||
success: function(pk) {
|
||||
var href = `/api/report/build/${pk}/print/?`;
|
||||
|
||||
builds.forEach(function(build) {
|
||||
href += `build=${build}&`;
|
||||
});
|
||||
|
||||
window.open(href);
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
function printBomReports(parts) {
|
||||
/**
|
||||
* Print BOM reports for the provided part(s)
|
||||
*/
|
||||
|
||||
if (parts.length == 0) {
|
||||
showAlertDialog(
|
||||
'{% trans "Select Parts" %}',
|
||||
'{% trans "Part(s) must be selected before printing reports" %}'
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// Request available reports from the server
|
||||
inventreeGet(
|
||||
'{% url "api-bom-report-list" %}',
|
||||
{
|
||||
enabled: true,
|
||||
parts: parts,
|
||||
},
|
||||
{
|
||||
success: function(response) {
|
||||
if (response.length == 0) {
|
||||
showAlertDialog(
|
||||
'{% trans "No Reports Found" %}',
|
||||
'{% trans "No report templates found which match selected part(s)" %}',
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// Select which report to print
|
||||
selectReport(
|
||||
response,
|
||||
parts,
|
||||
{
|
||||
success: function(pk) {
|
||||
var href = `/api/report/bom/${pk}/print/?`;
|
||||
|
||||
parts.forEach(function(part) {
|
||||
href += `part=${part}&`;
|
||||
});
|
||||
|
||||
window.open(href);
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
function printPurchaseOrderReports(orders) {
|
||||
/**
|
||||
* Print PurchaseOrder reports for the provided purchase order(s)
|
||||
*/
|
||||
|
||||
if (orders.length == 0) {
|
||||
showAlertDialog(
|
||||
'{% trans "Select Purchase Orders" %}',
|
||||
'{% trans "Purchase Order(s) must be selected before printing report" %}',
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// Request avaiable report templates
|
||||
inventreeGet(
|
||||
'{% url "api-po-report-list" %}',
|
||||
{
|
||||
enabled: true,
|
||||
orders: orders,
|
||||
},
|
||||
{
|
||||
success: function(response) {
|
||||
if (response.length == 0) {
|
||||
showAlertDialog(
|
||||
'{% trans "No Reports Found" %}',
|
||||
'{% trans "No report templates found which match selected orders" %}',
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// Select report template
|
||||
selectReport(
|
||||
response,
|
||||
orders,
|
||||
{
|
||||
success: function(pk) {
|
||||
var href = `/api/report/po/${pk}/print/?`;
|
||||
|
||||
orders.forEach(function(order) {
|
||||
href += `order=${order}&`;
|
||||
});
|
||||
|
||||
window.open(href);
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
function printSalesOrderReports(orders) {
|
||||
/**
|
||||
* Print SalesOrder reports for the provided purchase order(s)
|
||||
*/
|
||||
|
||||
if (orders.length == 0) {
|
||||
showAlertDialog(
|
||||
'{% trans "Select Sales Orders" %}',
|
||||
'{% trans "Sales Order(s) must be selected before printing report" %}',
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// Request avaiable report templates
|
||||
inventreeGet(
|
||||
'{% url "api-so-report-list" %}',
|
||||
{
|
||||
enabled: true,
|
||||
orders: orders,
|
||||
},
|
||||
{
|
||||
success: function(response) {
|
||||
if (response.length == 0) {
|
||||
showAlertDialog(
|
||||
'{% trans "No Reports Found" %}',
|
||||
'{% trans "No report templates found which match selected orders" %}',
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// Select report template
|
||||
selectReport(
|
||||
response,
|
||||
orders,
|
||||
{
|
||||
success: function(pk) {
|
||||
var href = `/api/report/so/${pk}/print/?`;
|
||||
|
||||
orders.forEach(function(order) {
|
||||
href += `order=${order}&`;
|
||||
});
|
||||
|
||||
window.open(href);
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
);
|
||||
});
|
||||
}
|
||||
|
@ -25,7 +25,7 @@
|
||||
modalSubmit,
|
||||
openModal,
|
||||
printStockItemLabels,
|
||||
printTestReports,
|
||||
printReports,
|
||||
renderLink,
|
||||
scanItemsIntoLocation,
|
||||
showAlertDialog,
|
||||
@ -2216,7 +2216,11 @@ function loadStockTable(table, options) {
|
||||
items.push(item.pk);
|
||||
});
|
||||
|
||||
printTestReports(items);
|
||||
printReports({
|
||||
items: items,
|
||||
key: 'item',
|
||||
url: '{% url "api-stockitem-testreport-list" %}',
|
||||
});
|
||||
});
|
||||
|
||||
if (global_settings.BARCODE_ENABLE) {
|
||||
|
Reference in New Issue
Block a user