mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +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 inventree_extras %}
|
||||
|
||||
{% if roles.part.change != True and editing_enabled %}
|
||||
{% if not roles.part.change %}
|
||||
<div class='alert alert-danger alert-block'>
|
||||
{% trans "You do not have permission to edit the BOM." %}
|
||||
</div>
|
||||
@ -23,7 +23,7 @@
|
||||
|
||||
<div id='bom-button-toolbar'>
|
||||
<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'>
|
||||
<span class='fas fa-trash-alt icon-red'></span>
|
||||
</button>
|
||||
@ -35,17 +35,9 @@
|
||||
<span class='fas fa-clone'></span>
|
||||
</button>
|
||||
{% 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>
|
||||
</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 %}
|
||||
<button class='btn btn-success' id='validate-bom' title='{% trans "Validate Bill of Materials" %}' type='button'>
|
||||
<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>
|
||||
{% endif %}
|
@ -473,7 +473,11 @@
|
||||
onPanelLoad("bom", function() {
|
||||
// Load the BOM table data
|
||||
loadBomTable($("#bom-table"), {
|
||||
editable: {{ editing_enabled }},
|
||||
{% if roles.part.change %}
|
||||
editable: true,
|
||||
{% else %}
|
||||
editable: false,
|
||||
{% endif %}
|
||||
bom_url: "{% url 'api-bom-list' %}",
|
||||
part_url: "{% url 'api-part-list' %}",
|
||||
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() {
|
||||
|
||||
// Get a list of the selected BOM items
|
||||
@ -559,8 +558,6 @@
|
||||
});
|
||||
});
|
||||
|
||||
{% else %}
|
||||
|
||||
$("#validate-bom").click(function() {
|
||||
launchModalForm(
|
||||
"{% 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 () {
|
||||
launchModalForm("{% url 'bom-export' part.id %}",
|
||||
{
|
||||
@ -584,8 +577,6 @@
|
||||
);
|
||||
});
|
||||
|
||||
{% endif %}
|
||||
|
||||
$("#print-bom-report").click(function() {
|
||||
printBomReports([{{ part.pk }}]);
|
||||
});
|
||||
@ -629,10 +620,9 @@
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
// Load the BOM table data in the pricing view
|
||||
loadBomTable($("#bom-pricing-table"), {
|
||||
editable: {{ editing_enabled }},
|
||||
editable: false,
|
||||
bom_url: "{% url 'api-bom-list' %}",
|
||||
part_url: "{% url 'api-part-list' %}",
|
||||
parent_id: {{ part.id }} ,
|
||||
|
@ -87,16 +87,6 @@ class PartDetailTest(PartViewTestCase):
|
||||
self.assertEqual(response.context['part'].pk, pk)
|
||||
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):
|
||||
"""
|
||||
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
|
||||
def get_context_data(self, **kwargs):
|
||||
""" Provide extra context data to template
|
||||
|
||||
- If '?editing=True', set 'editing_enabled' context variable
|
||||
"""
|
||||
Provide extra context data to template
|
||||
"""
|
||||
context = super().get_context_data(**kwargs)
|
||||
|
||||
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)
|
||||
context.update(**ctx)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user