mirror of
https://github.com/inventree/InvenTree.git
synced 2025-07-01 11:10:54 +00:00
Client side QR Codes (#4357)
* Add JS for qrcodejs Ref: https://davidshimjs.github.io/qrcodejs/ * Simple function for rendering a QR code * Refactor QR code view for Part * Replace QR code view for SupplierPart * Refactor QR codes for stock item and stock location models * Remove base QRCodeView entirely
This commit is contained in:
@ -523,10 +523,10 @@ $('#stock-edit-status').click(function () {
|
||||
{% endif %}
|
||||
|
||||
$("#show-qr-code").click(function() {
|
||||
launchModalForm("{% url 'stock-item-qr' item.id %}",
|
||||
{
|
||||
no_post: true,
|
||||
});
|
||||
showQRDialog(
|
||||
'{% trans "Stock Item QR Code" %}',
|
||||
'{"stockitem": {{ item.pk }}}',
|
||||
);
|
||||
});
|
||||
|
||||
{% if barcodes %}
|
||||
|
@ -399,10 +399,10 @@
|
||||
|
||||
{% if barcodes %}
|
||||
$('#show-qr-code').click(function() {
|
||||
launchModalForm("{% url 'stock-location-qr' location.id %}",
|
||||
{
|
||||
no_post: true,
|
||||
});
|
||||
showQRDialog(
|
||||
'{% trans "Stock Location QR Code" %}',
|
||||
'{"stocklocation": {{ location.pk }}}'
|
||||
);
|
||||
});
|
||||
|
||||
$("#barcode-link").click(function() {
|
||||
|
@ -7,8 +7,6 @@ from stock import views
|
||||
location_urls = [
|
||||
|
||||
re_path(r'^(?P<pk>\d+)/', include([
|
||||
re_path(r'^qr_code/?', views.StockLocationQRCode.as_view(), name='stock-location-qr'),
|
||||
|
||||
# Anything else - direct to the location detail view
|
||||
re_path('^.*$', views.StockLocationDetail.as_view(), name='stock-location-detail'),
|
||||
])),
|
||||
@ -16,8 +14,6 @@ location_urls = [
|
||||
]
|
||||
|
||||
stock_item_detail_urls = [
|
||||
re_path(r'^qr_code/', views.StockItemQRCode.as_view(), name='stock-item-qr'),
|
||||
|
||||
# Anything else - direct to the item detail view
|
||||
re_path('^.*$', views.StockItemDetail.as_view(), name='stock-item-detail'),
|
||||
]
|
||||
|
@ -2,11 +2,10 @@
|
||||
|
||||
from django.http import HttpResponseRedirect
|
||||
from django.urls import reverse
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from django.views.generic import DetailView, ListView
|
||||
|
||||
import common.settings
|
||||
from InvenTree.views import InvenTreeRoleMixin, QRCodeView
|
||||
from InvenTree.views import InvenTreeRoleMixin
|
||||
from plugin.views import InvenTreePluginViewMixin
|
||||
|
||||
from .models import StockItem, StockLocation
|
||||
@ -101,34 +100,3 @@ class StockItemDetail(InvenTreeRoleMixin, InvenTreePluginViewMixin, DetailView):
|
||||
return HttpResponseRedirect(reverse('stock-index'))
|
||||
|
||||
return super().get(request, *args, **kwargs)
|
||||
|
||||
|
||||
class StockLocationQRCode(QRCodeView):
|
||||
"""View for displaying a QR code for a StockLocation object."""
|
||||
|
||||
ajax_form_title = _("Stock Location QR code")
|
||||
|
||||
role_required = ['stock_location.view', 'stock.view']
|
||||
|
||||
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")
|
||||
role_required = 'stock.view'
|
||||
|
||||
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
|
||||
|
Reference in New Issue
Block a user