mirror of
https://github.com/inventree/InvenTree.git
synced 2025-04-30 20:46:47 +00:00
Simplify BOM editing view
- A user with permission to edit BOM data can immediately access the BOM editing tools
This commit is contained in:
parent
51efd6b2e4
commit
6816071388
@ -1,7 +1,7 @@
|
|||||||
{% load i18n %}
|
{% load i18n %}
|
||||||
{% load inventree_extras %}
|
{% load inventree_extras %}
|
||||||
|
|
||||||
{% if roles.part.change != True and editing_enabled %}
|
{% if not roles.part.change %}
|
||||||
<div class='alert alert-danger alert-block'>
|
<div class='alert alert-danger alert-block'>
|
||||||
{% trans "You do not have permission to edit the BOM." %}
|
{% trans "You do not have permission to edit the BOM." %}
|
||||||
</div>
|
</div>
|
||||||
@ -23,7 +23,7 @@
|
|||||||
|
|
||||||
<div id='bom-button-toolbar'>
|
<div id='bom-button-toolbar'>
|
||||||
<div class="btn-group" role="group" aria-label="...">
|
<div class="btn-group" role="group" aria-label="...">
|
||||||
{% if editing_enabled %}
|
{% if roles.part.change %}
|
||||||
<button class='btn btn-default' type='button' title='{% trans "Remove selected BOM items" %}' id='bom-item-delete'>
|
<button class='btn btn-default' type='button' title='{% trans "Remove selected BOM items" %}' id='bom-item-delete'>
|
||||||
<span class='fas fa-trash-alt icon-red'></span>
|
<span class='fas fa-trash-alt icon-red'></span>
|
||||||
</button>
|
</button>
|
||||||
@ -35,17 +35,9 @@
|
|||||||
<span class='fas fa-clone'></span>
|
<span class='fas fa-clone'></span>
|
||||||
</button>
|
</button>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<button class='btn btn-default' type='button' title='{% trans "New BOM Item" %}' id='bom-item-new'>
|
<button class='btn btn-success' type='button' title='{% trans "New BOM Item" %}' id='bom-item-new'>
|
||||||
<span class='fas fa-plus-circle'></span>
|
<span class='fas fa-plus-circle'></span>
|
||||||
</button>
|
</button>
|
||||||
<button class='btn btn-success' type='button' title='{% trans "Finish Editing" %}' id='editing-finished'>
|
|
||||||
<span class='fas fa-check-circle'></span>
|
|
||||||
</button>
|
|
||||||
{% elif part.active %}
|
|
||||||
{% if roles.part.change %}
|
|
||||||
<button class='btn btn-primary' type='button' title='{% trans "Edit BOM" %}' id='edit-bom'>
|
|
||||||
<span class='fas fa-edit'></span>
|
|
||||||
</button>
|
|
||||||
{% if part.is_bom_valid == False %}
|
{% if part.is_bom_valid == False %}
|
||||||
<button class='btn btn-success' id='validate-bom' title='{% trans "Validate Bill of Materials" %}' type='button'>
|
<button class='btn btn-success' id='validate-bom' title='{% trans "Validate Bill of Materials" %}' type='button'>
|
||||||
<span class='fas fa-clipboard-check'></span>
|
<span class='fas fa-clipboard-check'></span>
|
||||||
@ -67,4 +59,3 @@
|
|||||||
|
|
||||||
<table class='table table-bom table-condensed' data-toolbar="#bom-button-toolbar" id='bom-table'>
|
<table class='table table-bom table-condensed' data-toolbar="#bom-button-toolbar" id='bom-table'>
|
||||||
</table>
|
</table>
|
||||||
{% endif %}
|
|
@ -473,7 +473,11 @@
|
|||||||
onPanelLoad("bom", function() {
|
onPanelLoad("bom", function() {
|
||||||
// Load the BOM table data
|
// Load the BOM table data
|
||||||
loadBomTable($("#bom-table"), {
|
loadBomTable($("#bom-table"), {
|
||||||
editable: {{ editing_enabled }},
|
{% if roles.part.change %}
|
||||||
|
editable: true,
|
||||||
|
{% else %}
|
||||||
|
editable: false,
|
||||||
|
{% endif %}
|
||||||
bom_url: "{% url 'api-bom-list' %}",
|
bom_url: "{% url 'api-bom-list' %}",
|
||||||
part_url: "{% url 'api-part-list' %}",
|
part_url: "{% url 'api-part-list' %}",
|
||||||
parent_id: {{ part.id }} ,
|
parent_id: {{ part.id }} ,
|
||||||
@ -486,11 +490,6 @@
|
|||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
{% if editing_enabled %}
|
|
||||||
$("#editing-finished").click(function() {
|
|
||||||
location.href = "{% url 'part-detail' part.id %}?display=bom";
|
|
||||||
});
|
|
||||||
|
|
||||||
$('#bom-item-delete').click(function() {
|
$('#bom-item-delete').click(function() {
|
||||||
|
|
||||||
// Get a list of the selected BOM items
|
// Get a list of the selected BOM items
|
||||||
@ -559,8 +558,6 @@
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
{% else %}
|
|
||||||
|
|
||||||
$("#validate-bom").click(function() {
|
$("#validate-bom").click(function() {
|
||||||
launchModalForm(
|
launchModalForm(
|
||||||
"{% url 'bom-validate' part.id %}",
|
"{% url 'bom-validate' part.id %}",
|
||||||
@ -570,10 +567,6 @@
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
$("#edit-bom").click(function () {
|
|
||||||
location.href = "{% url 'part-detail' part.id %}?display=bom&edit=1";
|
|
||||||
});
|
|
||||||
|
|
||||||
$("#download-bom").click(function () {
|
$("#download-bom").click(function () {
|
||||||
launchModalForm("{% url 'bom-export' part.id %}",
|
launchModalForm("{% url 'bom-export' part.id %}",
|
||||||
{
|
{
|
||||||
@ -584,8 +577,6 @@
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
$("#print-bom-report").click(function() {
|
$("#print-bom-report").click(function() {
|
||||||
printBomReports([{{ part.pk }}]);
|
printBomReports([{{ part.pk }}]);
|
||||||
});
|
});
|
||||||
@ -629,10 +620,9 @@
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
// Load the BOM table data in the pricing view
|
// Load the BOM table data in the pricing view
|
||||||
loadBomTable($("#bom-pricing-table"), {
|
loadBomTable($("#bom-pricing-table"), {
|
||||||
editable: {{ editing_enabled }},
|
editable: false,
|
||||||
bom_url: "{% url 'api-bom-list' %}",
|
bom_url: "{% url 'api-bom-list' %}",
|
||||||
part_url: "{% url 'api-part-list' %}",
|
part_url: "{% url 'api-part-list' %}",
|
||||||
parent_id: {{ part.id }} ,
|
parent_id: {{ part.id }} ,
|
||||||
|
@ -87,16 +87,6 @@ class PartDetailTest(PartViewTestCase):
|
|||||||
self.assertEqual(response.context['part'].pk, pk)
|
self.assertEqual(response.context['part'].pk, pk)
|
||||||
self.assertEqual(response.context['category'], part.category)
|
self.assertEqual(response.context['category'], part.category)
|
||||||
|
|
||||||
self.assertFalse(response.context['editing_enabled'])
|
|
||||||
|
|
||||||
def test_editable(self):
|
|
||||||
|
|
||||||
pk = 1
|
|
||||||
response = self.client.get(reverse('part-detail', args=(pk,)), {'edit': True})
|
|
||||||
|
|
||||||
self.assertEqual(response.status_code, 200)
|
|
||||||
self.assertTrue(response.context['editing_enabled'])
|
|
||||||
|
|
||||||
def test_part_detail_from_ipn(self):
|
def test_part_detail_from_ipn(self):
|
||||||
"""
|
"""
|
||||||
Test that we can retrieve a part detail page from part IPN:
|
Test that we can retrieve a part detail page from part IPN:
|
||||||
|
@ -404,20 +404,13 @@ class PartDetail(InvenTreeRoleMixin, DetailView):
|
|||||||
|
|
||||||
# Add in some extra context information based on query params
|
# Add in some extra context information based on query params
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
""" Provide extra context data to template
|
"""
|
||||||
|
Provide extra context data to template
|
||||||
- If '?editing=True', set 'editing_enabled' context variable
|
|
||||||
"""
|
"""
|
||||||
context = super().get_context_data(**kwargs)
|
context = super().get_context_data(**kwargs)
|
||||||
|
|
||||||
part = self.get_object()
|
part = self.get_object()
|
||||||
|
|
||||||
if str2bool(self.request.GET.get('edit', '')):
|
|
||||||
# Allow BOM editing if the part is active
|
|
||||||
context['editing_enabled'] = 1 if part.active else 0
|
|
||||||
else:
|
|
||||||
context['editing_enabled'] = 0
|
|
||||||
|
|
||||||
ctx = part.get_context_data(self.request)
|
ctx = part.get_context_data(self.request)
|
||||||
context.update(**ctx)
|
context.update(**ctx)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user