mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Add more information to the Barcode
- API endpoint URL - Add barcode generation for StockLocation
This commit is contained in:
parent
d49ce465e5
commit
c901294a48
@ -46,11 +46,13 @@ def WrapWithQuotes(text, quote='"'):
|
||||
return text
|
||||
|
||||
|
||||
def MakeBarcode(object_type, data={}):
|
||||
def MakeBarcode(object_type, object_url, 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)
|
||||
object_type: string describing the object type e.g. 'StockItem'
|
||||
object_url: url for JSON API detail view of the object
|
||||
data: Python dict object containing extra datawhich will be rendered to string (must only contain stringable values)
|
||||
|
||||
Returns:
|
||||
json string of the supplied data plus some other data
|
||||
@ -58,6 +60,7 @@ def MakeBarcode(object_type, data={}):
|
||||
|
||||
# Add in some generic InvenTree data
|
||||
data['type'] = object_type
|
||||
data['url'] = object_url
|
||||
data['tool'] = 'InvenTree'
|
||||
data['generated'] = str(datetime.now().date())
|
||||
|
||||
|
@ -345,11 +345,11 @@ class LocationDetail(generics.RetrieveUpdateDestroyAPIView):
|
||||
|
||||
|
||||
stock_endpoints = [
|
||||
url(r'^$', StockDetail.as_view(), name='stockitem-detail'),
|
||||
url(r'^$', StockDetail.as_view(), name='api-stock-detail'),
|
||||
]
|
||||
|
||||
location_endpoints = [
|
||||
url(r'^$', LocationDetail.as_view(), name='stocklocation-detail'),
|
||||
url(r'^$', LocationDetail.as_view(), name='api-location-detail'),
|
||||
]
|
||||
|
||||
stock_api_urls = [
|
||||
|
@ -36,6 +36,19 @@ class StockLocation(InvenTreeTree):
|
||||
def has_items(self):
|
||||
return self.stock_items.count() > 0
|
||||
|
||||
@property
|
||||
def format_barcode(self):
|
||||
""" Return a JSON string for formatting a barcode for this StockLocation object """
|
||||
|
||||
return helpers.MakeBarcode(
|
||||
'StockLocation',
|
||||
reverse('api-location-detail', kwargs={'pk': self.id}),
|
||||
{
|
||||
'id': self.id,
|
||||
'name': self.name,
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
@receiver(pre_delete, sender=StockLocation, dispatch_uid='stocklocation_delete_log')
|
||||
def before_delete_stock_location(sender, instance, using, **kwargs):
|
||||
@ -135,13 +148,18 @@ class StockItem(models.Model):
|
||||
|
||||
{ type: 'StockItem', stock_id: <pk>, part_id: <part_pk> }
|
||||
|
||||
Any other data should be looked up using the InvenTree API (as it may change)
|
||||
Voltagile data (e.g. stock quantity) 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
|
||||
})
|
||||
return helpers.MakeBarcode(
|
||||
'StockItem',
|
||||
reverse('api-stock-detail', kwargs={'pk': self.id}),
|
||||
{
|
||||
'id': self.id,
|
||||
'part_id': self.part.id,
|
||||
'part_name': self.part.name
|
||||
}
|
||||
)
|
||||
|
||||
# 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')
|
||||
|
@ -1,5 +1,6 @@
|
||||
{% extends "stock/stock_app_base.html" %}
|
||||
{% load static %}
|
||||
{% load qr_code %}
|
||||
{% block content %}
|
||||
|
||||
<div class='row'>
|
||||
@ -25,6 +26,7 @@
|
||||
<li><a href="#" id='location-delete' title='Delete stock location'>Delete</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
{% qr_from_text location.format_barcode size="s" image_format="png" error_correction="L" %}
|
||||
{% endif %}
|
||||
</div>
|
||||
</h3>
|
||||
|
Loading…
Reference in New Issue
Block a user