mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Add form for selecting label template for a StockItem
This commit is contained in:
parent
30e24f19d9
commit
1807ba4e7b
@ -43,6 +43,12 @@ class LabelTemplate(models.Model):
|
|||||||
def template(self):
|
def template(self):
|
||||||
return self.label.path
|
return self.label.path
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return "{n} - {d}".format(
|
||||||
|
n=self.name,
|
||||||
|
d=self.description
|
||||||
|
)
|
||||||
|
|
||||||
name = models.CharField(
|
name = models.CharField(
|
||||||
unique=True,
|
unique=True,
|
||||||
blank=False, max_length=100,
|
blank=False, max_length=100,
|
||||||
@ -137,6 +143,7 @@ class StockItemLabel(LabelTemplate):
|
|||||||
'uid': item.uid,
|
'uid': item.uid,
|
||||||
'pk': item.pk,
|
'pk': item.pk,
|
||||||
'qr_data': item.format_short_barcode(),
|
'qr_data': item.format_short_barcode(),
|
||||||
|
'tests': item.testResultMap()
|
||||||
})
|
})
|
||||||
|
|
||||||
return records
|
return records
|
||||||
|
@ -178,6 +178,37 @@ class SerializeStockForm(HelperForm):
|
|||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
class StockItemLabelSelectForm(HelperForm):
|
||||||
|
""" Form for selecting a label template for a StockItem """
|
||||||
|
|
||||||
|
label = forms.ChoiceField(
|
||||||
|
label=_('Label'),
|
||||||
|
help_text=_('Select test report template')
|
||||||
|
)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = StockItem
|
||||||
|
fields = [
|
||||||
|
'label',
|
||||||
|
]
|
||||||
|
|
||||||
|
def get_label_choices(self, labels):
|
||||||
|
|
||||||
|
choices = []
|
||||||
|
|
||||||
|
if len(labels) > 0:
|
||||||
|
for label in labels:
|
||||||
|
choices.append((label.pk, label))
|
||||||
|
|
||||||
|
return choices
|
||||||
|
|
||||||
|
def __init__(self, labels, *args, **kwargs):
|
||||||
|
|
||||||
|
super().__init__(*args, **kwargs)
|
||||||
|
|
||||||
|
self.fields['label'].choices = self.get_label_choices(labels)
|
||||||
|
|
||||||
|
|
||||||
class TestReportFormatForm(HelperForm):
|
class TestReportFormatForm(HelperForm):
|
||||||
""" Form for selection a test report template """
|
""" Form for selection a test report template """
|
||||||
|
|
||||||
|
@ -129,6 +129,9 @@ InvenTree | {% trans "Stock Item" %} - {{ item }}
|
|||||||
<span class='fas fa-tasks'/>
|
<span class='fas fa-tasks'/>
|
||||||
</button>
|
</button>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
<button type='button' class='btn btn-default' id='stock-print-label' title='{% trans "Print labels" %}'>
|
||||||
|
<span class='fas fa-tag'></span>
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
@ -314,6 +317,15 @@ $("#stock-test-report").click(function() {
|
|||||||
});
|
});
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
$("#stock-print-label").click(function() {
|
||||||
|
launchModalForm(
|
||||||
|
"{% url 'stock-item-label-select' item.id %}",
|
||||||
|
{
|
||||||
|
follow: true,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
});
|
||||||
|
|
||||||
$("#stock-duplicate").click(function() {
|
$("#stock-duplicate").click(function() {
|
||||||
launchModalForm(
|
launchModalForm(
|
||||||
"{% url 'stock-item-create' %}",
|
"{% url 'stock-item-create' %}",
|
||||||
|
@ -29,6 +29,7 @@ stock_item_detail_urls = [
|
|||||||
url(r'^add_tracking/', views.StockItemTrackingCreate.as_view(), name='stock-tracking-create'),
|
url(r'^add_tracking/', views.StockItemTrackingCreate.as_view(), name='stock-tracking-create'),
|
||||||
|
|
||||||
url(r'^test-report-select/', views.StockItemTestReportSelect.as_view(), name='stock-item-test-report-select'),
|
url(r'^test-report-select/', views.StockItemTestReportSelect.as_view(), name='stock-item-test-report-select'),
|
||||||
|
url(r'^label-select/', views.StockItemSelectLabels.as_view(), name='stock-item-label-select'),
|
||||||
|
|
||||||
url(r'^test/', views.StockItemDetail.as_view(template_name='stock/item_tests.html'), name='stock-item-test-results'),
|
url(r'^test/', views.StockItemDetail.as_view(template_name='stock/item_tests.html'), name='stock-item-test-results'),
|
||||||
url(r'^children/', views.StockItemDetail.as_view(template_name='stock/item_childs.html'), name='stock-item-children'),
|
url(r'^children/', views.StockItemDetail.as_view(template_name='stock/item_childs.html'), name='stock-item-children'),
|
||||||
|
@ -296,6 +296,50 @@ class StockItemReturnToStock(AjaxUpdateView):
|
|||||||
return self.renderJsonResponse(request, self.get_form(), data)
|
return self.renderJsonResponse(request, self.get_form(), data)
|
||||||
|
|
||||||
|
|
||||||
|
class StockItemSelectLabels(AjaxView):
|
||||||
|
"""
|
||||||
|
View for selecting a template for printing labels for one (or more) StockItem objects
|
||||||
|
"""
|
||||||
|
|
||||||
|
model = StockItem
|
||||||
|
ajax_form_title = _('Select Label Template')
|
||||||
|
|
||||||
|
def get_form(self):
|
||||||
|
|
||||||
|
item = StockItem.objects.get(pk=self.kwargs['pk'])
|
||||||
|
|
||||||
|
labels = []
|
||||||
|
|
||||||
|
for label in StockItemLabel.objects.all():
|
||||||
|
if label.matches_stock_item(item):
|
||||||
|
labels.append(label)
|
||||||
|
|
||||||
|
return StockForms.StockItemLabelSelectForm(labels)
|
||||||
|
|
||||||
|
def post(self, request, *args, **kwargs):
|
||||||
|
|
||||||
|
label = request.POST.get('label', None)
|
||||||
|
|
||||||
|
try:
|
||||||
|
label = StockItemLabel.objects.get(pk=label)
|
||||||
|
except (ValueError, StockItemLabel.DoesNotExist):
|
||||||
|
raise ValidationError({'label': _("Select valid label")})
|
||||||
|
|
||||||
|
stock_item = StockItem.objects.get(pk=self.kwargs['pk'])
|
||||||
|
|
||||||
|
url = reverse('stock-item-print-labels')
|
||||||
|
|
||||||
|
url += '?label={pk}'.format(pk=label.pk)
|
||||||
|
url += '&items[]={pk}'.format(pk=stock_item.pk)
|
||||||
|
|
||||||
|
data = {
|
||||||
|
'form_valid': True,
|
||||||
|
'url': url,
|
||||||
|
}
|
||||||
|
|
||||||
|
return self.renderJsonResponse(request, self.get_form(), data=data)
|
||||||
|
|
||||||
|
|
||||||
class StockItemPrintLabels(AjaxView):
|
class StockItemPrintLabels(AjaxView):
|
||||||
"""
|
"""
|
||||||
View for printing labels and returning a PDF
|
View for printing labels and returning a PDF
|
||||||
|
Loading…
Reference in New Issue
Block a user