Rearrange button options for StockItem

This commit is contained in:
Oliver Walters 2021-01-07 00:18:18 +11:00
parent 735a3d2eb2
commit bb72658e76
4 changed files with 56 additions and 10 deletions

View File

@ -16,7 +16,7 @@ from django.conf import settings
from django.core.validators import FileExtensionValidator from django.core.validators import FileExtensionValidator
from django.core.exceptions import ValidationError from django.core.exceptions import ValidationError
from stock.models import StockItem import stock.models
from InvenTree.helpers import validateFilterString from InvenTree.helpers import validateFilterString
@ -191,7 +191,7 @@ class TestReport(ReportTemplateBase):
filters = validateFilterString(self.filters) filters = validateFilterString(self.filters)
items = StockItem.objects.filter(**filters) items = stock.models.StockItem.objects.filter(**filters)
# Ensure the provided StockItem object matches the filters # Ensure the provided StockItem object matches the filters
items = items.filter(pk=item.pk) items = items.filter(pk=item.pk)

View File

@ -247,7 +247,7 @@ class TestReportFormatForm(HelperForm):
templates = TestReport.objects.filter(enabled=True) templates = TestReport.objects.filter(enabled=True)
for template in templates: for template in templates:
if template.matches_stock_item(self.stock_item): if template.enabled and template.matches_stock_item(self.stock_item):
choices.append((template.pk, template)) choices.append((template.pk, template))
return choices return choices

View File

@ -31,6 +31,7 @@ from datetime import datetime, timedelta
from InvenTree import helpers from InvenTree import helpers
import common.models import common.models
import report.models
from InvenTree.status_codes import StockStatus from InvenTree.status_codes import StockStatus
from InvenTree.models import InvenTreeTree, InvenTreeAttachment from InvenTree.models import InvenTreeTree, InvenTreeAttachment
@ -1306,6 +1307,41 @@ class StockItem(MPTTModel):
return status['passed'] >= status['total'] return status['passed'] >= status['total']
def available_test_reports(self):
"""
Return a list of TestReport objects which match this StockItem.
"""
reports = []
item_query = StockItem.objects.filter(pk=self.pk)
for test_report in report.models.TestReport.objects.filter(enabled=True):
filters = helpers.validateFilterString(test_report.filters)
if item_query.filter(**filters).exists():
reports.append(test_report)
return reports
@property
def has_test_reports(self):
"""
Return True if there are test reports available for this stock item
"""
return len(self.available_test_reports()) > 0
@property
def has_labels(self):
"""
Return True if there are any label templates available for this stock item
"""
# TODO - Implement this
return True
@receiver(pre_delete, sender=StockItem, dispatch_uid='stock_item_pre_delete_log') @receiver(pre_delete, sender=StockItem, dispatch_uid='stock_item_pre_delete_log')
def before_delete_stock_item(sender, instance, using, **kwargs): def before_delete_stock_item(sender, instance, using, **kwargs):

View File

@ -108,7 +108,6 @@ InvenTree | {% trans "Stock Item" %} - {{ item }}
<button id='barcode-options' title='{% trans "Barcode actions" %}' class='btn btn-default dropdown-toggle' type='button' data-toggle='dropdown'><span class='fas fa-qrcode'></span> <span class='caret'></span></button> <button id='barcode-options' title='{% trans "Barcode actions" %}' class='btn btn-default dropdown-toggle' type='button' data-toggle='dropdown'><span class='fas fa-qrcode'></span> <span class='caret'></span></button>
<ul class='dropdown-menu' role='menu'> <ul class='dropdown-menu' role='menu'>
<li><a href='#' id='show-qr-code'><span class='fas fa-qrcode'></span> {% trans "Show QR Code" %}</a></li> <li><a href='#' id='show-qr-code'><span class='fas fa-qrcode'></span> {% trans "Show QR Code" %}</a></li>
<li><a href='#' id='print-label'><span class='fas fa-tag'></span> {% trans "Print Label" %}</a></li>
{% if roles.stock.change %} {% if roles.stock.change %}
{% if item.uid %} {% if item.uid %}
<li><a href='#' id='unlink-barcode'><span class='fas fa-unlink'></span> {% trans "Unlink Barcode" %}</a></li> <li><a href='#' id='unlink-barcode'><span class='fas fa-unlink'></span> {% trans "Unlink Barcode" %}</a></li>
@ -118,6 +117,20 @@ InvenTree | {% trans "Stock Item" %} - {{ item }}
{% endif %} {% endif %}
</ul> </ul>
</div> </div>
<!-- Document / label menu -->
{% if item.has_labels or item.has_test_reports %}
<div class='btn-group'>
<button id='document-options' title='{% trans "Document actions" %}' class='btn btn-default dropdown-toggle' type='button' data-toggle='dropdown'><span class='fas fa-file-alt'></span> <span class='caret'></span></button>
<ul class='dropdown-menu' role='menu'>
{% if item.has_labels %}
<li><a href='#' id='print-label'><span class='fas fa-tag'></span> {% trans "Print Label" %}</a></li>
{% endif %}
{% if item.has_test_reports %}
<li><a href='#' id='stock-test-report'><span class='fas fa-file-pdf'></span> {% trans "Test Report" %}</a></li>
{% endif %}
</ul>
</div>
{% endif %}
<!-- Stock adjustment menu --> <!-- Stock adjustment menu -->
{% if roles.stock.change and not item.is_building %} {% if roles.stock.change and not item.is_building %}
<div class='btn-group'> <div class='btn-group'>
@ -168,9 +181,6 @@ InvenTree | {% trans "Stock Item" %} - {{ item }}
</ul> </ul>
</div> </div>
{% endif %} {% endif %}
<button type='button' class='btn btn-default' id='stock-test-report' title='{% trans "Generate test report" %}'>
<span class='fas fa-file-invoice'/>
</button>
</div> </div>
{% endblock %} {% endblock %}