2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-06-14 19:15:41 +00:00

Add more information to the Barcode

- API endpoint URL
- Add barcode generation for StockLocation
This commit is contained in:
Oliver Walters
2019-05-02 20:50:20 +10:00
parent d49ce465e5
commit c901294a48
4 changed files with 32 additions and 9 deletions

View File

@ -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 = [

View File

@ -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')

View File

@ -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>