mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Removed UUID field from StockItem
- QR code is now created based on a JSON object - This will make it extensible to other things such as StockLocation - Created a helper function to make Barcode objects
This commit is contained in:
parent
2f7c02133e
commit
d49ce465e5
@ -3,6 +3,8 @@ Provides helper functions used throughout the InvenTree project
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
import io
|
import io
|
||||||
|
import json
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
from wsgiref.util import FileWrapper
|
from wsgiref.util import FileWrapper
|
||||||
from django.http import StreamingHttpResponse
|
from django.http import StreamingHttpResponse
|
||||||
@ -44,6 +46,24 @@ def WrapWithQuotes(text, quote='"'):
|
|||||||
return text
|
return text
|
||||||
|
|
||||||
|
|
||||||
|
def MakeBarcode(object_type, data={}):
|
||||||
|
""" Generate a string for a barcode. Adds some global InvenTree parameters.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
data: Python dict obejct which will be rendered to string (must only contain stringable values)
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
json string of the supplied data plus some other data
|
||||||
|
"""
|
||||||
|
|
||||||
|
# Add in some generic InvenTree data
|
||||||
|
data['type'] = object_type
|
||||||
|
data['tool'] = 'InvenTree'
|
||||||
|
data['generated'] = str(datetime.now().date())
|
||||||
|
|
||||||
|
return json.dumps(data, sort_keys=True)
|
||||||
|
|
||||||
|
|
||||||
def DownloadFile(data, filename, content_type='application/text'):
|
def DownloadFile(data, filename, content_type='application/text'):
|
||||||
""" Create a dynamic file for the user to download.
|
""" Create a dynamic file for the user to download.
|
||||||
|
|
||||||
|
18
InvenTree/part/migrations/0014_auto_20190502_2039.py
Normal file
18
InvenTree/part/migrations/0014_auto_20190502_2039.py
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
# Generated by Django 2.2 on 2019-05-02 10:39
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('part', '0013_auto_20190429_2229'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='part',
|
||||||
|
name='URL',
|
||||||
|
field=models.URLField(blank=True, help_text='Link to extenal URL'),
|
||||||
|
),
|
||||||
|
]
|
@ -272,7 +272,6 @@ class StockList(generics.ListCreateAPIView):
|
|||||||
|
|
||||||
filter_fields = [
|
filter_fields = [
|
||||||
'part',
|
'part',
|
||||||
'uuid',
|
|
||||||
'supplier_part',
|
'supplier_part',
|
||||||
'customer',
|
'customer',
|
||||||
'belongs_to',
|
'belongs_to',
|
||||||
|
17
InvenTree/stock/migrations/0013_remove_stockitem_uuid.py
Normal file
17
InvenTree/stock/migrations/0013_remove_stockitem_uuid.py
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
# Generated by Django 2.2 on 2019-05-02 10:39
|
||||||
|
|
||||||
|
from django.db import migrations
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('stock', '0012_auto_20190502_0058'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RemoveField(
|
||||||
|
model_name='stockitem',
|
||||||
|
name='uuid',
|
||||||
|
),
|
||||||
|
]
|
@ -17,7 +17,7 @@ from django.db.models.signals import pre_delete
|
|||||||
from django.dispatch import receiver
|
from django.dispatch import receiver
|
||||||
|
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
import uuid
|
from InvenTree import helpers
|
||||||
|
|
||||||
from InvenTree.models import InvenTreeTree
|
from InvenTree.models import InvenTreeTree
|
||||||
|
|
||||||
@ -126,8 +126,22 @@ class StockItem(models.Model):
|
|||||||
('part', 'serial'),
|
('part', 'serial'),
|
||||||
]
|
]
|
||||||
|
|
||||||
# UUID for generating QR codes
|
@property
|
||||||
uuid = models.UUIDField(default=uuid.uuid4, blank=True, editable=False, help_text='Unique ID for the StockItem')
|
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
|
||||||
|
|
||||||
|
Contains the following data:
|
||||||
|
|
||||||
|
{ type: 'StockItem', stock_id: <pk>, part_id: <part_pk> }
|
||||||
|
|
||||||
|
Any other data should be looked up using the InvenTree API (as it may change)
|
||||||
|
"""
|
||||||
|
|
||||||
|
return helpers.MakeBarcode('StockItem', {
|
||||||
|
'stock_id': self.id,
|
||||||
|
'part_id': self.part.id
|
||||||
|
})
|
||||||
|
|
||||||
# The 'master' copy of the part of which this stock item is an instance
|
# The 'master' copy of the part of which this stock item is an instance
|
||||||
part = models.ForeignKey('part.Part', on_delete=models.CASCADE, related_name='locations', help_text='Base part')
|
part = models.ForeignKey('part.Part', on_delete=models.CASCADE, related_name='locations', help_text='Base part')
|
||||||
|
@ -38,7 +38,6 @@ class StockItemSerializerBrief(serializers.ModelSerializer):
|
|||||||
model = StockItem
|
model = StockItem
|
||||||
fields = [
|
fields = [
|
||||||
'pk',
|
'pk',
|
||||||
'uuid',
|
|
||||||
'part',
|
'part',
|
||||||
'part_name',
|
'part_name',
|
||||||
'supplier_part',
|
'supplier_part',
|
||||||
@ -65,7 +64,6 @@ class StockItemSerializer(serializers.ModelSerializer):
|
|||||||
model = StockItem
|
model = StockItem
|
||||||
fields = [
|
fields = [
|
||||||
'pk',
|
'pk',
|
||||||
'uuid',
|
|
||||||
'url',
|
'url',
|
||||||
'part',
|
'part',
|
||||||
'supplier_part',
|
'supplier_part',
|
||||||
|
@ -39,10 +39,6 @@
|
|||||||
<td>Part</td>
|
<td>Part</td>
|
||||||
<td><a href="{% url 'part-stock' item.part.id %}">{{ item.part.name }}</td>
|
<td><a href="{% url 'part-stock' item.part.id %}">{{ item.part.name }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
|
||||||
<td>UUID</td>
|
|
||||||
<td>{{ item.uuid }}</td>
|
|
||||||
</tr>
|
|
||||||
{% if item.belongs_to %}
|
{% if item.belongs_to %}
|
||||||
<tr>
|
<tr>
|
||||||
<td>Belongs To</td>
|
<td>Belongs To</td>
|
||||||
@ -114,7 +110,7 @@
|
|||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
<div class='col-sm-6'>
|
<div class='col-sm-6'>
|
||||||
{% qr_from_text item.uuid size="s" image_format="png" error_correction="L" %}
|
{% qr_from_text item.format_barcode size="s" image_format="png" error_correction="L" %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user