mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Merge pull request #1255 from SchrodingersGat/simple-qr-codes
Default to using "simple" QR codes
This commit is contained in:
commit
65791a2b9b
@ -267,7 +267,7 @@ def WrapWithQuotes(text, quote='"'):
|
|||||||
return text
|
return text
|
||||||
|
|
||||||
|
|
||||||
def MakeBarcode(object_name, object_pk, object_data, **kwargs):
|
def MakeBarcode(object_name, object_pk, object_data={}, **kwargs):
|
||||||
""" Generate a string for a barcode. Adds some global InvenTree parameters.
|
""" Generate a string for a barcode. Adds some global InvenTree parameters.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
@ -280,7 +280,7 @@ def MakeBarcode(object_name, object_pk, object_data, **kwargs):
|
|||||||
json string of the supplied data plus some other data
|
json string of the supplied data plus some other data
|
||||||
"""
|
"""
|
||||||
|
|
||||||
brief = kwargs.get('brief', False)
|
brief = kwargs.get('brief', True)
|
||||||
|
|
||||||
data = {}
|
data = {}
|
||||||
|
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
|
|
||||||
|
import json
|
||||||
|
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
import django.core.exceptions as django_exceptions
|
import django.core.exceptions as django_exceptions
|
||||||
from django.core.exceptions import ValidationError
|
from django.core.exceptions import ValidationError
|
||||||
@ -134,7 +136,7 @@ class TestIncrement(TestCase):
|
|||||||
class TestMakeBarcode(TestCase):
|
class TestMakeBarcode(TestCase):
|
||||||
""" Tests for barcode string creation """
|
""" Tests for barcode string creation """
|
||||||
|
|
||||||
def test_barcode(self):
|
def test_barcode_extended(self):
|
||||||
|
|
||||||
bc = helpers.MakeBarcode(
|
bc = helpers.MakeBarcode(
|
||||||
"part",
|
"part",
|
||||||
@ -142,13 +144,30 @@ class TestMakeBarcode(TestCase):
|
|||||||
{
|
{
|
||||||
"id": 3,
|
"id": 3,
|
||||||
"url": "www.google.com",
|
"url": "www.google.com",
|
||||||
}
|
},
|
||||||
|
brief=False
|
||||||
)
|
)
|
||||||
|
|
||||||
self.assertIn('part', bc)
|
self.assertIn('part', bc)
|
||||||
self.assertIn('tool', bc)
|
self.assertIn('tool', bc)
|
||||||
self.assertIn('"tool": "InvenTree"', bc)
|
self.assertIn('"tool": "InvenTree"', bc)
|
||||||
|
|
||||||
|
data = json.loads(bc)
|
||||||
|
|
||||||
|
self.assertEqual(data['part']['id'], 3)
|
||||||
|
self.assertEqual(data['part']['url'], 'www.google.com')
|
||||||
|
|
||||||
|
def test_barcode_brief(self):
|
||||||
|
|
||||||
|
bc = helpers.MakeBarcode(
|
||||||
|
"stockitem",
|
||||||
|
7,
|
||||||
|
)
|
||||||
|
|
||||||
|
data = json.loads(bc)
|
||||||
|
self.assertEqual(len(data), 1)
|
||||||
|
self.assertEqual(data['stockitem'], 7)
|
||||||
|
|
||||||
|
|
||||||
class TestDownloadFile(TestCase):
|
class TestDownloadFile(TestCase):
|
||||||
|
|
||||||
|
@ -25,6 +25,8 @@ def hash_barcode(barcode_data):
|
|||||||
TODO: Work out a way around this!
|
TODO: Work out a way around this!
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
barcode_data = str(barcode_data).strip()
|
||||||
|
|
||||||
printable_chars = filter(lambda x: x in string.printable, barcode_data)
|
printable_chars = filter(lambda x: x in string.printable, barcode_data)
|
||||||
|
|
||||||
barcode_data = ''.join(list(printable_chars))
|
barcode_data = ''.join(list(printable_chars))
|
||||||
|
@ -100,7 +100,7 @@ class PartTest(TestCase):
|
|||||||
self.assertEqual(r.available_stock, 0)
|
self.assertEqual(r.available_stock, 0)
|
||||||
|
|
||||||
def test_barcode(self):
|
def test_barcode(self):
|
||||||
barcode = self.r1.format_barcode()
|
barcode = self.r1.format_barcode(brief=False)
|
||||||
self.assertIn('InvenTree', barcode)
|
self.assertIn('InvenTree', barcode)
|
||||||
self.assertIn(self.r1.name, barcode)
|
self.assertIn(self.r1.name, barcode)
|
||||||
|
|
||||||
|
@ -122,7 +122,7 @@ class StockTest(TestCase):
|
|||||||
self.assertEqual(self.home.get_absolute_url(), '/stock/location/1/')
|
self.assertEqual(self.home.get_absolute_url(), '/stock/location/1/')
|
||||||
|
|
||||||
def test_barcode(self):
|
def test_barcode(self):
|
||||||
barcode = self.office.format_barcode()
|
barcode = self.office.format_barcode(brief=False)
|
||||||
|
|
||||||
self.assertIn('"name": "Office"', barcode)
|
self.assertIn('"name": "Office"', barcode)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user