From 7af2bb4e8c58565a8d4992a03f98f2ee6f2361c5 Mon Sep 17 00:00:00 2001 From: Oliver Date: Tue, 4 Apr 2023 11:30:49 +1000 Subject: [PATCH] Order barcodes (#4575) * Add barcode support to external orders - ReturnOrder - PurchaseOrder - SalesOrder * Support scanning for new model types * Integrate UI elements for ReturnOrder * Update PurchaseOrder page * SalesOrder implementation --- .../templates/company/supplier_part.html | 8 +-- .../migrations/0089_auto_20230404_0030.py | 43 ++++++++++++++++ InvenTree/order/models.py | 5 +- InvenTree/order/serializers.py | 3 ++ .../order/templates/order/order_base.html | 47 +++++++++++++++++ .../templates/order/return_order_base.html | 50 +++++++++++++++++++ .../templates/order/sales_order_base.html | 48 ++++++++++++++++++ InvenTree/part/templates/part/part_base.html | 8 +-- .../builtin/barcodes/inventree_barcode.py | 18 ++++--- .../stock/templates/stock/item_base.html | 11 ++-- InvenTree/stock/templates/stock/location.html | 8 +-- InvenTree/templates/barcode_data.html | 10 ++++ 12 files changed, 221 insertions(+), 38 deletions(-) create mode 100644 InvenTree/order/migrations/0089_auto_20230404_0030.py create mode 100644 InvenTree/templates/barcode_data.html diff --git a/InvenTree/company/templates/company/supplier_part.html b/InvenTree/company/templates/company/supplier_part.html index 8ecf4b1ece..7bb9f06560 100644 --- a/InvenTree/company/templates/company/supplier_part.html +++ b/InvenTree/company/templates/company/supplier_part.html @@ -116,13 +116,7 @@ src="{% static 'img/blank_image.png' %}" {% decimal part.available %}{% render_date part.availability_updated %} {% endif %} - {% if part.barcode_hash %} - - - {% trans "Barcode Identifier" %} - {{ part.barcode_hash }} - - {% endif %} + {% include "barcode_data.html" with instance=part %} {% endblock details %} diff --git a/InvenTree/order/migrations/0089_auto_20230404_0030.py b/InvenTree/order/migrations/0089_auto_20230404_0030.py new file mode 100644 index 0000000000..a28439003b --- /dev/null +++ b/InvenTree/order/migrations/0089_auto_20230404_0030.py @@ -0,0 +1,43 @@ +# Generated by Django 3.2.18 on 2023-04-04 00:30 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('order', '0088_auto_20230403_1402'), + ] + + operations = [ + migrations.AddField( + model_name='purchaseorder', + name='barcode_data', + field=models.CharField(blank=True, help_text='Third party barcode data', max_length=500, verbose_name='Barcode Data'), + ), + migrations.AddField( + model_name='purchaseorder', + name='barcode_hash', + field=models.CharField(blank=True, help_text='Unique hash of barcode data', max_length=128, verbose_name='Barcode Hash'), + ), + migrations.AddField( + model_name='returnorder', + name='barcode_data', + field=models.CharField(blank=True, help_text='Third party barcode data', max_length=500, verbose_name='Barcode Data'), + ), + migrations.AddField( + model_name='returnorder', + name='barcode_hash', + field=models.CharField(blank=True, help_text='Unique hash of barcode data', max_length=128, verbose_name='Barcode Hash'), + ), + migrations.AddField( + model_name='salesorder', + name='barcode_data', + field=models.CharField(blank=True, help_text='Third party barcode data', max_length=500, verbose_name='Barcode Data'), + ), + migrations.AddField( + model_name='salesorder', + name='barcode_hash', + field=models.CharField(blank=True, help_text='Unique hash of barcode data', max_length=128, verbose_name='Barcode Hash'), + ), + ] diff --git a/InvenTree/order/models.py b/InvenTree/order/models.py index a6424973e3..3ec7c82b72 100644 --- a/InvenTree/order/models.py +++ b/InvenTree/order/models.py @@ -35,7 +35,8 @@ from InvenTree.exceptions import log_error from InvenTree.fields import (InvenTreeModelMoneyField, InvenTreeNotesField, InvenTreeURLField, RoundingDecimalField) from InvenTree.helpers import decimal2string, getSetting, notify_responsible -from InvenTree.models import InvenTreeAttachment, ReferenceIndexingMixin +from InvenTree.models import (InvenTreeAttachment, InvenTreeBarcodeMixin, + ReferenceIndexingMixin) from InvenTree.status_codes import (PurchaseOrderStatus, ReturnOrderLineStatus, ReturnOrderStatus, SalesOrderStatus, StockHistoryCode, StockStatus) @@ -130,7 +131,7 @@ class TotalPriceMixin(models.Model): return total -class Order(MetadataMixin, ReferenceIndexingMixin): +class Order(InvenTreeBarcodeMixin, MetadataMixin, ReferenceIndexingMixin): """Abstract model for an order. Instances of this class: diff --git a/InvenTree/order/serializers.py b/InvenTree/order/serializers.py index 494826b5bf..9f188c2fd9 100644 --- a/InvenTree/order/serializers.py +++ b/InvenTree/order/serializers.py @@ -66,6 +66,8 @@ class AbstractOrderSerializer(serializers.Serializer): # Boolean field indicating if this order is overdue (Note: must be annotated) overdue = serializers.BooleanField(required=False, read_only=True) + barcode_hash = serializers.CharField(read_only=True) + def validate_reference(self, reference): """Custom validation for the reference field""" @@ -101,6 +103,7 @@ class AbstractOrderSerializer(serializers.Serializer): 'status', 'status_text', 'notes', + 'barcode_hash', 'overdue', ] + extra_fields diff --git a/InvenTree/order/templates/order/order_base.html b/InvenTree/order/templates/order/order_base.html index aafe96d1c0..3049edf0f1 100644 --- a/InvenTree/order/templates/order/order_base.html +++ b/InvenTree/order/templates/order/order_base.html @@ -23,6 +23,24 @@ {% url 'admin:order_purchaseorder_change' order.pk as url %} {% include "admin_button.html" with url=url %} {% endif %} +{% if barcodes %} + +
+ + +
+{% endif %}
+ +
+{% endif %}
+ +
+{% endif %}
diff --git a/InvenTree/plugin/builtin/barcodes/inventree_barcode.py b/InvenTree/plugin/builtin/barcodes/inventree_barcode.py index 36a253086e..fd92101ace 100644 --- a/InvenTree/plugin/builtin/barcodes/inventree_barcode.py +++ b/InvenTree/plugin/builtin/barcodes/inventree_barcode.py @@ -11,12 +11,13 @@ import json from django.utils.translation import gettext_lazy as _ -from company.models import SupplierPart +import company.models +import order.models +import part.models +import stock.models from InvenTree.helpers import hash_barcode -from part.models import Part from plugin import InvenTreePlugin from plugin.mixins import BarcodeMixin -from stock.models import StockItem, StockLocation class InvenTreeInternalBarcodePlugin(BarcodeMixin, InvenTreePlugin): @@ -33,10 +34,13 @@ class InvenTreeInternalBarcodePlugin(BarcodeMixin, InvenTreePlugin): """Returns a list of database models which support barcode functionality""" return [ - Part, - StockItem, - StockLocation, - SupplierPart, + company.models.SupplierPart, + order.models.PurchaseOrder, + order.models.ReturnOrder, + order.models.SalesOrder, + part.models.Part, + stock.models.StockItem, + stock.models.StockLocation, ] def format_matched_response(self, label, model, instance): diff --git a/InvenTree/stock/templates/stock/item_base.html b/InvenTree/stock/templates/stock/item_base.html index 369a50454a..316db8bfef 100644 --- a/InvenTree/stock/templates/stock/item_base.html +++ b/InvenTree/stock/templates/stock/item_base.html @@ -155,13 +155,8 @@ - {% if item.barcode_hash %} - - - {% trans "Barcode Identifier" %} - {{ item.barcode_hash }} - - {% endif %} + {% include "barcode_data.html" with instance=item %} + {% if item.batch %} @@ -537,6 +532,7 @@ $('#stock-edit-status').click(function () { {% endif %} +{% if barcodes %} $("#show-qr-code").click(function() { showQRDialog( '{% trans "Stock Item QR Code" %}', @@ -544,7 +540,6 @@ $("#show-qr-code").click(function() { ); }); -{% if barcodes %} $("#barcode-link").click(function() { linkBarcodeDialog( { diff --git a/InvenTree/stock/templates/stock/location.html b/InvenTree/stock/templates/stock/location.html index de742fa7ee..f631c1b6ff 100644 --- a/InvenTree/stock/templates/stock/location.html +++ b/InvenTree/stock/templates/stock/location.html @@ -150,13 +150,7 @@ {% endif %} - {% if location and location.barcode_hash %} - - - {% trans "Barcode Identifier" %} - {{ location.barcode_hash }} - - {% endif %} + {% include "barcode_data.html" with instance=location %} {% endblock details_left %} diff --git a/InvenTree/templates/barcode_data.html b/InvenTree/templates/barcode_data.html new file mode 100644 index 0000000000..4e95bbd9d1 --- /dev/null +++ b/InvenTree/templates/barcode_data.html @@ -0,0 +1,10 @@ +{% load i18n %} +{% if instance and instance.barcode_hash %} + + + {% trans "Barcode Identifier" %} + + {{ instance.barcode_hash}} + + +{% endif %}