mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Merge remote-tracking branch 'inventree/master'
This commit is contained in:
commit
015ed66967
@ -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' %}",
|
||||||
|
@ -1162,15 +1162,59 @@ class BomUpload(FormView):
|
|||||||
class PartExport(AjaxView):
|
class PartExport(AjaxView):
|
||||||
""" Export a CSV file containing information on multiple parts """
|
""" Export a CSV file containing information on multiple parts """
|
||||||
|
|
||||||
def get(self, request, *args, **kwargs):
|
def get_parts(self, request):
|
||||||
part = request.GET.get('parts', '')
|
""" Extract part list from the POST parameters.
|
||||||
parts = []
|
Parts can be supplied as:
|
||||||
|
|
||||||
for pk in part.split(','):
|
- 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:
|
try:
|
||||||
parts.append(Part.objects.get(pk=int(pk)))
|
category = PartCategory.objects.get(pk=cat_id)
|
||||||
except (Part.DoesNotExist, ValueError):
|
part_list = category.get_parts()
|
||||||
continue
|
except (ValueError, PartCategory.DoesNotExist):
|
||||||
|
pass
|
||||||
|
|
||||||
|
# Backup - All parts
|
||||||
|
if part_list is None:
|
||||||
|
part_list = Part.objects.all()
|
||||||
|
|
||||||
|
# Also optionally filter by explicit list of part IDs
|
||||||
|
part_ids = request.GET.get('parts', '')
|
||||||
|
parts = []
|
||||||
|
|
||||||
|
for pk in part_ids.split(','):
|
||||||
|
try:
|
||||||
|
parts.append(int(pk))
|
||||||
|
except ValueError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
if len(parts) > 0:
|
||||||
|
part_list = part_list.filter(pk__in=parts)
|
||||||
|
|
||||||
|
# Prefetch related fields to reduce DB hits
|
||||||
|
part_list = part_list.prefetch_related(
|
||||||
|
'category',
|
||||||
|
'used_in',
|
||||||
|
'builds',
|
||||||
|
'supplier_parts__purchase_order_line_items',
|
||||||
|
'stock_items__allocations',
|
||||||
|
)
|
||||||
|
|
||||||
|
return part_list
|
||||||
|
|
||||||
|
def get(self, request, *args, **kwargs):
|
||||||
|
|
||||||
|
parts = self.get_parts(request)
|
||||||
|
|
||||||
headers = [
|
headers = [
|
||||||
'ID',
|
'ID',
|
||||||
@ -1187,10 +1231,16 @@ class PartExport(AjaxView):
|
|||||||
'Component',
|
'Component',
|
||||||
'Template',
|
'Template',
|
||||||
'Trackable',
|
'Trackable',
|
||||||
|
'Purchaseable',
|
||||||
'Salable',
|
'Salable',
|
||||||
'Active',
|
'Active',
|
||||||
'Virtual',
|
'Virtual',
|
||||||
'Stock Info', # Spacer between part data and stock data
|
|
||||||
|
# Part meta-data
|
||||||
|
'Used In',
|
||||||
|
|
||||||
|
# Stock Information
|
||||||
|
'Stock Info',
|
||||||
'In Stock',
|
'In Stock',
|
||||||
'Allocated',
|
'Allocated',
|
||||||
'Building',
|
'Building',
|
||||||
@ -1222,8 +1272,14 @@ class PartExport(AjaxView):
|
|||||||
line.append(part.pk)
|
line.append(part.pk)
|
||||||
line.append(part.name)
|
line.append(part.name)
|
||||||
line.append(part.description)
|
line.append(part.description)
|
||||||
line.append(str(part.category))
|
|
||||||
line.append(part.category.pk)
|
if part.category:
|
||||||
|
line.append(str(part.category))
|
||||||
|
line.append(part.category.pk)
|
||||||
|
else:
|
||||||
|
line.append('')
|
||||||
|
line.append('')
|
||||||
|
|
||||||
line.append(part.IPN)
|
line.append(part.IPN)
|
||||||
line.append(part.revision)
|
line.append(part.revision)
|
||||||
line.append(part.URL)
|
line.append(part.URL)
|
||||||
@ -1233,10 +1289,14 @@ class PartExport(AjaxView):
|
|||||||
line.append(part.component)
|
line.append(part.component)
|
||||||
line.append(part.is_template)
|
line.append(part.is_template)
|
||||||
line.append(part.trackable)
|
line.append(part.trackable)
|
||||||
|
line.append(part.purchaseable)
|
||||||
line.append(part.salable)
|
line.append(part.salable)
|
||||||
line.append(part.active)
|
line.append(part.active)
|
||||||
line.append(part.virtual)
|
line.append(part.virtual)
|
||||||
|
|
||||||
|
# Part meta-data
|
||||||
|
line.append(part.used_in_count)
|
||||||
|
|
||||||
# Stock information
|
# Stock information
|
||||||
line.append('')
|
line.append('')
|
||||||
line.append(part.total_stock)
|
line.append(part.total_stock)
|
||||||
@ -1244,6 +1304,7 @@ class PartExport(AjaxView):
|
|||||||
line.append(part.quantity_being_built)
|
line.append(part.quantity_being_built)
|
||||||
line.append(part.on_order)
|
line.append(part.on_order)
|
||||||
|
|
||||||
|
# Supplier Information
|
||||||
if len(supplier_names) > 0:
|
if len(supplier_names) > 0:
|
||||||
line.append('')
|
line.append('')
|
||||||
|
|
||||||
|
@ -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…
Reference in New Issue
Block a user