diff --git a/InvenTree/InvenTree/api.py b/InvenTree/InvenTree/api.py
new file mode 100644
index 0000000000..d68ecd67ad
--- /dev/null
+++ b/InvenTree/InvenTree/api.py
@@ -0,0 +1,142 @@
+"""
+Main JSON interface views
+"""
+
+# -*- coding: utf-8 -*-
+from __future__ import unicode_literals
+
+from django.utils.translation import ugettext as _
+from django.http import JsonResponse
+
+from rest_framework import permissions
+from rest_framework.response import Response
+from rest_framework.views import APIView
+
+from .views import AjaxView
+from .version import inventreeVersion, inventreeInstanceName
+
+from plugins import plugins as inventree_plugins
+
+# Load barcode plugins
+print("INFO: Loading plugins")
+
+barcode_plugins = inventree_plugins.load_barcode_plugins()
+action_plugins = inventree_plugins.load_action_plugins()
+
+
+class InfoView(AjaxView):
+ """ Simple JSON endpoint for InvenTree information.
+ Use to confirm that the server is running, etc.
+ """
+
+ def get(self, request, *args, **kwargs):
+
+ data = {
+ 'server': 'InvenTree',
+ 'version': inventreeVersion(),
+ 'instance': inventreeInstanceName(),
+ }
+
+ return JsonResponse(data)
+
+
+class ActionPluginView(APIView):
+ """
+ Endpoint for running custom action plugins.
+ """
+
+ permission_classes = [
+ permissions.IsAuthenticated,
+ ]
+
+ def post(self, request, *args, **kwargs):
+
+ action = request.data.get('action', None)
+
+ data = request.data.get('data', None)
+
+ if action is None:
+ return Response({
+ 'error': _("No action specified")
+ })
+
+ for plugin_class in action_plugins:
+ if plugin_class.action_name() == action:
+
+ plugin = plugin_class(request.user, data=data)
+
+ plugin.perform_action()
+
+ return Response(plugin.get_response())
+
+ # If we got to here, no matching action was found
+ return Response({
+ 'error': _("No matching action found"),
+ "action": action,
+ })
+
+
+class BarcodePluginView(APIView):
+ """
+ Endpoint for handling barcode scan requests.
+
+ Barcode data are decoded by the client application,
+ and sent to this endpoint (as a JSON object) for validation.
+
+ A barcode could follow the internal InvenTree barcode format,
+ or it could match to a third-party barcode format (e.g. Digikey).
+
+ """
+
+ permission_classes = [
+ permissions.IsAuthenticated,
+ ]
+
+ def post(self, request, *args, **kwargs):
+
+ response = {}
+
+ barcode_data = request.data.get('barcode', None)
+
+ print("Barcode data:")
+ print(barcode_data)
+
+ if barcode_data is None:
+ response['error'] = _('No barcode data provided')
+ else:
+ # Look for a barcode plugin that knows how to handle the data
+ for plugin_class in barcode_plugins:
+
+ # Instantiate the plugin with the provided plugin data
+ plugin = plugin_class(barcode_data)
+
+ if plugin.validate():
+
+ # Plugin should return a dict response
+ response = plugin.decode()
+
+ if type(response) is dict:
+ if 'success' not in response.keys() and 'error' not in response.keys():
+ response['success'] = _('Barcode successfully decoded')
+ else:
+ response = {
+ 'error': _('Barcode plugin returned incorrect response')
+ }
+
+ response['plugin'] = plugin.plugin_name()
+ response['hash'] = plugin.hash()
+
+ break
+
+ if 'error' not in response and 'success' not in response:
+ response = {
+ 'error': _('Unknown barcode format'),
+ }
+
+ # Include the original barcode data
+ response['barcode_data'] = barcode_data
+
+ print("Response:")
+ print(response)
+
+ return Response(response)
diff --git a/InvenTree/InvenTree/helpers.py b/InvenTree/InvenTree/helpers.py
index 6b619b4aa2..b9a4d73740 100644
--- a/InvenTree/InvenTree/helpers.py
+++ b/InvenTree/InvenTree/helpers.py
@@ -172,7 +172,7 @@ def WrapWithQuotes(text, quote='"'):
return text
-def MakeBarcode(object_type, object_id, object_url, data={}):
+def MakeBarcode(object_name, object_data):
""" Generate a string for a barcode. Adds some global InvenTree parameters.
Args:
@@ -185,13 +185,12 @@ def MakeBarcode(object_type, object_id, object_url, data={}):
json string of the supplied data plus some other data
"""
- # Add in some generic InvenTree data
- data['type'] = object_type
- data['id'] = object_id
- data['url'] = object_url
- data['tool'] = 'InvenTree'
- data['instance'] = inventreeInstanceName()
- data['version'] = inventreeVersion()
+ data = {
+ 'tool': 'InvenTree',
+ 'version': inventreeVersion(),
+ 'instance': inventreeInstanceName(),
+ object_name: object_data
+ }
return json.dumps(data, sort_keys=True)
diff --git a/InvenTree/InvenTree/static/script/inventree/part.js b/InvenTree/InvenTree/static/script/inventree/part.js
index 05b209b9b8..7954caa012 100644
--- a/InvenTree/InvenTree/static/script/inventree/part.js
+++ b/InvenTree/InvenTree/static/script/inventree/part.js
@@ -81,15 +81,19 @@ function loadPartTable(table, url, options={}) {
* - table: HTML reference to the table
* - url: Base URL for API query
* - options: object containing following (optional) fields
- * allowInactive: If true, allow display of inactive parts
* checkbox: Show the checkbox column
* query: extra query params for API request
* buttons: If provided, link buttons to selection status of this table
+ * disableFilters: If true, disable custom filters
*/
- var params = options.parms || {};
+ var params = options.params || {};
- var filters = loadTableFilters("parts");
+ var filters = {};
+
+ if (!options.disableFilters) {
+ filters = loadTableFilters("parts");
+ }
for (var key in params) {
filters[key] = params[key];
@@ -147,6 +151,10 @@ function loadPartTable(table, url, options={}) {
display += ``;
}
+ if (row.starred) {
+ display += ``;
+ }
+
/*
if (row.component) {
display = display + ``;
diff --git a/InvenTree/InvenTree/static/script/inventree/stock.js b/InvenTree/InvenTree/static/script/inventree/stock.js
index bf0ddbef5e..d68d0946a2 100644
--- a/InvenTree/InvenTree/static/script/inventree/stock.js
+++ b/InvenTree/InvenTree/static/script/inventree/stock.js
@@ -41,6 +41,7 @@ function loadStockTable(table, options) {
* groupByField - Column for grouping stock items
* buttons - Which buttons to link to stock selection callbacks
* filterList -
element where filters are displayed
+ * disableFilters: If true, disable custom filters
*/
// List of user-params which override the default filters
@@ -48,7 +49,11 @@ function loadStockTable(table, options) {
var filterListElement = options.filterList || "#filter-list-stock";
- var filters = loadTableFilters("stock");
+ var filters = {};
+
+ if (!options.disableFilters) {
+ filters = loadTableFilters("stock");
+ }
var original = {};
diff --git a/InvenTree/InvenTree/test_api.py b/InvenTree/InvenTree/test_api.py
index 0bb36db59f..5b13663897 100644
--- a/InvenTree/InvenTree/test_api.py
+++ b/InvenTree/InvenTree/test_api.py
@@ -27,6 +27,22 @@ class APITests(APITestCase):
User = get_user_model()
User.objects.create_user(self.username, 'user@email.com', self.password)
+ def test_info_view(self):
+ """
+ Test that we can read the 'info-view' endpoint.
+ """
+
+ url = reverse('api-inventree-info')
+
+ response = self.client.get(url, format='json')
+
+ data = response.json()
+ self.assertIn('server', data)
+ self.assertIn('version', data)
+ self.assertIn('instance', data)
+
+ self.assertEquals('InvenTree', data['server'])
+
def test_get_token_fail(self):
""" Ensure that an invalid user cannot get a token """
@@ -65,3 +81,7 @@ class APITests(APITestCase):
response = self.client.get(part_url, format='json')
self.assertEqual(response.status_code, status.HTTP_200_OK)
+
+ def test_barcode(self):
+ # TODO - Complete this
+ pass
diff --git a/InvenTree/InvenTree/tests.py b/InvenTree/InvenTree/tests.py
index d93a40e631..203748de3e 100644
--- a/InvenTree/InvenTree/tests.py
+++ b/InvenTree/InvenTree/tests.py
@@ -113,15 +113,15 @@ class TestMakeBarcode(TestCase):
def test_barcode(self):
- data = {
- 'animal': 'cat',
- 'legs': 3,
- 'noise': 'purr'
- }
+ bc = helpers.MakeBarcode(
+ "part",
+ {
+ "id": 3,
+ "url": "www.google.com",
+ }
+ )
- bc = helpers.MakeBarcode("part", 3, "www.google.com", data)
-
- self.assertIn('animal', bc)
+ self.assertIn('part', bc)
self.assertIn('tool', bc)
self.assertIn('"tool": "InvenTree"', bc)
diff --git a/InvenTree/InvenTree/urls.py b/InvenTree/InvenTree/urls.py
index fd36fa9112..d9600333f4 100644
--- a/InvenTree/InvenTree/urls.py
+++ b/InvenTree/InvenTree/urls.py
@@ -35,7 +35,8 @@ from rest_framework.documentation import include_docs_urls
from .views import IndexView, SearchView, DatabaseStatsView
from .views import SettingsView, EditUserView, SetPasswordView
-from .views import InfoView
+
+from .api import InfoView, BarcodePluginView, ActionPluginView
from users.urls import user_urls
@@ -53,8 +54,12 @@ apipatterns = [
# User URLs
url(r'^user/', include(user_urls)),
+ # Plugin endpoints
+ url(r'^barcode/', BarcodePluginView.as_view(), name='api-barcode-plugin'),
+ url(r'^action/', ActionPluginView.as_view(), name='api-action-plugin'),
+
# InvenTree information endpoint
- url(r'^$', InfoView.as_view(), name='inventree-info'),
+ url(r'^$', InfoView.as_view(), name='api-inventree-info'),
]
settings_urls = [
diff --git a/InvenTree/InvenTree/views.py b/InvenTree/InvenTree/views.py
index e1258385a5..943a18d35c 100644
--- a/InvenTree/InvenTree/views.py
+++ b/InvenTree/InvenTree/views.py
@@ -22,7 +22,6 @@ from common.models import InvenTreeSetting
from .forms import DeleteForm, EditUserForm, SetPasswordForm
from .helpers import str2bool
-from .version import inventreeVersion, inventreeInstanceName
from rest_framework import views
@@ -416,22 +415,6 @@ class AjaxDeleteView(AjaxMixin, UpdateView):
return self.renderJsonResponse(request, form, data=data, context=context)
-class InfoView(AjaxView):
- """ Simple JSON endpoint for InvenTree information.
- Use to confirm that the server is running, etc.
- """
-
- def get(self, request, *args, **kwargs):
-
- data = {
- 'server': 'InvenTree',
- 'version': inventreeVersion(),
- 'instance': inventreeInstanceName(),
- }
-
- return JsonResponse(data)
-
-
class EditUserView(AjaxUpdateView):
""" View for editing user information """
@@ -494,15 +477,16 @@ class IndexView(TemplateView):
context = super(TemplateView, self).get_context_data(**kwargs)
- context['starred'] = [star.part for star in self.request.user.starred_parts.all()]
+ # TODO - Re-implement this when a less expensive method is worked out
+ # context['starred'] = [star.part for star in self.request.user.starred_parts.all()]
# Generate a list of orderable parts which have stock below their minimum values
# TODO - Is there a less expensive way to get these from the database
- context['to_order'] = [part for part in Part.objects.filter(purchaseable=True) if part.need_to_restock()]
+ # context['to_order'] = [part for part in Part.objects.filter(purchaseable=True) if part.need_to_restock()]
# Generate a list of assembly parts which have stock below their minimum values
# TODO - Is there a less expensive way to get these from the database
- context['to_build'] = [part for part in Part.objects.filter(assembly=True) if part.need_to_restock()]
+ # context['to_build'] = [part for part in Part.objects.filter(assembly=True) if part.need_to_restock()]
return context
diff --git a/InvenTree/company/migrations/0019_auto_20200413_0642.py b/InvenTree/company/migrations/0019_auto_20200413_0642.py
index 2c120b30b4..f683ee783a 100644
--- a/InvenTree/company/migrations/0019_auto_20200413_0642.py
+++ b/InvenTree/company/migrations/0019_auto_20200413_0642.py
@@ -3,7 +3,7 @@
import os
from rapidfuzz import fuzz
-from django.db import migrations
+from django.db import migrations, connection
from company.models import Company, SupplierPart
from django.db.utils import OperationalError, ProgrammingError
@@ -29,17 +29,41 @@ def reverse_association(apps, schema_editor):
print("Reversing migration for manufacturer association")
- try:
- for part in SupplierPart.objects.all():
- if part.manufacturer is not None:
- part.manufacturer_name = part.manufacturer.name
-
- part.save()
+ for part in SupplierPart.objects.all():
- except (OperationalError, ProgrammingError):
- # An exception might be called if the database is empty
- pass
+ print("Checking part [{pk}]:".format(pk=part.pk))
+ cursor = connection.cursor()
+
+ # Grab the manufacturer ID from the part
+ response = cursor.execute('SELECT manufacturer_id FROM part_supplierpart WHERE id={ID};'.format(ID=part.id))
+
+ manufacturer_id = None
+
+ row = response.fetchone()
+
+ if len(row) > 0:
+ try:
+ manufacturer_id = int(row[0])
+ except (TypeError, ValueError):
+ pass
+
+ if manufacturer_id is None:
+ print(" - Manufacturer ID not set: Skipping")
+ continue
+
+ print(" - Manufacturer ID: [{id}]".format(id=manufacturer_id))
+
+ # Now extract the "name" for the manufacturer
+ response = cursor.execute('SELECT name from company_company where id={ID};'.format(ID=manufacturer_id))
+
+ row = response.fetchone()
+
+ name = row[0]
+
+ print(" - Manufacturer name: '{name}'".format(name=name))
+
+ response = cursor.execute("UPDATE part_supplierpart SET manufacturer_name='{name}' WHERE id={ID};".format(name=name, ID=part.id))
def associate_manufacturers(apps, schema_editor):
"""
@@ -54,6 +78,29 @@ def associate_manufacturers(apps, schema_editor):
It uses fuzzy pattern matching to help the user out as much as possible.
"""
+
+ def get_manufacturer_name(part_id):
+ """
+ THIS IS CRITICAL!
+
+ Once the pythonic representation of the model has removed the 'manufacturer_name' field,
+ it is NOT ACCESSIBLE by calling SupplierPart.manufacturer_name.
+
+ However, as long as the migrations are applied in order, then the table DOES have a field called 'manufacturer_name'.
+
+ So, we just need to request it using dirty SQL.
+ """
+
+ query = "SELECT manufacturer_name from part_supplierpart where id={ID};".format(ID=part_id)
+
+ cursor = connection.cursor()
+ response = cursor.execute(query)
+ row = response.fetchone()
+
+ if len(row) > 0:
+ return row[0]
+ return ''
+
# Exit if there are no SupplierPart objects
# This crucial otherwise the unit test suite fails!
@@ -70,23 +117,19 @@ def associate_manufacturers(apps, schema_editor):
for company in Company.objects.all():
companies[company.name] = company
- # List of parts which will need saving
- parts = []
-
-
def link_part(part, name):
""" Attempt to link Part to an existing Company """
# Matches a company name directly
if name in companies.keys():
- print(" -> '{n}' maps to existing manufacturer".format(n=name))
+ print(" - Part[{pk}]: '{n}' maps to existing manufacturer".format(pk=part.pk, n=name))
part.manufacturer = companies[name]
part.save()
return True
# Have we already mapped this
if name in links.keys():
- print(" -> Mapped '{n}' -> '{c}'".format(n=name, c=links[name].name))
+ print(" - Part[{pk}]: Mapped '{n}' - '{c}'".format(pk=part.pk, n=name, c=links[name].name))
part.manufacturer = links[name]
part.save()
return True
@@ -100,23 +143,22 @@ def associate_manufacturers(apps, schema_editor):
company = Company(name=company_name, description=company_name, is_manufacturer=True)
company.is_manufacturer = True
+
+ # Save the company BEFORE we associate the part, otherwise the PK does not exist
+ company.save()
# Map both names to the same company
links[input_name] = company
links[company_name] = company
companies[company_name] = company
-
- # Save the company BEFORE we associate the part, otherwise the PK does not exist
- company.save()
+ print(" - Part[{pk}]: Created new manufacturer: '{name}'".format(pk=part.pk, name=company_name))
+
# Save the manufacturer reference link
part.manufacturer = company
part.save()
- print(" -> Created new manufacturer: '{name}'".format(name=company_name))
-
-
def find_matches(text, threshold=65):
"""
Attempt to match a 'name' to an existing Company.
@@ -140,10 +182,11 @@ def associate_manufacturers(apps, schema_editor):
def map_part_to_manufacturer(part, idx, total):
- name = str(part.manufacturer_name)
+ name = get_manufacturer_name(part.id)
# Skip empty names
if not name or len(name) == 0:
+ print(" - Part[{pk}]: No manufacturer_name provided, skipping".format(pk=part.pk))
return
# Can be linked to an existing manufacturer
@@ -157,7 +200,7 @@ def associate_manufacturers(apps, schema_editor):
# Present a list of options
print("----------------------------------")
- print("Checking part {idx} of {total}".format(idx=idx+1, total=total))
+ print("Checking part [{pk}] ({idx} of {total})".format(pk=part.pk, idx=idx+1, total=total))
print("Manufacturer name: '{n}'".format(n=name))
print("----------------------------------")
print("Select an option from the list below:")
@@ -170,9 +213,8 @@ def associate_manufacturers(apps, schema_editor):
print("")
print("OR - Type a new custom manufacturer name")
-
- while (1):
+ while True:
response = str(input("> ")).strip()
# Attempt to parse user response as an integer
@@ -185,7 +227,7 @@ def associate_manufacturers(apps, schema_editor):
create_manufacturer(part, name, name)
return
- # Options 1) -> n) select an existing manufacturer
+ # Options 1) - n) select an existing manufacturer
else:
n = n - 1
@@ -206,9 +248,11 @@ def associate_manufacturers(apps, schema_editor):
links[name] = company
links[company_name] = company
- print(" -> Linked '{n}' to manufacturer '{m}'".format(n=name, m=company_name))
+ print(" - Part[{pk}]: Linked '{n}' to manufacturer '{m}'".format(pk=part.pk, n=name, m=company_name))
return
+ else:
+ print("Please select a valid option")
except ValueError:
# User has typed in a custom name!
@@ -256,11 +300,10 @@ def associate_manufacturers(apps, schema_editor):
for idx, part in enumerate(SupplierPart.objects.all()):
if part.manufacturer is not None:
- print(" -> Part '{p}' already has a manufacturer associated (skipping)".format(p=part))
+ print(" - Part '{p}' already has a manufacturer associated (skipping)".format(p=part))
continue
map_part_to_manufacturer(part, idx, part_count)
- parts.append(part)
print("Done!")
diff --git a/InvenTree/company/templates/company/detail_part.html b/InvenTree/company/templates/company/detail_part.html
index 537f7b07c3..2364f36b61 100644
--- a/InvenTree/company/templates/company/detail_part.html
+++ b/InvenTree/company/templates/company/detail_part.html
@@ -33,16 +33,29 @@
"{% url 'supplier-part-create' %}",
{
data: {
- supplier: {{ company.id }}
+ {% if company.is_supplier %}supplier: {{ company.id }},{% endif %}
+ {% if company.is_manufacturer %}manufacturer: {{ company.id }},{% endif %}
},
reload: true,
secondary: [
{
field: 'part',
- label: 'New Part',
- title: 'Create New Part',
+ label: '{% trans "New Part" %}',
+ title: '{% trans "Create new Part" %}',
url: "{% url 'part-create' %}"
},
+ {
+ field: 'supplier',
+ label: "{% trans 'New Supplier' %}",
+ title: "{% trans 'Create new Supplier' %}",
+ url: "{% url 'supplier-create' %}",
+ },
+ {
+ field: 'manufacturer',
+ label: '{% trans "New Manufacturer" %}',
+ title: '{% trans "Create new Manufacturer" %}',
+ url: "{% url 'manufacturer-create' %}",
+ },
]
});
});
diff --git a/InvenTree/company/templates/company/supplier_part_base.html b/InvenTree/company/templates/company/supplier_part_base.html
index 964c61ee5e..fec430628b 100644
--- a/InvenTree/company/templates/company/supplier_part_base.html
+++ b/InvenTree/company/templates/company/supplier_part_base.html
@@ -61,7 +61,7 @@ InvenTree | {% trans "Supplier Part" %}
{% trans "Supplier" %} |
{{ part.supplier.name }} |
- |
+ |
{% trans "SKU" %} |
{{ part.SKU }} |
@@ -71,14 +71,14 @@ InvenTree | {% trans "Supplier Part" %}
{% trans "Manufacturer" %} |
{{ part.manufacturer.name }} |
- |
+ |
{% trans "MPN" %} |
{{ part.MPN }} |
{% endif %}
{% if part.note %}
- |
+ |
{% trans "Note" %} |
{{ part.note }} |
diff --git a/InvenTree/company/views.py b/InvenTree/company/views.py
index d1fc9b643f..ae88629505 100644
--- a/InvenTree/company/views.py
+++ b/InvenTree/company/views.py
@@ -273,10 +273,6 @@ class SupplierPartCreate(AjaxCreateView):
Hide some fields if they are not appropriate in context
"""
form = super(AjaxCreateView, self).get_form()
-
- if form.initial.get('supplier', None):
- # Hide the supplier field
- form.fields['supplier'].widget = HiddenInput()
if form.initial.get('part', None):
# Hide the part field
@@ -292,20 +288,27 @@ class SupplierPartCreate(AjaxCreateView):
"""
initials = super(SupplierPartCreate, self).get_initial().copy()
+ manufacturer_id = self.get_param('manufacturer')
supplier_id = self.get_param('supplier')
part_id = self.get_param('part')
if supplier_id:
try:
initials['supplier'] = Company.objects.get(pk=supplier_id)
- except Company.DoesNotExist:
- initials['supplier'] = None
+ except (ValueError, Company.DoesNotExist):
+ pass
+
+ if manufacturer_id:
+ try:
+ initials['manufacturer'] = Company.objects.get(pk=manufacturer_id)
+ except (ValueError, Company.DoesNotExist):
+ pass
if part_id:
try:
initials['part'] = Part.objects.get(pk=part_id)
- except Part.DoesNotExist:
- initials['part'] = None
+ except (ValueError, Part.DoesNotExist):
+ pass
return initials
diff --git a/InvenTree/order/api.py b/InvenTree/order/api.py
index 21fbd80326..18ba890127 100644
--- a/InvenTree/order/api.py
+++ b/InvenTree/order/api.py
@@ -74,6 +74,7 @@ class POList(generics.ListCreateAPIView):
data = queryset.values(
'pk',
'supplier',
+ 'supplier_reference',
'supplier__name',
'supplier__image',
'reference',
diff --git a/InvenTree/order/forms.py b/InvenTree/order/forms.py
index c110dfadca..52c761e03e 100644
--- a/InvenTree/order/forms.py
+++ b/InvenTree/order/forms.py
@@ -69,6 +69,7 @@ class EditPurchaseOrderForm(HelperForm):
fields = [
'reference',
'supplier',
+ 'supplier_reference',
'description',
'link',
]
diff --git a/InvenTree/order/migrations/0019_purchaseorder_supplier_reference.py b/InvenTree/order/migrations/0019_purchaseorder_supplier_reference.py
new file mode 100644
index 0000000000..cf9cd345bc
--- /dev/null
+++ b/InvenTree/order/migrations/0019_purchaseorder_supplier_reference.py
@@ -0,0 +1,18 @@
+# Generated by Django 2.2.10 on 2020-04-15 03:31
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('order', '0018_auto_20200406_0151'),
+ ]
+
+ operations = [
+ migrations.AddField(
+ model_name='purchaseorder',
+ name='supplier_reference',
+ field=models.CharField(blank=True, help_text='Supplier order reference', max_length=64),
+ ),
+ ]
diff --git a/InvenTree/order/models.py b/InvenTree/order/models.py
index 9b569aa4cb..3a7d65abac 100644
--- a/InvenTree/order/models.py
+++ b/InvenTree/order/models.py
@@ -119,7 +119,7 @@ class PurchaseOrder(Order):
supplier: Reference to the company supplying the goods in the order
received_by: User that received the goods
"""
-
+
ORDER_PREFIX = "PO"
supplier = models.ForeignKey(
@@ -131,6 +131,8 @@ class PurchaseOrder(Order):
help_text=_('Company')
)
+ supplier_reference = models.CharField(max_length=64, blank=True, help_text=_("Supplier order reference"))
+
received_by = models.ForeignKey(
User,
on_delete=models.SET_NULL,
diff --git a/InvenTree/order/serializers.py b/InvenTree/order/serializers.py
index ae6ace2148..9a8f1afee5 100644
--- a/InvenTree/order/serializers.py
+++ b/InvenTree/order/serializers.py
@@ -19,6 +19,7 @@ class POSerializer(InvenTreeModelSerializer):
fields = [
'pk',
'supplier',
+ 'supplier_reference',
'reference',
'description',
'link',
diff --git a/InvenTree/order/templates/order/order_base.html b/InvenTree/order/templates/order/order_base.html
index 420f312310..03aa4c4ce2 100644
--- a/InvenTree/order/templates/order/order_base.html
+++ b/InvenTree/order/templates/order/order_base.html
@@ -63,15 +63,27 @@ InvenTree | {{ order }}
- |
- {% trans "Supplier" %} |
- {{ order.supplier }} |
+ |
+ {% trans "Order Reference" %} |
+ {{ order.reference }} |
|
- {% trans "Status" %} |
+ {% trans "Order Status" %} |
{% order_status order.status %} |
+
+ |
+ {% trans "Supplier" %} |
+ {{ order.supplier.name }} |
+
+ {% if order.supplier_reference %}
+
+ |
+ {% trans "Supplier Reference" %} |
+ {{ order.supplier_reference }} |
+
+ {% endif %}
{% if order.link %}
|
diff --git a/InvenTree/part/api.py b/InvenTree/part/api.py
index 7d193fa1ee..e36d4a568b 100644
--- a/InvenTree/part/api.py
+++ b/InvenTree/part/api.py
@@ -153,6 +153,7 @@ class PartList(generics.ListCreateAPIView):
The Part object list can be filtered by:
- category: Filter by PartCategory reference
- cascade: If true, include parts from sub-categories
+ - starred: Is the part "starred" by the current user?
- is_template: Is the part a template part?
- variant_of: Filter by variant_of Part reference
- assembly: Filter by assembly field
@@ -257,12 +258,18 @@ class PartList(generics.ListCreateAPIView):
# Filter items which have an 'in_stock' level higher than 'minimum_stock'
data = data.filter(Q(in_stock__gte=F('minimum_stock')))
+ # Get a list of the parts that this user has starred
+ starred_parts = [star.part.pk for star in self.request.user.starred_parts.all()]
+
# Reduce the number of lookups we need to do for the part categories
categories = {}
for item in data:
if item['image']:
+ # Is this part 'starred' for the current user?
+ item['starred'] = item['pk'] in starred_parts
+
img = item['image']
# Use the 'thumbnail' image here instead of the full-size image
@@ -294,32 +301,53 @@ class PartList(generics.ListCreateAPIView):
return Response(data)
def get_queryset(self):
-
- # Does the user wish to filter by category?
- cat_id = self.request.query_params.get('category', None)
+ """
+ Implement custom filtering for the Part list API
+ """
# Start with all objects
parts_list = Part.objects.all()
- cascade = str2bool(self.request.query_params.get('cascade', False))
+ # Filter by 'starred' parts?
+ starred = str2bool(self.request.query_params.get('starred', None))
+
+ if starred is not None:
+ starred_parts = [star.part.pk for star in self.request.user.starred_parts.all()]
+
+ if starred:
+ parts_list = parts_list.filter(pk__in=starred_parts)
+ else:
+ parts_list = parts_list.exclude(pk__in=starred_parts)
+
+ cascade = str2bool(self.request.query_params.get('cascade', None))
+
+ # Does the user wish to filter by category?
+ cat_id = self.request.query_params.get('category', None)
if cat_id is None:
- # Top-level parts
- if not cascade:
- parts_list = parts_list.filter(category=None)
-
+ # No category filtering if category is not specified
+ pass
+
else:
- try:
- category = PartCategory.objects.get(pk=cat_id)
+ # Category has been specified!
+ if isNull(cat_id):
+ # A 'null' category is the top-level category
+ if cascade is False:
+ # Do not cascade, only list parts in the top-level category
+ parts_list = parts_list.filter(category=None)
- # If '?cascade=true' then include parts which exist in sub-categories
- if cascade:
- parts_list = parts_list.filter(category__in=category.getUniqueChildren())
- # Just return parts directly in the requested category
- else:
- parts_list = parts_list.filter(category=cat_id)
- except (ValueError, PartCategory.DoesNotExist):
- pass
+ else:
+ try:
+ category = PartCategory.objects.get(pk=cat_id)
+
+ # If '?cascade=true' then include parts which exist in sub-categories
+ if cascade:
+ parts_list = parts_list.filter(category__in=category.getUniqueChildren())
+ # Just return parts directly in the requested category
+ else:
+ parts_list = parts_list.filter(category=cat_id)
+ except (ValueError, PartCategory.DoesNotExist):
+ pass
# Ensure that related models are pre-loaded to reduce DB trips
parts_list = self.get_serializer_class().setup_eager_loading(parts_list)
diff --git a/InvenTree/part/models.py b/InvenTree/part/models.py
index c182cc6583..ca5b8f11c2 100644
--- a/InvenTree/part/models.py
+++ b/InvenTree/part/models.py
@@ -478,11 +478,11 @@ class Part(models.Model):
""" Return a JSON string for formatting a barcode for this Part object """
return helpers.MakeBarcode(
- "Part",
- self.id,
- reverse('api-part-detail', kwargs={'pk': self.id}),
+ "part",
{
- 'name': self.name,
+ "id": self.id,
+ "name": self.full_name,
+ "url": reverse('api-part-detail', kwargs={'pk': self.id}),
}
)
diff --git a/InvenTree/part/serializers.py b/InvenTree/part/serializers.py
index d5270cabb2..788613e104 100644
--- a/InvenTree/part/serializers.py
+++ b/InvenTree/part/serializers.py
@@ -96,6 +96,8 @@ class PartSerializer(InvenTreeModelSerializer):
queryset = queryset.prefetch_related('builds')
return queryset
+ # TODO - Include a 'category_detail' field which serializers the category object
+
class Meta:
model = Part
partial = True
diff --git a/InvenTree/part/templates/part/category.html b/InvenTree/part/templates/part/category.html
index cc663a63c4..9382259cce 100644
--- a/InvenTree/part/templates/part/category.html
+++ b/InvenTree/part/templates/part/category.html
@@ -137,29 +137,30 @@
$("#cat-create").click(function() {
launchModalForm(
- "{% url 'category-create' %}",
- {
- follow: true,
- {% if category %}
- data: {
- category: {{ category.id }}
- },
- {% endif %}
- secondary: [
- {
- field: 'default_location',
- label: 'New Location',
- title: 'Create new location',
- url: "{% url 'stock-location-create' %}",
- },
- {
- field: 'parent',
- label: 'New Category',
- title: 'Create new category',
- url: "{% url 'category-create' %}",
- },
- ]
- });
+ "{% url 'category-create' %}",
+ {
+ follow: true,
+ {% if category %}
+ data: {
+ category: {{ category.id }}
+ },
+ {% endif %}
+ secondary: [
+ {
+ field: 'default_location',
+ label: 'New Location',
+ title: 'Create new location',
+ url: "{% url 'stock-location-create' %}",
+ },
+ {
+ field: 'parent',
+ label: 'New Category',
+ title: 'Create new category',
+ url: "{% url 'category-create' %}",
+ },
+ ]
+ }
+ );
})
$("#part-export").click(function() {
@@ -200,11 +201,11 @@
{% if category %}
$("#cat-edit").click(function () {
launchModalForm(
- "{% url 'category-edit' category.id %}",
- {
- reload: true
- },
- );
+ "{% url 'category-edit' category.id %}",
+ {
+ reload: true
+ },
+ );
return false;
});
@@ -227,9 +228,9 @@
"#part-table",
"{% url 'api-part-list' %}",
{
- query: {
- {% if category %}
- category: {{ category.id }},
+ params: {
+ {% if category %}category: {{ category.id }},
+ {% else %}category: "null",
{% endif %}
},
buttons: ['#part-options'],
diff --git a/InvenTree/part/templatetags/inventree_extras.py b/InvenTree/part/templatetags/inventree_extras.py
index e68e9c23dc..ab3b0694ac 100644
--- a/InvenTree/part/templatetags/inventree_extras.py
+++ b/InvenTree/part/templatetags/inventree_extras.py
@@ -70,7 +70,7 @@ def inventree_commit_date(*args, **kwargs):
@register.simple_tag()
def inventree_github_url(*args, **kwargs):
""" Return URL for InvenTree github site """
- return "https://github.com/InvenTree"
+ return "https://github.com/InvenTree/InvenTree/"
@register.simple_tag()
diff --git a/InvenTree/plugins/__init__.py b/InvenTree/plugins/__init__.py
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/InvenTree/plugins/action/__init__.py b/InvenTree/plugins/action/__init__.py
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/InvenTree/plugins/action/action.py b/InvenTree/plugins/action/action.py
new file mode 100644
index 0000000000..4e0b0f5cb0
--- /dev/null
+++ b/InvenTree/plugins/action/action.py
@@ -0,0 +1,87 @@
+# -*- coding: utf-8 -*-
+
+import plugins.plugin as plugin
+
+
+class ActionPlugin(plugin.InvenTreePlugin):
+ """
+ The ActionPlugin class is used to perform custom actions
+ """
+
+ ACTION_NAME = ""
+
+ @classmethod
+ def action_name(cls):
+ """
+ Return the action name for this plugin.
+ If the ACTION_NAME parameter is empty,
+ look at the PLUGIN_NAME instead.
+ """
+ action = cls.ACTION_NAME
+
+ if not action:
+ action = cls.PLUGIN_NAME
+
+ return action
+
+ def __init__(self, user, data=None):
+ """
+ An action plugin takes a user reference, and an optional dataset (dict)
+ """
+ plugin.InvenTreePlugin.__init__(self)
+
+ self.user = user
+ self.data = data
+
+ def perform_action(self):
+ """
+ Override this method to perform the action!
+ """
+ pass
+
+ def get_result(self):
+ """
+ Result of the action?
+ """
+
+ # Re-implement this for cutsom actions
+ return False
+
+ def get_info(self):
+ """
+ Extra info? Can be a string / dict / etc
+ """
+ return None
+
+ def get_response(self):
+ """
+ Return a response. Default implementation is a simple response
+ which can be overridden.
+ """
+ return {
+ "action": self.action_name(),
+ "result": self.get_result(),
+ "info": self.get_info(),
+ }
+
+
+class SimpleActionPlugin(ActionPlugin):
+ """
+ An EXTREMELY simple action plugin which demonstrates
+ the capability of the ActionPlugin class
+ """
+
+ PLUGIN_NAME = "SimpleActionPlugin"
+ ACTION_NAME = "simple"
+
+ def perform_action(self):
+ print("Action plugin in action!")
+
+ def get_info(self):
+ return {
+ "user": self.user.username,
+ "hello": "world",
+ }
+
+ def get_result(self):
+ return True
diff --git a/InvenTree/plugins/barcode/__init__.py b/InvenTree/plugins/barcode/__init__.py
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/InvenTree/plugins/barcode/barcode.py b/InvenTree/plugins/barcode/barcode.py
new file mode 100644
index 0000000000..f8bd82f744
--- /dev/null
+++ b/InvenTree/plugins/barcode/barcode.py
@@ -0,0 +1,81 @@
+# -*- coding: utf-8 -*-
+
+import hashlib
+
+from rest_framework.renderers import JSONRenderer
+
+from stock.serializers import StockItemSerializer, LocationSerializer
+from part.serializers import PartSerializer
+
+import plugins.plugin as plugin
+
+
+class BarcodePlugin(plugin.InvenTreePlugin):
+ """
+ The BarcodePlugin class is the base class for any barcode plugin.
+ """
+
+ def __init__(self, barcode_data):
+ plugin.InvenTreePlugin.__init__(self)
+
+ self.data = barcode_data
+
+ def hash(self):
+ """
+ Calculate a hash for the barcode data.
+ This is supposed to uniquely identify the barcode contents,
+ at least within the bardcode sub-type.
+
+ The default implementation simply returns an MD5 hash of the barcode data,
+ encoded to a string.
+
+ This may be sufficient for most applications, but can obviously be overridden
+ by a subclass.
+
+ """
+
+ hash = hashlib.md5(str(self.data).encode())
+ return str(hash.hexdigest())
+
+ def validate(self):
+ """
+ Default implementation returns False
+ """
+ return False
+
+ def decode(self):
+ """
+ Decode the barcode, and craft a response
+ """
+
+ return None
+
+ def render_part(self, part):
+ """
+ Render a Part object to JSON
+ Use the existing serializer to do this.
+ """
+
+ serializer = PartSerializer(part)
+
+ return serializer.data
+
+ def render_stock_location(self, loc):
+ """
+ Render a StockLocation object to JSON
+ Use the existing serializer to do this.
+ """
+
+ serializer = LocationSerializer(loc)
+
+ return serializer.data
+
+ def render_stock_item(self, item):
+ """
+ Render a StockItem object to JSON.
+ Use the existing serializer to do this
+ """
+
+ serializer = StockItemSerializer(item, part_detail=True, location_detail=True, supplier_detail=True)
+
+ return serializer.data
diff --git a/InvenTree/plugins/barcode/digikey.py b/InvenTree/plugins/barcode/digikey.py
new file mode 100644
index 0000000000..2542fe964a
--- /dev/null
+++ b/InvenTree/plugins/barcode/digikey.py
@@ -0,0 +1,8 @@
+# -*- coding: utf-8 -*-
+
+from . import barcode
+
+
+class DigikeyBarcodePlugin(barcode.BarcodePlugin):
+
+ PLUGIN_NAME = "DigikeyBarcodePlugin"
diff --git a/InvenTree/plugins/barcode/inventree.py b/InvenTree/plugins/barcode/inventree.py
new file mode 100644
index 0000000000..93b86d42b7
--- /dev/null
+++ b/InvenTree/plugins/barcode/inventree.py
@@ -0,0 +1,94 @@
+"""
+The InvenTreeBarcodePlugin validates barcodes generated by InvenTree itself.
+It can be used as a template for developing third-party barcode plugins.
+
+The data format is very simple, and maps directly to database objects,
+via the "id" parameter.
+
+Parsing an InvenTree barcode simply involves validating that the
+references model objects actually exist in the database.
+"""
+
+# -*- coding: utf-8 -*-
+
+import json
+
+from . import barcode
+
+from stock.models import StockItem, StockLocation
+from part.models import Part
+
+from django.utils.translation import ugettext as _
+
+
+class InvenTreeBarcodePlugin(barcode.BarcodePlugin):
+
+ PLUGIN_NAME = "InvenTreeBarcodePlugin"
+
+ def validate(self):
+ """
+ An "InvenTree" barcode must include the following tags:
+
+ {
+ 'tool': 'InvenTree',
+ 'version':
+ }
+
+ """
+
+ # The data must either be dict or be able to dictified
+ if type(self.data) is dict:
+ pass
+ elif type(self.data) is str:
+ try:
+ self.data = json.loads(self.data)
+ except json.JSONDecodeError:
+ return False
+ else:
+ return False
+
+ for key in ['tool', 'version']:
+ if key not in self.data.keys():
+ return False
+
+ if not self.data['tool'] == 'InvenTree':
+ return False
+
+ return True
+
+ def decode(self):
+
+ response = {}
+
+ if 'part' in self.data.keys():
+ id = self.data['part'].get('id', None)
+
+ try:
+ part = Part.objects.get(id=id)
+ response['part'] = self.render_part(part)
+ except (ValueError, Part.DoesNotExist):
+ response['error'] = _('Part does not exist')
+
+ elif 'stocklocation' in self.data.keys():
+ id = self.data['stocklocation'].get('id', None)
+
+ try:
+ loc = StockLocation.objects.get(id=id)
+ response['stocklocation'] = self.render_stock_location(loc)
+ except (ValueError, StockLocation.DoesNotExist):
+ response['error'] = _('StockLocation does not exist')
+
+ elif 'stockitem' in self.data.keys():
+
+ id = self.data['stockitem'].get('id', None)
+
+ try:
+ item = StockItem.objects.get(id=id)
+ response['stockitem'] = self.render_stock_item(item)
+ except (ValueError, StockItem.DoesNotExist):
+ response['error'] = _('StockItem does not exist')
+
+ else:
+ response['error'] = _('No matching data')
+
+ return response
diff --git a/InvenTree/plugins/plugin.py b/InvenTree/plugins/plugin.py
new file mode 100644
index 0000000000..11de4d1365
--- /dev/null
+++ b/InvenTree/plugins/plugin.py
@@ -0,0 +1,16 @@
+# -*- coding: utf-8 -*-
+
+
+class InvenTreePlugin():
+ """
+ Base class for a Barcode plugin
+ """
+
+ # Override the plugin name for each concrete plugin instance
+ PLUGIN_NAME = ''
+
+ def plugin_name(self):
+ return self.PLUGIN_NAME
+
+ def __init__(self):
+ pass
diff --git a/InvenTree/plugins/plugins.py b/InvenTree/plugins/plugins.py
new file mode 100644
index 0000000000..f913c1f295
--- /dev/null
+++ b/InvenTree/plugins/plugins.py
@@ -0,0 +1,87 @@
+# -*- coding: utf-8 -*-
+
+import inspect
+import importlib
+import pkgutil
+
+# Barcode plugins
+import plugins.barcode as barcode
+from plugins.barcode.barcode import BarcodePlugin
+
+# Action plugins
+import plugins.action as action
+from plugins.action.action import ActionPlugin
+
+
+def iter_namespace(pkg):
+
+ return pkgutil.iter_modules(pkg.__path__, pkg.__name__ + ".")
+
+
+def get_modules(pkg):
+ # Return all modules in a given package
+ return [importlib.import_module(name) for finder, name, ispkg in iter_namespace(pkg)]
+
+
+def get_classes(module):
+ # Return all classes in a given module
+ return inspect.getmembers(module, inspect.isclass)
+
+
+def get_plugins(pkg, baseclass):
+ """
+ Return a list of all modules under a given package.
+
+ - Modules must be a subclass of the provided 'baseclass'
+ - Modules must have a non-empty PLUGIN_NAME parameter
+ """
+
+ plugins = []
+
+ modules = get_modules(pkg)
+
+ # Iterate through each module in the package
+ for mod in modules:
+ # Iterate through each class in the module
+ for item in get_classes(mod):
+ plugin = item[1]
+ if issubclass(plugin, baseclass) and plugin.PLUGIN_NAME:
+ plugins.append(plugin)
+
+ return plugins
+
+
+def load_barcode_plugins():
+ """
+ Return a list of all registered barcode plugins
+ """
+
+ print("Loading barcode plugins")
+
+ plugins = get_plugins(barcode, BarcodePlugin)
+
+ if len(plugins) > 0:
+ print("Discovered {n} barcode plugins:".format(n=len(plugins)))
+
+ for bp in plugins:
+ print(" - {bp}".format(bp=bp.PLUGIN_NAME))
+
+ return plugins
+
+
+def load_action_plugins():
+ """
+ Return a list of all registered action plugins
+ """
+
+ print("Loading action plugins")
+
+ plugins = get_plugins(action, ActionPlugin)
+
+ if len(plugins) > 0:
+ print("Discovered {n} action plugins:".format(n=len(plugins)))
+
+ for ap in plugins:
+ print(" - {ap}".format(ap=ap.PLUGIN_NAME))
+
+ return plugins
diff --git a/InvenTree/stock/api.py b/InvenTree/stock/api.py
index b9132ab557..9f485ba5f7 100644
--- a/InvenTree/stock/api.py
+++ b/InvenTree/stock/api.py
@@ -344,6 +344,7 @@ class StockList(generics.ListCreateAPIView):
data = queryset.values(
'pk',
+ 'uid',
'parent',
'quantity',
'serial',
@@ -540,7 +541,7 @@ class StockList(generics.ListCreateAPIView):
'supplier_part',
'customer',
'belongs_to',
- 'build'
+ 'build',
]
diff --git a/InvenTree/stock/migrations/0026_stockitem_uid.py b/InvenTree/stock/migrations/0026_stockitem_uid.py
new file mode 100644
index 0000000000..c00e858815
--- /dev/null
+++ b/InvenTree/stock/migrations/0026_stockitem_uid.py
@@ -0,0 +1,18 @@
+# Generated by Django 2.2.10 on 2020-04-14 12:53
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('stock', '0025_auto_20200405_2243'),
+ ]
+
+ operations = [
+ migrations.AddField(
+ model_name='stockitem',
+ name='uid',
+ field=models.CharField(blank=True, help_text='Unique identifier field', max_length=128),
+ ),
+ ]
diff --git a/InvenTree/stock/models.py b/InvenTree/stock/models.py
index ff0cf7b21a..51b61ff3fd 100644
--- a/InvenTree/stock/models.py
+++ b/InvenTree/stock/models.py
@@ -44,11 +44,11 @@ class StockLocation(InvenTreeTree):
""" Return a JSON string for formatting a barcode for this StockLocation object """
return helpers.MakeBarcode(
- 'StockLocation',
- self.id,
- reverse('api-location-detail', kwargs={'pk': self.id}),
+ 'stocklocation',
{
- 'name': self.name,
+ "id": self.id,
+ "name": self.name,
+ "url": reverse('api-location-detail', kwargs={'pk': self.id}),
}
)
@@ -108,6 +108,7 @@ class StockItem(MPTTModel):
Attributes:
parent: Link to another StockItem from which this StockItem was created
+ uid: Field containing a unique-id which is mapped to a third-party identifier (e.g. a barcode)
part: Link to the master abstract part that this StockItem is an instance of
supplier_part: Link to a specific SupplierPart (optional)
location: Where this StockItem is located
@@ -288,15 +289,15 @@ class StockItem(MPTTModel):
"""
return helpers.MakeBarcode(
- 'StockItem',
- self.id,
- reverse('api-stock-detail', kwargs={'pk': self.id}),
+ "stockitem",
{
- 'part_id': self.part.id,
- 'part_name': self.part.full_name
+ "id": self.id,
+ "url": reverse('api-stock-detail', kwargs={'pk': self.id}),
}
)
+ uid = models.CharField(blank=True, max_length=128, help_text=("Unique identifier field"))
+
parent = TreeForeignKey('self',
on_delete=models.DO_NOTHING,
blank=True, null=True,
diff --git a/InvenTree/stock/serializers.py b/InvenTree/stock/serializers.py
index ce4041fec3..fe4f850658 100644
--- a/InvenTree/stock/serializers.py
+++ b/InvenTree/stock/serializers.py
@@ -39,6 +39,7 @@ class StockItemSerializerBrief(InvenTreeModelSerializer):
model = StockItem
fields = [
'pk',
+ 'uid',
'part',
'part_name',
'supplier_part',
@@ -106,6 +107,7 @@ class StockItemSerializer(InvenTreeModelSerializer):
'status',
'status_text',
'tracking_items',
+ 'uid',
'url',
]
diff --git a/InvenTree/stock/templates/stock/item_base.html b/InvenTree/stock/templates/stock/item_base.html
index 46e26b6ff1..9785b78850 100644
--- a/InvenTree/stock/templates/stock/item_base.html
+++ b/InvenTree/stock/templates/stock/item_base.html
@@ -85,7 +85,7 @@
{% if item.belongs_to %}
- |
+ |
{% trans "Belongs To" %} |
{{ item.belongs_to }} |
@@ -96,6 +96,13 @@
{{ item.location.name }} |
{% endif %}
+ {% if item.uid %}
+
+ |
+ {% trans "Unique Identifier" %} |
+ {{ item.uid }} |
+
+ {% endif %}
{% if item.serialized %}
|
diff --git a/InvenTree/templates/InvenTree/index.html b/InvenTree/templates/InvenTree/index.html
index c4eb5990cc..570378e55d 100644
--- a/InvenTree/templates/InvenTree/index.html
+++ b/InvenTree/templates/InvenTree/index.html
@@ -9,13 +9,7 @@ InvenTree | Index
{% include "InvenTree/starred_parts.html" with collapse_id="starred" %}
-{% if to_order %}
-{% include "InvenTree/parts_to_order.html" with collapse_id="order" %}
-{% endif %}
-
-{% if to_build %}
-{% include "InvenTree/parts_to_build.html" with collapse_id="build" %}
-{% endif %}
+{% include "InvenTree/low_stock.html" with collapse_id="order" %}
{% endblock %}
@@ -25,15 +19,31 @@ InvenTree | Index
{% block js_ready %}
-console.log("abcde?");
-
{{ block.super }}
-//TODO: These calls to bootstrapTable() are failing, for some reason?
-//$("#to-build-table").bootstrapTable();
-//$("#to-order-table").bootstrapTable();
-//$("#starred-parts-table").bootstrapTable();
+loadPartTable("#starred-parts-table", "{% url 'api-part-list' %}", {
+ params: {
+ "starred": true,
+ }
+});
+
+loadPartTable("#low-stock-table", "{% url 'api-part-list' %}", {
+ params: {
+ "low_stock": true,
+ }
+});
+
+$("#starred-parts-table").on('load-success.bs.table', function() {
+ var count = $("#starred-parts-table").bootstrapTable('getData').length;
+
+ $("#starred-parts-count").html(count);
+});
+
+$("#low-stock-table").on('load-success.bs.table', function() {
+ var count = $("#low-stock-table").bootstrapTable('getData').length;
+
+ $("#low-stock-count").html(count);
+});
-console.log("Got to here...");
{% endblock %}
\ No newline at end of file
diff --git a/InvenTree/templates/InvenTree/low_stock.html b/InvenTree/templates/InvenTree/low_stock.html
new file mode 100644
index 0000000000..edafab1756
--- /dev/null
+++ b/InvenTree/templates/InvenTree/low_stock.html
@@ -0,0 +1,15 @@
+{% extends "collapse.html" %}
+
+{% load i18n %}
+
+{% block collapse_title %}
+
+{% trans "Low Stock" %}0
+{% endblock %}
+
+{% block collapse_content %}
+
+
+
+{% endblock %}
\ No newline at end of file
diff --git a/InvenTree/templates/InvenTree/parts_to_order.html b/InvenTree/templates/InvenTree/parts_to_order.html
deleted file mode 100644
index 5d2c3472b4..0000000000
--- a/InvenTree/templates/InvenTree/parts_to_order.html
+++ /dev/null
@@ -1,15 +0,0 @@
-{% extends "collapse.html" %}
-{% block collapse_title %}
-
-Parts to Order{{ to_order | length }}
-{% endblock %}
-
-{% block collapse_heading %}
-There are {{ to_order | length }} parts which need to be ordered.
-{% endblock %}
-
-{% block collapse_content %}
-
-{% include "required_part_table.html" with parts=to_order table_id="to-order-table" %}
-
-{% endblock %}
\ No newline at end of file
diff --git a/InvenTree/templates/InvenTree/search.html b/InvenTree/templates/InvenTree/search.html
index e8cda96809..76fd62b697 100644
--- a/InvenTree/templates/InvenTree/search.html
+++ b/InvenTree/templates/InvenTree/search.html
@@ -104,6 +104,7 @@ InvenTree | {% trans "Search Results" %}
],
});
+
$("#location-results-table").inventreeTable({
url: "{% url 'api-location-list' %}",
queryParams: {
@@ -124,20 +125,22 @@ InvenTree | {% trans "Search Results" %}
],
});
+
loadPartTable("#part-results-table",
"{% url 'api-part-list' %}",
{
- query: {
+ params: {
search: "{{ query }}",
},
- allowInactive: true,
checkbox: false,
+ disableFilters: true,
}
);
+
loadCompanyTable('#company-results-table', "{% url 'api-company-list' %}", {
params: {
- serach: "{{ query }}",
+ search: "{{ query }}",
}
});
@@ -153,5 +156,5 @@ InvenTree | {% trans "Search Results" %}
},
}
);
-
+
{% endblock %}
\ No newline at end of file
diff --git a/InvenTree/templates/InvenTree/search_parts.html b/InvenTree/templates/InvenTree/search_parts.html
index 69c5c29051..ca75b096c2 100644
--- a/InvenTree/templates/InvenTree/search_parts.html
+++ b/InvenTree/templates/InvenTree/search_parts.html
@@ -9,6 +9,13 @@
{% endblock %}
{% block collapse_content %}
+
+
{% endblock %}
\ No newline at end of file
diff --git a/InvenTree/templates/InvenTree/starred_parts.html b/InvenTree/templates/InvenTree/starred_parts.html
index 091afde064..f13987e3c5 100644
--- a/InvenTree/templates/InvenTree/starred_parts.html
+++ b/InvenTree/templates/InvenTree/starred_parts.html
@@ -1,15 +1,15 @@
{% extends "collapse.html" %}
+
+{% load i18n %}
+
{% block collapse_title %}
-Starred Parts{{ starred | length }}
-{% endblock %}
-
-{% block collapse_heading %}
-You have {{ starred | length }} favourite parts
+{% trans "Starred Parts" %}0
{% endblock %}
{% block collapse_content %}
-{% include "required_part_table.html" with parts=starred table_id="starred-parts-table" %}
+
{% endblock %}
\ No newline at end of file
diff --git a/InvenTree/templates/base.html b/InvenTree/templates/base.html
index 3cae9fd37b..8559e6d5f1 100644
--- a/InvenTree/templates/base.html
+++ b/InvenTree/templates/base.html
@@ -102,6 +102,7 @@ InvenTree
+
diff --git a/InvenTree/templates/table_filters.html b/InvenTree/templates/table_filters.html
index e3dd78be19..f976e977a6 100644
--- a/InvenTree/templates/table_filters.html
+++ b/InvenTree/templates/table_filters.html
@@ -89,6 +89,10 @@ function getAvailableTableFilters(tableKey) {
type: 'bool',
title: '{% trans "Component" %}',
},
+ starred: {
+ type: 'bool',
+ title: '{% trans "Starred" %}',
+ },
};
}
diff --git a/docs/start.rst b/docs/start.rst
index 1b389d7e5b..45a32ffb0b 100644
--- a/docs/start.rst
+++ b/docs/start.rst
@@ -17,10 +17,16 @@ Requirements
To install InvenTree you will need the following system components installed:
* python3
+* python3-dev
* python3-pip (pip3)
+* g++
* make
-Each of these programs need to be installed (e.g. using apt or similar) before running the ``make install`` script.
+Each of these programs need to be installed (e.g. using apt or similar) before running the ``make install`` script:
+
+```
+sudo apt-get install python3 python3-dev python3-pip g++ make
+```
Virtual Environment
-------------------
@@ -115,4 +121,4 @@ Other shorthand functions are provided for the development and testing process:
* ``make coverage`` - Run all unit tests and generate code coverage report
* ``make style`` - Check Python codebase against PEP coding standards (using Flake)
* ``make docreqs`` - Install the packages required to generate documentation
-* ``make docs`` - Generate this documentation
\ No newline at end of file
+* ``make docs`` - Generate this documentation
diff --git a/requirements.txt b/requirements.txt
index ff65664282..4eace551ea 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -1,4 +1,5 @@
-Django==2.2.10 # Django package
+wheel>=0.34.2 # Wheel
+Django==2.2.10 # Django package
pillow==6.2.0 # Image manipulation
djangorestframework==3.10.3 # DRF framework
django-cors-headers==3.2.0 # CORS headers extension for DRF