mirror of
https://github.com/inventree/InvenTree.git
synced 2025-06-14 19:15:41 +00:00
QR code improvements
- Display QR codes as links to served images - The qr_code plugin caches these images in the background - Make a qr_code template to push out as a modal form - Create a QRCodeView to simplify display of QR codes - Add option to launchModalForm() to disable the 'submit' button Refactored QR code display for - StockLocation - StockItem - Part
This commit is contained in:
@ -36,7 +36,6 @@ class StockLocation(InvenTreeTree):
|
||||
def has_items(self):
|
||||
return self.stock_items.count() > 0
|
||||
|
||||
@property
|
||||
def format_barcode(self):
|
||||
""" Return a JSON string for formatting a barcode for this StockLocation object """
|
||||
|
||||
@ -139,7 +138,6 @@ class StockItem(models.Model):
|
||||
('part', 'serial'),
|
||||
]
|
||||
|
||||
@property
|
||||
def format_barcode(self):
|
||||
""" Return a JSON string for formatting a barcode for this StockItem.
|
||||
Can be used to perform lookup of a stockitem using barcode
|
||||
|
@ -2,8 +2,6 @@
|
||||
{% load static %}
|
||||
{% block content %}
|
||||
|
||||
{% load qr_code %}
|
||||
|
||||
<div class='row'>
|
||||
<div class='col-sm-6'>
|
||||
<h3>Stock Item Details</h3>
|
||||
@ -25,6 +23,8 @@
|
||||
<li><a href='#' id='stock-stocktake' title='Count stock'>Stocktake</a></li>
|
||||
{% endif %}
|
||||
<li><a href="#" id='stock-delete' title='Delete stock item'>Delete stock item</a></li>
|
||||
<hr>
|
||||
<li><a href="#" id='item-qr-code' title='Generate QR code'>Show QR code</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
@ -109,9 +109,6 @@
|
||||
{% endif %}
|
||||
</table>
|
||||
</div>
|
||||
<div class='col-sm-6'>
|
||||
{% qr_from_text item.format_barcode size="s" image_format="png" error_correction="L" %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
@ -148,6 +145,13 @@
|
||||
});
|
||||
});
|
||||
|
||||
$("#item-qr-code").click(function() {
|
||||
launchModalForm("{% url 'stock-item-qr' item.id %}",
|
||||
{
|
||||
no_post: true,
|
||||
});
|
||||
});
|
||||
|
||||
{% if item.in_stock %}
|
||||
$("#stock-move").click(function() {
|
||||
launchModalForm(
|
||||
|
@ -1,6 +1,5 @@
|
||||
{% extends "stock/stock_app_base.html" %}
|
||||
{% load static %}
|
||||
{% load qr_code %}
|
||||
{% block content %}
|
||||
|
||||
<div class='row'>
|
||||
@ -24,12 +23,13 @@
|
||||
<ul class="dropdown-menu">
|
||||
<li><a href="#" id='location-edit' title='Edit stock location'>Edit</a></li>
|
||||
<li><a href="#" id='location-delete' title='Delete stock location'>Delete</a></li>
|
||||
<hr>
|
||||
<li><a href="#" id='location-qr-code' title='Generate QR code'>Show QR code</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
{% qr_from_text location.format_barcode size="s" image_format="png" error_correction="L" %}
|
||||
{% endif %}
|
||||
</div>
|
||||
</h3>
|
||||
</div>
|
||||
</h3>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -101,6 +101,13 @@
|
||||
return false;
|
||||
});
|
||||
|
||||
$('#location-qr-code').click(function() {
|
||||
launchModalForm("{% url 'stock-location-qr' location.id %}",
|
||||
{
|
||||
no_post: true,
|
||||
});
|
||||
});
|
||||
|
||||
{% endif %}
|
||||
|
||||
$('#item-create').click(function () {
|
||||
@ -170,5 +177,4 @@
|
||||
},
|
||||
url: "{% url 'api-stock-list' %}",
|
||||
});
|
||||
|
||||
{% endblock %}
|
||||
|
@ -10,6 +10,7 @@ from . import views
|
||||
stock_location_detail_urls = [
|
||||
url(r'^edit/?', views.StockLocationEdit.as_view(), name='stock-location-edit'),
|
||||
url(r'^delete/?', views.StockLocationDelete.as_view(), name='stock-location-delete'),
|
||||
url(r'^qr_code/?', views.StockLocationQRCode.as_view(), name='stock-location-qr'),
|
||||
|
||||
# Anything else
|
||||
url('^.*$', views.StockLocationDetail.as_view(), name='stock-location-detail'),
|
||||
@ -20,6 +21,7 @@ stock_item_detail_urls = [
|
||||
url(r'^delete/?', views.StockItemDelete.as_view(), name='stock-item-delete'),
|
||||
url(r'^move/?', views.StockItemMove.as_view(), name='stock-item-move'),
|
||||
url(r'^stocktake/?', views.StockItemStocktake.as_view(), name='stock-item-stocktake'),
|
||||
url(r'^qr_code/?', views.StockItemQRCode.as_view(), name='stock-item-qr'),
|
||||
|
||||
url('^.*$', views.StockItemDetail.as_view(), name='stock-item-detail'),
|
||||
]
|
||||
|
@ -10,6 +10,7 @@ from django.forms.models import model_to_dict
|
||||
from django.forms import HiddenInput
|
||||
|
||||
from InvenTree.views import AjaxUpdateView, AjaxDeleteView, AjaxCreateView
|
||||
from InvenTree.views import QRCodeView
|
||||
|
||||
from part.models import Part
|
||||
from .models import StockItem, StockLocation, StockItemTracking
|
||||
@ -75,6 +76,34 @@ class StockLocationEdit(AjaxUpdateView):
|
||||
ajax_form_title = 'Edit Stock Location'
|
||||
|
||||
|
||||
class StockLocationQRCode(QRCodeView):
|
||||
""" View for displaying a QR code for a StockLocation object """
|
||||
|
||||
ajax_form_title = "Stock Location QR code"
|
||||
|
||||
def get_qr_data(self):
|
||||
""" Generate QR code data for the StockLocation """
|
||||
try:
|
||||
loc = StockLocation.objects.get(id=self.pk)
|
||||
return loc.format_barcode()
|
||||
except StockLocation.DoesNotExist:
|
||||
return None
|
||||
|
||||
|
||||
class StockItemQRCode(QRCodeView):
|
||||
""" View for displaying a QR code for a StockItem object """
|
||||
|
||||
ajax_form_title = "Stock Item QR Code"
|
||||
|
||||
def get_qr_data(self):
|
||||
""" Generate QR code data for the StockItem """
|
||||
try:
|
||||
item = StockItem.objects.get(id=self.pk)
|
||||
return item.format_barcode()
|
||||
except StockItem.DoesNotExist:
|
||||
return None
|
||||
|
||||
|
||||
class StockItemEdit(AjaxUpdateView):
|
||||
"""
|
||||
View for editing details of a single StockItem
|
||||
|
Reference in New Issue
Block a user