mirror of
https://github.com/inventree/InvenTree.git
synced 2025-04-30 20:46:47 +00:00
Add "brief" version of QR codes
- Use this to render to labels (as it contains much less information)
This commit is contained in:
parent
2f5e3efada
commit
2bbc65cc59
@ -242,7 +242,7 @@ def WrapWithQuotes(text, quote='"'):
|
|||||||
return text
|
return text
|
||||||
|
|
||||||
|
|
||||||
def MakeBarcode(object_name, object_data):
|
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:
|
||||||
@ -255,12 +255,17 @@ def MakeBarcode(object_name, object_data):
|
|||||||
json string of the supplied data plus some other data
|
json string of the supplied data plus some other data
|
||||||
"""
|
"""
|
||||||
|
|
||||||
data = {
|
brief = kwargs.get('brief', False)
|
||||||
'tool': 'InvenTree',
|
|
||||||
'version': inventreeVersion(),
|
data = {}
|
||||||
'instance': inventreeInstanceName(),
|
|
||||||
object_name: object_data
|
if brief:
|
||||||
}
|
data[object_name] = object_pk
|
||||||
|
else:
|
||||||
|
data['tool'] = 'InvenTree'
|
||||||
|
data['version'] = inventreeVersion()
|
||||||
|
data['instance'] = inventreeInstanceName()
|
||||||
|
data[object_name] = object_data
|
||||||
|
|
||||||
return json.dumps(data, sort_keys=True)
|
return json.dumps(data, sort_keys=True)
|
||||||
|
|
||||||
|
@ -47,12 +47,12 @@ class InvenTreeBarcodePlugin(BarcodePlugin):
|
|||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
for key in ['tool', 'version']:
|
# If any of the following keys are in the JSON data,
|
||||||
if key not in self.data.keys():
|
# let's go ahead and assume that the code is a valid InvenTree one...
|
||||||
return False
|
|
||||||
|
|
||||||
if not self.data['tool'] == 'InvenTree':
|
for key in ['tool', 'version', 'InvenTree', 'stockitem', 'location', 'part']:
|
||||||
return False
|
if key in self.data.keys():
|
||||||
|
return True
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@ -60,6 +60,18 @@ class InvenTreeBarcodePlugin(BarcodePlugin):
|
|||||||
|
|
||||||
for k in self.data.keys():
|
for k in self.data.keys():
|
||||||
if k.lower() == 'stockitem':
|
if k.lower() == 'stockitem':
|
||||||
|
|
||||||
|
data = self.data[k]
|
||||||
|
|
||||||
|
pk = None
|
||||||
|
|
||||||
|
# Initially try casting to an integer
|
||||||
|
try:
|
||||||
|
pk = int(data)
|
||||||
|
except (ValueError):
|
||||||
|
pk = None
|
||||||
|
|
||||||
|
if pk is None:
|
||||||
try:
|
try:
|
||||||
pk = self.data[k]['id']
|
pk = self.data[k]['id']
|
||||||
except (AttributeError, KeyError):
|
except (AttributeError, KeyError):
|
||||||
|
@ -142,7 +142,7 @@ class StockItemLabel(LabelTemplate):
|
|||||||
'serial': item.serial,
|
'serial': item.serial,
|
||||||
'uid': item.uid,
|
'uid': item.uid,
|
||||||
'pk': item.pk,
|
'pk': item.pk,
|
||||||
'qr_data': item.format_short_barcode(),
|
'qr_data': item.format_barcode(brief=True),
|
||||||
'tests': item.testResultMap()
|
'tests': item.testResultMap()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -283,7 +283,7 @@ class StockItem(MPTTModel):
|
|||||||
def get_part_name(self):
|
def get_part_name(self):
|
||||||
return self.part.full_name
|
return self.part.full_name
|
||||||
|
|
||||||
def format_barcode(self):
|
def format_barcode(self, **kwargs):
|
||||||
""" Return a JSON string for formatting a barcode for this StockItem.
|
""" Return a JSON string for formatting a barcode for this StockItem.
|
||||||
Can be used to perform lookup of a stockitem using barcode
|
Can be used to perform lookup of a stockitem using barcode
|
||||||
|
|
||||||
@ -296,19 +296,14 @@ class StockItem(MPTTModel):
|
|||||||
|
|
||||||
return helpers.MakeBarcode(
|
return helpers.MakeBarcode(
|
||||||
"stockitem",
|
"stockitem",
|
||||||
|
self.id,
|
||||||
{
|
{
|
||||||
"id": self.id,
|
"id": self.id,
|
||||||
"url": reverse('api-stock-detail', kwargs={'pk': self.id}),
|
"url": reverse('api-stock-detail', kwargs={'pk': self.id}),
|
||||||
}
|
},
|
||||||
|
**kwargs
|
||||||
)
|
)
|
||||||
|
|
||||||
def format_short_barcode(self):
|
|
||||||
"""
|
|
||||||
Return a short barcode
|
|
||||||
"""
|
|
||||||
|
|
||||||
return "stockid={pk}".format(pk=self.pk)
|
|
||||||
|
|
||||||
uid = models.CharField(blank=True, max_length=128, help_text=("Unique identifier field"))
|
uid = models.CharField(blank=True, max_length=128, help_text=("Unique identifier field"))
|
||||||
|
|
||||||
parent = TreeForeignKey(
|
parent = TreeForeignKey(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user