mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Added barcode for Part object
This commit is contained in:
parent
c901294a48
commit
5a234a1070
@ -46,7 +46,7 @@ def WrapWithQuotes(text, quote='"'):
|
||||
return text
|
||||
|
||||
|
||||
def MakeBarcode(object_type, object_url, data={}):
|
||||
def MakeBarcode(object_type, object_id, object_url, data={}):
|
||||
""" Generate a string for a barcode. Adds some global InvenTree parameters.
|
||||
|
||||
Args:
|
||||
@ -60,6 +60,7 @@ def MakeBarcode(object_type, object_url, data={}):
|
||||
|
||||
# Add in some generic InvenTree data
|
||||
data['type'] = object_type
|
||||
data['id'] = object_id
|
||||
data['url'] = object_url
|
||||
data['tool'] = 'InvenTree'
|
||||
data['generated'] = str(datetime.now().date())
|
||||
|
@ -21,6 +21,7 @@ from django.core.validators import MinValueValidator
|
||||
from django.db.models.signals import pre_delete
|
||||
from django.dispatch import receiver
|
||||
|
||||
from InvenTree import helpers
|
||||
from InvenTree.models import InvenTreeTree
|
||||
from company.models import Company
|
||||
|
||||
@ -179,6 +180,16 @@ class Part(models.Model):
|
||||
def __str__(self):
|
||||
return "{n} - {d}".format(n=self.name, d=self.description)
|
||||
|
||||
@property
|
||||
def format_barcode(self):
|
||||
""" Return a JSON string for formatting a barcode for this Part object """
|
||||
|
||||
return helpers.MakeBarcode(
|
||||
"Part",
|
||||
self.id,
|
||||
reverse('api-part-detail', kwargs={'pk': self.id}),
|
||||
)
|
||||
|
||||
class Meta:
|
||||
verbose_name = "Part"
|
||||
verbose_name_plural = "Parts"
|
||||
|
@ -1,5 +1,6 @@
|
||||
{% extends "part/part_base.html" %}
|
||||
{% load static %}
|
||||
{% load qr_code %}
|
||||
{% block details %}
|
||||
|
||||
{% include 'part/tabs.html' with tab='detail' %}
|
||||
@ -115,6 +116,8 @@
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% qr_from_text part.format_barcode size="s" image_format="png" error_correction="L" %}
|
||||
|
||||
{% endblock %}
|
||||
|
||||
{% block js_load %}
|
||||
|
@ -42,9 +42,9 @@ class StockLocation(InvenTreeTree):
|
||||
|
||||
return helpers.MakeBarcode(
|
||||
'StockLocation',
|
||||
self.id,
|
||||
reverse('api-location-detail', kwargs={'pk': self.id}),
|
||||
{
|
||||
'id': self.id,
|
||||
'name': self.name,
|
||||
}
|
||||
)
|
||||
@ -153,9 +153,9 @@ class StockItem(models.Model):
|
||||
|
||||
return helpers.MakeBarcode(
|
||||
'StockItem',
|
||||
self.id,
|
||||
reverse('api-stock-detail', kwargs={'pk': self.id}),
|
||||
{
|
||||
'id': self.id,
|
||||
'part_id': self.part.id,
|
||||
'part_name': self.part.name
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user