mirror of
https://github.com/inventree/InvenTree.git
synced 2025-05-01 04:56:45 +00:00
Create a "unique(ish)" hash for barcode data
This commit is contained in:
parent
f742f32804
commit
277b28a7e9
@ -85,6 +85,7 @@ class BarcodeScanView(APIView):
|
|||||||
}
|
}
|
||||||
|
|
||||||
response['plugin'] = plugin.get_name()
|
response['plugin'] = plugin.get_name()
|
||||||
|
response['hash'] = plugin.hash()
|
||||||
|
|
||||||
break
|
break
|
||||||
|
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
import hashlib
|
||||||
|
|
||||||
import plugins.plugin as plugin
|
import plugins.plugin as plugin
|
||||||
|
|
||||||
|
|
||||||
@ -18,9 +20,17 @@ class BarcodePlugin(plugin.InvenTreePlugin):
|
|||||||
Calculate a hash for the barcode data.
|
Calculate a hash for the barcode data.
|
||||||
This is supposed to uniquely identify the barcode contents,
|
This is supposed to uniquely identify the barcode contents,
|
||||||
at least within the bardcode sub-type.
|
at least within the bardcode sub-type.
|
||||||
|
|
||||||
|
The default implementation simply returns an MD5 hash of the barcode data,
|
||||||
|
encoded to a string.
|
||||||
|
|
||||||
|
This may be sufficient for most applications, but can obviously be overridden
|
||||||
|
by a subclass.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
return ""
|
hash = hashlib.md5(str(self.data).encode())
|
||||||
|
return str(hash.hexdigest())
|
||||||
|
|
||||||
def validate(self):
|
def validate(self):
|
||||||
"""
|
"""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user