From 84d2d2e45b22a078e440d218d9170b985f433195 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Fri, 12 Apr 2019 22:43:22 +1000 Subject: [PATCH 1/7] Changed 'stocklocation.items' to 'stocklocation.stock_items' --- InvenTree/stock/models.py | 6 +++--- InvenTree/stock/templates/stock/location_delete.html | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/InvenTree/stock/models.py b/InvenTree/stock/models.py index d0f7fd3f38..b020640497 100644 --- a/InvenTree/stock/models.py +++ b/InvenTree/stock/models.py @@ -27,19 +27,19 @@ class StockLocation(InvenTreeTree): return '/stock/location/{id}/'.format(id=self.id) @property - def items(self): + def stock_items(self): return self.stockitem_set.all() @property def has_items(self): - return self.items.count() > 0 + return self.stock_items.count() > 0 @receiver(pre_delete, sender=StockLocation, dispatch_uid='stocklocation_delete_log') def before_delete_stock_location(sender, instance, using, **kwargs): # Update each part in the stock location - for item in instance.items.all(): + for item in instance.stock_items.all(): item.location = instance.parent item.save() diff --git a/InvenTree/stock/templates/stock/location_delete.html b/InvenTree/stock/templates/stock/location_delete.html index 53cdf2cc27..6c3ee981e5 100644 --- a/InvenTree/stock/templates/stock/location_delete.html +++ b/InvenTree/stock/templates/stock/location_delete.html @@ -19,8 +19,8 @@ the top level 'Stock' location. {% endif %} -{% if location.items.all|length > 0 %} -

This location contains {{ location.items.all|length }} stock items.
+{% if location.stock_items.all|length > 0 %} +

This location contains {{ location.stock_items.all|length }} stock items.
{% if location.parent %} If this location is deleted, these items will be moved to the '{{ location.parent.name }}' location. {% else %} @@ -29,7 +29,7 @@ If this location is deleted, these items will be moved to the top level 'Stock'

From 1b5287307b5a7a08d5c00c10f518f94810afd601 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Sat, 13 Apr 2019 00:52:26 +1000 Subject: [PATCH 2/7] Add some help text --- InvenTree/stock/forms.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/InvenTree/stock/forms.py b/InvenTree/stock/forms.py index 26f81ba958..cccf265605 100644 --- a/InvenTree/stock/forms.py +++ b/InvenTree/stock/forms.py @@ -38,7 +38,7 @@ class CreateStockItemForm(HelperForm): class MoveStockItemForm(forms.ModelForm): - note = forms.CharField(label='Notes', required=True) + note = forms.CharField(label='Notes', required=True, help_text='Add note (required)') class Meta: model = StockItem From dffb2b4dbe0cb758fe9436e6eb3a84d88b497c2f Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Sat, 13 Apr 2019 01:01:09 +1000 Subject: [PATCH 3/7] Added base requirement for django-qr-code --- requirements/base.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/requirements/base.txt b/requirements/base.txt index 5c0ec6f74f..03e725b7ec 100644 --- a/requirements/base.txt +++ b/requirements/base.txt @@ -7,4 +7,5 @@ coreapi>=2.3.0 pygments>=2.2.0 django-crispy-forms>=1.7.2 django-import-export>=1.0.0 -django-cleanup>=2.1.0 \ No newline at end of file +django-cleanup>=2.1.0 +django-qr-code==1.0.0 From b0f42fd30f9610e23d63c0213c096d0e338d989a Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Sat, 13 Apr 2019 01:03:56 +1000 Subject: [PATCH 4/7] Add qr_code to list of installed addons --- InvenTree/InvenTree/settings.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/InvenTree/InvenTree/settings.py b/InvenTree/InvenTree/settings.py index a4386800a9..ced66b2166 100644 --- a/InvenTree/InvenTree/settings.py +++ b/InvenTree/InvenTree/settings.py @@ -54,12 +54,14 @@ INSTALLED_APPS = [ 'company.apps.CompanyConfig', 'build.apps.BuildConfig', + # Third part add-ons 'django_filters', 'rest_framework', 'simple_history', 'crispy_forms', 'import_export', 'django_cleanup', + 'qr_code', ] MIDDLEWARE = [ From b64e584b52e1378c457e314fabc9249791db7e70 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Sat, 13 Apr 2019 01:12:47 +1000 Subject: [PATCH 5/7] Add UUID field to StockItem model --- .../stock/migrations/0006_stockitem_uuid.py | 19 +++++++++++++++++++ InvenTree/stock/models.py | 4 ++++ 2 files changed, 23 insertions(+) create mode 100644 InvenTree/stock/migrations/0006_stockitem_uuid.py diff --git a/InvenTree/stock/migrations/0006_stockitem_uuid.py b/InvenTree/stock/migrations/0006_stockitem_uuid.py new file mode 100644 index 0000000000..4d358e7201 --- /dev/null +++ b/InvenTree/stock/migrations/0006_stockitem_uuid.py @@ -0,0 +1,19 @@ +# Generated by Django 2.2 on 2019-04-12 15:06 + +from django.db import migrations, models +import uuid + + +class Migration(migrations.Migration): + + dependencies = [ + ('stock', '0005_stockitemtracking_quantity'), + ] + + operations = [ + migrations.AddField( + model_name='stockitem', + name='uuid', + field=models.UUIDField(blank=True, default=uuid.uuid4, editable=False), + ), + ] diff --git a/InvenTree/stock/models.py b/InvenTree/stock/models.py index 31c48887ba..727a211d0c 100644 --- a/InvenTree/stock/models.py +++ b/InvenTree/stock/models.py @@ -11,6 +11,7 @@ from django.db.models.signals import pre_delete from django.dispatch import receiver from datetime import datetime +import uuid from InvenTree.models import InvenTreeTree @@ -116,6 +117,9 @@ class StockItem(models.Model): ('part', 'serial'), ] + # UUID for generating QR codes + uuid = models.UUIDField(default=uuid.uuid4, blank=True, editable=False) + # The 'master' copy of the part of which this stock item is an instance part = models.ForeignKey('part.Part', on_delete=models.CASCADE, related_name='locations') From 7b68bac32f9c297df5973987a79816b3ac6a457d Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Sat, 13 Apr 2019 01:14:24 +1000 Subject: [PATCH 6/7] Display UUID and QR code on stockitem page - The actual display of this can be improved upon at a later stage --- InvenTree/stock/templates/stock/item.html | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/InvenTree/stock/templates/stock/item.html b/InvenTree/stock/templates/stock/item.html index b00b77ecac..7f6673621c 100644 --- a/InvenTree/stock/templates/stock/item.html +++ b/InvenTree/stock/templates/stock/item.html @@ -2,6 +2,8 @@ {% load static %} {% block content %} +{% load qr_code %} +

Stock Item Details

@@ -29,11 +31,17 @@
+{% qr_from_text item.uuid size="s" image_format="png" error_correction="L" %} + + + + + {% if item.belongs_to %} From 51d77ce4d2382edb9a8fd2cd07b3854aa8beeaa5 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Sat, 13 Apr 2019 07:56:06 +1000 Subject: [PATCH 7/7] Include uuid in serializer and api --- InvenTree/stock/api.py | 1 + InvenTree/stock/serializers.py | 1 + 2 files changed, 2 insertions(+) diff --git a/InvenTree/stock/api.py b/InvenTree/stock/api.py index d2c1c13805..fc3d3f023b 100644 --- a/InvenTree/stock/api.py +++ b/InvenTree/stock/api.py @@ -222,6 +222,7 @@ class StockList(generics.ListCreateAPIView): filter_fields = [ 'part', + 'uuid', 'location', 'supplier_part', 'customer', diff --git a/InvenTree/stock/serializers.py b/InvenTree/stock/serializers.py index 9105e78dce..f143162e7a 100644 --- a/InvenTree/stock/serializers.py +++ b/InvenTree/stock/serializers.py @@ -60,6 +60,7 @@ class StockItemSerializer(serializers.ModelSerializer): model = StockItem fields = [ 'pk', + 'uuid', 'url', 'part', 'supplier_part',
Part {{ item.part.name }}
UUID{{ item.uuid }}
Belongs To