Refactor StockItem pages

This commit is contained in:
Oliver 2021-07-15 22:19:13 +10:00
parent b1640fcc23
commit 533a3aa368
10 changed files with 358 additions and 427 deletions

View File

@ -3,44 +3,360 @@
{% load static %}
{% load inventree_extras %}
{% load i18n %}
{% load markdownify %}
{% block menubar %}
{% include "stock/navbar.html" with tab="tracking" %}
{% include "stock/navbar.html" %}
{% endblock %}
{% block heading %}
{% trans "Stock Tracking Information" %}
{% endblock %}
{% block page_content %}
{% block details %}
<div class='panel panel-default panel-inventree panel-hidden' id='panel-history'>
<div class='panel-heading'>
<h4>{% trans "Stock Tracking Information" %}</h4>
</div>
<div class='panel-content'>
{% setting_object 'STOCK_OWNERSHIP_CONTROL' as owner_control %}
{% if owner_control.value == "True" %}
{% authorized_owners item.owner as owners %}
{% endif %}
<!-- Check permissions and owner -->
{% if owner_control.value == "False" or owner_control.value == "True" and user in owners %}
{% if roles.stock.change and not item.is_building %}
<div id='table-toolbar'>
<div class='btn-group'>
<button class='btn btn-success' type='button' title='New tracking entry' id='new-entry'>
<span class='fas fa-plus-circle'></span> {% trans "New Entry" %}
</button>
</div>
</div>
{% endif %}
{% endif %}
<table class='table table-condensed table-striped' id='track-table' data-toolbar='#table-toolbar'>
</table>
</div>
</div>
{% setting_object 'STOCK_OWNERSHIP_CONTROL' as owner_control %}
{% if owner_control.value == "True" %}
{% authorized_owners item.owner as owners %}
{% endif %}
<div class='panel panel-default panel-inventree panel-hidden' id='panel-children'>
<div class='panel-heading'>
<h4>{% trans "Child Stock Items" %}</h4>
</div>
<div class='panel-content'>
{% if item.child_count > 0 %}
{% include "stock_table.html" with prefix="childs-" %}
{% else %}
<div class='alert alert-block alert-info'>
{% trans "This stock item does not have any child items" %}
</div>
{% endif %}
</div>
</div>
<hr>
<div class='panel panel-default panel-inventree panel-hidden' id='panel-test-data'>
<div class='panel-heading'>
<h4>{% trans "Test Data" %}</h4>
</div>
<div class='panel-content'>
<div id='test-button-toolbar'>
<div class='button-toolbar container-fluid' style="float: right;">
<div class='btn-group' role='group'>
{% if user.is_staff %}
<button type='button' class='btn btn-danger' id='delete-test-results'>
<span class='fas fa-trash-alt'></span> {% trans "Delete Test Data" %}
</button>
{% endif %}
<button type='button' class='btn btn-success' id='add-test-result'>
<span class='fas fa-plus-circle'></span> {% trans "Add Test Data" %}
</button>
<button type='button' class='btn btn-default' id='test-report'>
<span class='fas fa-tasks'></span> {% trans "Test Report" %}
</button>
</div>
<div class='filter-list' id='filter-list-stocktests'>
<!-- Empty div -->
</div>
</div>
</div>
<table class='table table-striped table-condensed' data-toolbar='#test-button-toolbar' id='test-result-table'></table>
</div>
</div>
<!-- Check permissions and owner -->
{% if owner_control.value == "False" or owner_control.value == "True" and user in owners %}
{% if roles.stock.change and not item.is_building %}
<div id='table-toolbar'>
<div class='btn-group'>
<button class='btn btn-success' type='button' title='New tracking entry' id='new-entry'>
<span class='fas fa-plus-circle'></span> {% trans "New Entry" %}
</button>
<div class='panel panel-default panel-inventree panel-hidden' id='panel-attachments'>
<div class='panel-heading'>
<h4>{% trans "Attachments" %}</h4>
</div>
<div class='panel-content'>
{% include "attachment_table.html" %}
</div>
</div>
<div class='panel panel-default panel-inventree panel-hidden' id='panel-notes'>
<div class='panel-heading'>
<div class='row'>
<div class='col-sm-6'>
<h4>{% trans "Stock Item Notes" %}</h4>
</div>
<div class='col-sm-6'>
<div class='btn-group float-right'>
<button type='button' id='edit-notes' title='{% trans "Edit Notes" %}' class='btn btn-small btn-default'>
<span class='fas fa-edit'>
</span>
</button>
</div>
</div>
</div>
</div>
{% endif %}
{% endif %}
<table class='table table-condensed table-striped' id='track-table' data-toolbar='#table-toolbar'>
</table>
<div class='panel-content'>
{% if item.notes %}
{{ item.notes | markdownify }}
{% endif %}
</div>
</div>
<div class='panel panel-default panel-inventree panel-hidden' id='panel-installed-items'>
<div class='panel-heading'>
<h4>{% trans "Installed Stock Items" %}</h4>
</div>
<div class='panel-content'>
<table class='table table-striped table-condensed' id='installed-table'></table>
</div>
</div>
{% endblock %}
{% block js_ready %}
{{ block.super }}
loadInstalledInTable(
$('#installed-table'),
{
stock_item: {{ item.pk }},
part: {{ item.part.pk }},
quantity: {{ item.quantity }},
}
);
$('#multi-item-uninstall').click(function() {
var selections = $('#installed-table').bootstrapTable('getSelections');
var items = [];
selections.forEach(function(item) {
items.push(item.pk);
});
launchModalForm(
"{% url 'stock-item-uninstall' %}",
{
data: {
'items[]': items,
},
reload: true,
}
);
});
$('#edit-notes').click(function() {
constructForm('{% url "api-stock-detail" item.pk %}', {
fields: {
notes: {
multiline: true,
}
},
title: '{% trans "Edit Notes" %}',
reload: true,
});
});
enableDragAndDrop(
'#attachment-dropzone',
"{% url 'api-stock-attachment-list' %}",
{
data: {
stock_item: {{ item.id }},
},
label: 'attachment',
success: function(data, status, xhr) {
reloadAttachmentTable();
}
}
);
loadAttachmentTable(
'{% url "api-stock-attachment-list" %}',
{
filters: {
stock_item: {{ item.pk }},
},
onEdit: function(pk) {
var url = `/api/stock/attachment/${pk}/`;
constructForm(url, {
fields: {
comment: {},
},
title: '{% trans "Edit Attachment" %}',
onSuccess: reloadAttachmentTable
});
},
onDelete: function(pk) {
var url = `/api/stock/attachment/${pk}/`;
constructForm(url, {
method: 'DELETE',
confirmMessage: '{% trans "Confirm Delete Operation" %}',
title: '{% trans "Delete Attachment" %}',
onSuccess: reloadAttachmentTable,
});
}
}
);
$("#new-attachment").click(function() {
constructForm(
'{% url "api-stock-attachment-list" %}',
{
method: 'POST',
fields: {
attachment: {},
comment: {},
stock_item: {
value: {{ item.pk }},
hidden: true,
},
},
reload: true,
title: '{% trans "Add Attachment" %}',
}
);
});
loadStockTestResultsTable(
$("#test-result-table"), {
part: {{ item.part.id }},
stock_item: {{ item.id }},
}
);
function reloadTable() {
$("#test-result-table").bootstrapTable("refresh");
}
{% if item.has_test_reports %}
$("#test-report").click(function() {
printTestReports([{{ item.pk }}]);
});
{% endif %}
{% if user.is_staff %}
$("#delete-test-results").click(function() {
launchModalForm(
"{% url 'stock-item-delete-test-data' item.id %}",
{
success: reloadTable,
}
);
});
{% endif %}
$("#add-test-result").click(function() {
constructForm('{% url "api-stock-test-result-list" %}', {
method: 'POST',
fields: {
test: {},
result: {},
value: {},
attachment: {},
notes: {},
stock_item: {
value: {{ item.pk }},
hidden: true,
}
},
title: '{% trans "Add Test Result" %}',
onSuccess: reloadTable,
});
});
$("#test-result-table").on('click', '.button-test-add', function() {
var button = $(this);
var test_name = button.attr('pk');
constructForm('{% url "api-stock-test-result-list" %}', {
method: 'POST',
fields: {
test: {
value: test_name,
},
result: {},
value: {},
attachment: {},
notes: {},
stock_item: {
value: {{ item.pk }},
hidden: true,
}
},
title: '{% trans "Add Test Result" %}',
onSuccess: reloadTable,
});
});
$("#test-result-table").on('click', '.button-test-edit', function() {
var button = $(this);
var pk = button.attr('pk');
var url = `/api/stock/test/${pk}/`;
constructForm(url, {
fields: {
test: {},
result: {},
value: {},
attachment: {},
notes: {},
},
title: '{% trans "Edit Test Result" %}',
onSuccess: reloadTable,
});
});
$("#test-result-table").on('click', '.button-test-delete', function() {
var button = $(this);
var pk = button.attr('pk');
var url = `/api/stock/test/${pk}/`;
constructForm(url, {
method: 'DELETE',
title: '{% trans "Delete Test Result" %}',
onSuccess: reloadTable,
});
});
{% if item.child_count > 0 %}
loadStockTable($("#childs-stock-table"), {
params: {
location_detail: true,
part_detail: false,
ancestor: {{ item.id }},
},
name: 'item-childs',
groupByField: 'location',
buttons: [
'#stock-options',
],
url: "{% url 'api-stock-list' %}",
});
{% endif %}
$("#new-entry").click(function() {
launchModalForm(
"{% url 'stock-tracking-create' item.id %}",

View File

@ -1,86 +0,0 @@
{% extends "stock/item_base.html" %}
{% load static %}
{% load i18n %}
{% block menubar %}
{% include "stock/navbar.html" with tab='attachments' %}
{% endblock %}
{% block heading %}
{% trans "Stock Item Attachments" %}
{% endblock %}
{% block details %}
{% include "attachment_table.html" with attachments=item.attachments.all %}
{% endblock %}
{% block js_ready %}
{{ block.super }}
enableDragAndDrop(
'#attachment-dropzone',
"{% url 'api-stock-attachment-list' %}",
{
data: {
stock_item: {{ item.id }},
},
label: 'attachment',
success: function(data, status, xhr) {
reloadAttachmentTable();
}
}
);
loadAttachmentTable(
'{% url "api-stock-attachment-list" %}',
{
filters: {
stock_item: {{ item.pk }},
},
onEdit: function(pk) {
var url = `/api/stock/attachment/${pk}/`;
constructForm(url, {
fields: {
comment: {},
},
title: '{% trans "Edit Attachment" %}',
onSuccess: reloadAttachmentTable
});
},
onDelete: function(pk) {
var url = `/api/stock/attachment/${pk}/`;
constructForm(url, {
method: 'DELETE',
confirmMessage: '{% trans "Confirm Delete Operation" %}',
title: '{% trans "Delete Attachment" %}',
onSuccess: reloadAttachmentTable,
});
}
}
);
$("#new-attachment").click(function() {
constructForm(
'{% url "api-stock-attachment-list" %}',
{
method: 'POST',
fields: {
attachment: {},
comment: {},
stock_item: {
value: {{ item.pk }},
hidden: true,
},
},
reload: true,
title: '{% trans "Add Attachment" %}',
}
);
});
{% endblock %}

View File

@ -428,6 +428,7 @@
</tr>
{% endif %}
</table>
{% endblock %}
{% block js_ready %}
@ -610,4 +611,9 @@ $("#stock-return-from-customer").click(function() {
{% endif %}
attachNavCallbacks({
name: 'stockitem',
default: 'history'
});
{% endblock %}

View File

@ -1,45 +0,0 @@
{% extends "stock/item_base.html" %}
{% load static %}
{% load i18n %}
{% block menubar %}
{% include "stock/navbar.html" with tab='children' %}
{% endblock %}
{% block heading %}
{% trans "Child Stock Items" %}
{% endblock %}
{% block details %}
{% if item.child_count > 0 %}
{% include "stock_table.html" %}
{% else %}
<div class='alert alert-block alert-info'>
{% trans "This stock item does not have any child items" %}
</div>
{% endif %}
{% endblock %}
{% block js_ready %}
{{ block.super }}
{% if item.child_count > 0 %}
loadStockTable($("#stock-table"), {
params: {
location_detail: true,
part_detail: false,
ancestor: {{ item.id }},
},
name: 'item-childs',
groupByField: 'location',
buttons: [
'#stock-options',
],
url: "{% url 'api-stock-list' %}",
});
{% endif %}
{% endblock %}

View File

@ -1,53 +0,0 @@
{% extends "stock/item_base.html" %}
{% load static %}
{% load i18n %}
{% block menubar %}
{% include "stock/navbar.html" with tab='installed' %}
{% endblock %}
{% block heading %}
{% trans "Installed Stock Items" %}
{% endblock %}
{% block details %}
<table class='table table-striped table-condensed' id='installed-table'></table>
{% endblock %}
{% block js_ready %}
{{ block.super }}
loadInstalledInTable(
$('#installed-table'),
{
stock_item: {{ item.pk }},
part: {{ item.part.pk }},
quantity: {{ item.quantity }},
}
);
$('#multi-item-uninstall').click(function() {
var selections = $('#installed-table').bootstrapTable('getSelections');
var items = [];
selections.forEach(function(item) {
items.push(item.pk);
});
launchModalForm(
"{% url 'stock-item-uninstall' %}",
{
data: {
'items[]': items,
},
reload: true,
}
);
});
{% endblock %}

View File

@ -1,51 +0,0 @@
{% extends "stock/item_base.html" %}
{% load static %}
{% load inventree_extras %}
{% load i18n %}
{% load markdownify %}
{% block menubar %}
{% include "stock/navbar.html" with tab="notes" %}
{% endblock %}
{% block heading %}
{% trans "Stock Item Notes" %}
{% if roles.stock.change and not editing %}
<button title='{% trans "Edit notes" %}' class='btn btn-default' id='edit-notes'><span class='fas fa-edit'></span></button>
{% endif %}
{% endblock %}
{% block details %}
{% if editing %}
<form method='POST'>
{% csrf_token %}
{{ form }}
<hr>
<button type="submit" class='btn btn-default'>{% trans "Save" %}</button>
</form>
{{ form.media }}
{% else %}
{% if item.notes %}
{{ item.notes | markdownify }}
{% endif %}
{% endif %}
{% endblock %}
{% block js_ready %}
{{ block.super }}
{% if editing %}
{% else %}
$("#edit-notes").click(function() {
location.href = "{% url 'stock-item-notes' item.id %}?edit=1";
});
{% endif %}
{% endblock %}

View File

@ -1,150 +0,0 @@
{% extends "stock/item_base.html" %}
{% load static %}
{% load i18n %}
{% block menubar %}
{% include "stock/navbar.html" with tab='tests' %}
{% endblock %}
{% block heading %}
{% trans "Test Data" %}
{% endblock %}
{% block details %}
<div id='button-toolbar'>
<div class='button-toolbar container-fluid' style="float: right;">
<div class='btn-group' role='group'>
{% if user.is_staff %}
<button type='button' class='btn btn-danger' id='delete-test-results'>
<span class='fas fa-trash-alt'></span> {% trans "Delete Test Data" %}
</button>
{% endif %}
<button type='button' class='btn btn-success' id='add-test-result'>
<span class='fas fa-plus-circle'></span> {% trans "Add Test Data" %}
</button>
<button type='button' class='btn btn-default' id='test-report'>
<span class='fas fa-tasks'></span> {% trans "Test Report" %}
</button>
</div>
<div class='filter-list' id='filter-list-stocktests'>
<!-- Empty div -->
</div>
</div>
</div>
<table class='table table-striped table-condensed' data-toolbar='#button-toolbar' id='test-result-table'></table>
{% endblock %}
{% block js_ready %}
{{ block.super }}
loadStockTestResultsTable(
$("#test-result-table"), {
part: {{ item.part.id }},
stock_item: {{ item.id }},
}
);
function reloadTable() {
$("#test-result-table").bootstrapTable("refresh");
}
{% if item.has_test_reports %}
$("#test-report").click(function() {
printTestReports([{{ item.pk }}]);
});
{% endif %}
{% if user.is_staff %}
$("#delete-test-results").click(function() {
launchModalForm(
"{% url 'stock-item-delete-test-data' item.id %}",
{
success: reloadTable,
}
);
});
{% endif %}
$("#add-test-result").click(function() {
constructForm('{% url "api-stock-test-result-list" %}', {
method: 'POST',
fields: {
test: {},
result: {},
value: {},
attachment: {},
notes: {},
stock_item: {
value: {{ item.pk }},
hidden: true,
}
},
title: '{% trans "Add Test Result" %}',
onSuccess: reloadTable,
});
});
$("#test-result-table").on('click', '.button-test-add', function() {
var button = $(this);
var test_name = button.attr('pk');
constructForm('{% url "api-stock-test-result-list" %}', {
method: 'POST',
fields: {
test: {
value: test_name,
},
result: {},
value: {},
attachment: {},
notes: {},
stock_item: {
value: {{ item.pk }},
hidden: true,
}
},
title: '{% trans "Add Test Result" %}',
onSuccess: reloadTable,
});
});
$("#test-result-table").on('click', '.button-test-edit', function() {
var button = $(this);
var pk = button.attr('pk');
var url = `/api/stock/test/${pk}/`;
constructForm(url, {
fields: {
test: {},
result: {},
value: {},
attachment: {},
notes: {},
},
title: '{% trans "Edit Test Result" %}',
onSuccess: reloadTable,
});
});
$("#test-result-table").on('click', '.button-test-delete', function() {
var button = $(this);
var pk = button.attr('pk');
var url = `/api/stock/test/${pk}/`;
constructForm(url, {
method: 'DELETE',
title: '{% trans "Delete Test Result" %}',
onSuccess: reloadTable,
});
});
{% endblock %}

View File

@ -8,24 +8,24 @@
</a>
</li>
<li class='list-group-item {% if tab == "tracking" %}active{% endif %}' title='{% trans "Stock Item Tracking" %}'>
<a href='{% url "stock-item-detail" item.id %}'>
<li class='list-group-item' title='{% trans "Stock Item Tracking" %}'>
<a href='#' id='select-history' class='nav-toggle'>
<span class='fas fa-history sidebar-icon'></span>
{% trans "History" %}
</a>
</li>
{% if item.part.trackable %}
<li class='list-group-item {% if tab == "tests" %}active{% endif %}' title='{% trans "Test Data" %}'>
<a href='{% url "stock-item-test-results" item.id %}'>
<li class='list-group-item' title='{% trans "Test Data" %}'>
<a href='#' id='select-test-data' class='nav-toggle'>
<span class='fas fa-vial sidebar-icon'></span>
{% trans "Test Data" %}
</a>
</li>
{% if item.part.assembly %}
<li class='list-group-item {% if tab == "installed" %}active{% endif %}' title='{% trans "Installed Stock Items" %}'>
<a href='{% url "stock-item-installed" item.id %}'>
<li class='list-group-item' title='{% trans "Installed Stock Items" %}'>
<a href='#' id='select-installed-items' class='nav-toggle'>
<span class='fas fa-sign-in-alt sidebar-icon'></span>
{% trans "Installed Items" %}
</a>
@ -35,8 +35,8 @@
{% endif %}
{% if item.child_count > 0 %}
<li class='list-group-item {% if tab == "children" %}active{% endif %}' title='{% trans "Child Items" %}'>
<a href='{% url "stock-item-children" item.id %}'>
<li class='list-group-item' title='{% trans "Child Items" %}'>
<a href='#' id='select-children' class='nav-toggle'>
<span class='fas fa-sitemap sidebar-icon'></span>
{% trans "Children" %}
</a>
@ -44,15 +44,15 @@
{% endif %}
<li class='list-group-item {% if tab == "attachments" %}active{% endif %}' title='{% trans "Attachments" %}'>
<a href='{% url "stock-item-attachments" item.id %}'>
<li class='list-group-item' title='{% trans "Attachments" %}'>
<a href='#' id='select-attachments' class='nav-toggle'>
<span class='fas fa-paperclip sidebar-icon'></span>
{% trans "Attachments" %}
</a>
</li>
<li class='list-group-item {% if tab == "notes" %}active{% endif %}' title='{% trans "Stock Item Notes" %}'>
<a href='{% url "stock-item-notes" item.id %}'>
<li class='list-group-item' title='{% trans "Stock Item Notes" %}'>
<a href='#' id='select-notes' class='nav-toggle'>
<span class='fas fa-clipboard sidebar-icon'></span>
{% trans "Notes" %}
</a>

View File

@ -34,12 +34,6 @@ stock_item_detail_urls = [
url(r'^add_tracking/', views.StockItemTrackingCreate.as_view(), name='stock-tracking-create'),
url(r'^test/', views.StockItemDetail.as_view(template_name='stock/item_tests.html'), name='stock-item-test-results'),
url(r'^children/', views.StockItemDetail.as_view(template_name='stock/item_childs.html'), name='stock-item-children'),
url(r'^attachments/', views.StockItemDetail.as_view(template_name='stock/item_attachments.html'), name='stock-item-attachments'),
url(r'^installed/', views.StockItemDetail.as_view(template_name='stock/item_installed.html'), name='stock-item-installed'),
url(r'^notes/', views.StockItemNotes.as_view(), name='stock-item-notes'),
url('^.*$', views.StockItemDetail.as_view(), name='stock-item-detail'),
]

View File

@ -8,7 +8,7 @@
{% authorized_owners location.owner as owners %}
{% endif %}
<div id='button-toolbar'>
<div id='{{ prefix }}button-toolbar'>
<div class='button-toolbar container-fluid' style='float: right;'>
<div class='btn-group'>
<button class='btn btn-default' id='stock-export' title='{% trans "Export Stock Information" %}'>
@ -74,5 +74,5 @@
</div>
</div>
<table class='table table-striped table-condensed' data-toolbar='#button-toolbar' id='stock-table'>
<table class='table table-striped table-condensed' data-toolbar='#{{ prefix }}button-toolbar' id='{{ prefix }}stock-table'>
</table>