mirror of
https://github.com/inventree/InvenTree.git
synced 2025-05-15 11:33:08 +00:00
Filter by category too
This commit is contained in:
parent
776fc8b1e5
commit
ddb041fe44
@ -44,6 +44,7 @@
|
|||||||
|
|
||||||
<div id='button-toolbar'>
|
<div id='button-toolbar'>
|
||||||
<div class='button-toolbar container-fluid' style="float: right;">
|
<div class='button-toolbar container-fluid' style="float: right;">
|
||||||
|
<button class='btn btn-default' id='part-export' title='Export Part Data'>Export</button>
|
||||||
<button class='btn btn-success' id='part-create'>New Part</button>
|
<button class='btn btn-success' id='part-create'>New Part</button>
|
||||||
<div class='dropdown' style='float: right;'>
|
<div class='dropdown' style='float: right;'>
|
||||||
<button id='part-options' class='btn btn-primary dropdown-toggle' type='button' data-toggle="dropdown">Options<span class='caret'></span></button>
|
<button id='part-options' class='btn btn-primary dropdown-toggle' type='button' data-toggle="dropdown">Options<span class='caret'></span></button>
|
||||||
@ -104,6 +105,13 @@
|
|||||||
});
|
});
|
||||||
})
|
})
|
||||||
|
|
||||||
|
$("#part-export").click(function() {
|
||||||
|
|
||||||
|
var url = "{% url 'part-export' %}?category={{ category.id }}";
|
||||||
|
|
||||||
|
location.href = url;
|
||||||
|
});
|
||||||
|
|
||||||
$("#part-create").click(function() {
|
$("#part-create").click(function() {
|
||||||
launchModalForm(
|
launchModalForm(
|
||||||
"{% url 'part-create' %}",
|
"{% url 'part-create' %}",
|
||||||
|
@ -1166,12 +1166,29 @@ class PartExport(AjaxView):
|
|||||||
""" Extract part list from the POST parameters.
|
""" Extract part list from the POST parameters.
|
||||||
Parts can be supplied as:
|
Parts can be supplied as:
|
||||||
|
|
||||||
- List of part PK values
|
|
||||||
- Part category
|
- Part category
|
||||||
|
- List of part PK values
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
# Filter by part category
|
||||||
|
cat_id = request.GET.get('category', None)
|
||||||
|
|
||||||
|
print('cat_id:', cat_id)
|
||||||
|
|
||||||
|
part_list = None
|
||||||
|
|
||||||
|
if cat_id is not None:
|
||||||
|
try:
|
||||||
|
category = PartCategory.objects.get(pk=cat_id)
|
||||||
|
part_list = category.get_parts()
|
||||||
|
except (ValueError, PartCategory.DoesNotExist):
|
||||||
|
pass
|
||||||
|
|
||||||
|
# Backup - All parts
|
||||||
|
if part_list is None:
|
||||||
part_list = Part.objects.all()
|
part_list = Part.objects.all()
|
||||||
|
|
||||||
|
# Also optionally filter by explicit list of part IDs
|
||||||
part_ids = request.GET.get('parts', '')
|
part_ids = request.GET.get('parts', '')
|
||||||
parts = []
|
parts = []
|
||||||
|
|
||||||
@ -1181,20 +1198,9 @@ class PartExport(AjaxView):
|
|||||||
except ValueError:
|
except ValueError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
# Filter by list of Part IDs
|
|
||||||
if len(parts) > 0:
|
if len(parts) > 0:
|
||||||
part_list = part_list.filter(pk__in=parts)
|
part_list = part_list.filter(pk__in=parts)
|
||||||
|
|
||||||
# Filter by part category
|
|
||||||
cat_id = request.GET.get('category', None)
|
|
||||||
|
|
||||||
if cat_id is not None:
|
|
||||||
try:
|
|
||||||
category = PartCategory.objects.get(cat_id)
|
|
||||||
part_list = part_list.filter(category=category)
|
|
||||||
except (ValueError, PartCategory.DoesNotExist):
|
|
||||||
pass
|
|
||||||
|
|
||||||
# Prefetch related fields to reduce DB hits
|
# Prefetch related fields to reduce DB hits
|
||||||
part_list = part_list.prefetch_related(
|
part_list = part_list.prefetch_related(
|
||||||
'category',
|
'category',
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
<div id='button-toolbar'>
|
<div id='button-toolbar'>
|
||||||
<div class='button-toolbar container-fluid' style='float: right;'>
|
<div class='button-toolbar container-fluid' style='float: right;'>
|
||||||
<button class='btn btn-success' id='stock-export' title='Export Stock Information'>Export</button>
|
<button class='btn btn-default' id='stock-export' title='Export Stock Information'>Export</button>
|
||||||
{% if not part or part.is_template == False %}
|
{% if not part or part.is_template == False %}
|
||||||
<button class="btn btn-success" id='item-create'>New Stock Item</button>
|
<button class="btn btn-success" id='item-create'>New Stock Item</button>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user