mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Merge pull request #1205 from SchrodingersGat/hide-report-button
Rearrange button options for StockItem
This commit is contained in:
commit
c377fb7b0c
@ -16,7 +16,7 @@ from django.conf import settings
|
||||
from django.core.validators import FileExtensionValidator
|
||||
from django.core.exceptions import ValidationError
|
||||
|
||||
from stock.models import StockItem
|
||||
import stock.models
|
||||
|
||||
from InvenTree.helpers import validateFilterString
|
||||
|
||||
@ -191,7 +191,7 @@ class TestReport(ReportTemplateBase):
|
||||
|
||||
filters = validateFilterString(self.filters)
|
||||
|
||||
items = StockItem.objects.filter(**filters)
|
||||
items = stock.models.StockItem.objects.filter(**filters)
|
||||
|
||||
# Ensure the provided StockItem object matches the filters
|
||||
items = items.filter(pk=item.pk)
|
||||
|
@ -247,7 +247,7 @@ class TestReportFormatForm(HelperForm):
|
||||
templates = TestReport.objects.filter(enabled=True)
|
||||
|
||||
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))
|
||||
|
||||
return choices
|
||||
|
@ -31,6 +31,7 @@ from datetime import datetime, timedelta
|
||||
from InvenTree import helpers
|
||||
|
||||
import common.models
|
||||
import report.models
|
||||
|
||||
from InvenTree.status_codes import StockStatus
|
||||
from InvenTree.models import InvenTreeTree, InvenTreeAttachment
|
||||
@ -1306,6 +1307,41 @@ class StockItem(MPTTModel):
|
||||
|
||||
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')
|
||||
def before_delete_stock_item(sender, instance, using, **kwargs):
|
||||
|
@ -108,16 +108,29 @@ 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>
|
||||
<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='print-label'><span class='fas fa-tag'></span> {% trans "Print Label" %}</a></li>
|
||||
{% if roles.stock.change %}
|
||||
{% if item.uid %}
|
||||
<li><a href='#' id='unlink-barcode'><span class='fas fa-unlink'></span> {% trans "Unlink Barcode" %}</a></li>
|
||||
{% if item.uid %}
|
||||
<li><a href='#' id='unlink-barcode'><span class='fas fa-unlink'></span> {% trans "Unlink Barcode" %}</a></li>
|
||||
{% else %}
|
||||
<li><a href='#' id='link-barcode'><span class='fas fa-link'></span> {% trans "Link Barcode" %}</a></li>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
</ul>
|
||||
</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 -->
|
||||
{% if roles.stock.change and not item.is_building %}
|
||||
<div class='btn-group'>
|
||||
@ -168,9 +181,6 @@ InvenTree | {% trans "Stock Item" %} - {{ item }}
|
||||
</ul>
|
||||
</div>
|
||||
{% 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>
|
||||
|
||||
{% endblock %}
|
||||
|
Loading…
Reference in New Issue
Block a user