Add option to print build report

This commit is contained in:
Oliver Walters 2021-02-16 08:36:04 +11:00
parent e72aaf2e07
commit b222119653
2 changed files with 84 additions and 19 deletions

View File

@ -45,27 +45,35 @@ src="{% static 'img/blank_image.png' %}"
</h3>
<hr>
<p>{{ build.title }}</p>
<div class='btn-row'>
<div class='btn-group action-buttons'>
{% if roles.build.change %}
<button type='button' class='btn btn-default' id='build-edit' title='{% trans "Edit Build" %}'>
<span class='fas fa-edit icon-green'/>
<div class='btn-group action-buttons' role='group'>
<!-- Printing options -->
<div class='btn-group'>
<button id='print-options' title='{% trans "Print actions" %}' class='btn btn-default dropdown-toggle' type='button' data-toggle='dropdown'>
<span class='fas fa-print'></span> <span class='caret'></span>
</button>
{% if build.is_active %}
<button type='button' class='btn btn-default' id='build-complete' title='{% trans "Complete Build" %}'>
<span class='fas fa-tools'/>
</button>
<button type='button' class='btn btn-default btn-glyph' id='build-cancel' title='{% trans "Cancel Build" %}'>
<span class='fas fa-times-circle icon-red'/>
</button>
{% endif %}
{% endif %}
{% if build.status == BuildStatus.CANCELLED and roles.build.delete %}
<button type='button' class='btn btn-default btn-glyph' id='build-delete' title='{% trans "Delete Build" %}'>
<span class='fas fa-trash-alt icon-red'/>
</button>
{% endif %}
<ul class='dropdown-menu' role='menu'>
<li><a href='#' id='print-build-report'><span class='fas fa-file-pdf'></span> {% trans "Print Build Order" %}</a></li>
</ul>
</div>
{% if roles.build.change %}
<button type='button' class='btn btn-default' id='build-edit' title='{% trans "Edit Build" %}'>
<span class='fas fa-edit icon-green'/>
</button>
{% if build.is_active %}
<button type='button' class='btn btn-default' id='build-complete' title='{% trans "Complete Build" %}'>
<span class='fas fa-tools'/>
</button>
<button type='button' class='btn btn-default btn-glyph' id='build-cancel' title='{% trans "Cancel Build" %}'>
<span class='fas fa-times-circle icon-red'/>
</button>
{% endif %}
{% endif %}
{% if build.status == BuildStatus.CANCELLED and roles.build.delete %}
<button type='button' class='btn btn-default btn-glyph' id='build-delete' title='{% trans "Delete Build" %}'>
<span class='fas fa-trash-alt icon-red'/>
</button>
{% endif %}
</div>
{% endblock %}
@ -151,6 +159,10 @@ src="{% static 'img/blank_image.png' %}"
);
});
$('#print-build-report').click(function() {
printBuildReports([{{ build.pk }}]);
});
$("#build-delete").on('click', function() {
launchModalForm(
"{% url 'build-delete' build.id %}",

View File

@ -142,6 +142,59 @@ function printTestReports(items, options={}) {
}
function printBuildReports(builds, options={}) {
/**
* Print Build report for the provided build(s)
*/
if (builds.length == 0) {
showAlertDialog(
'{% trans "Select Builds" %}',
'{% trans "Build(s) must be selected before printing reports" %}',
);
return;
}
inventreeGet(
'{% url "api-build-report-list" %}',
{
enabled: true,
builds: builds,
},
{
success: function(response) {
if (response.length == 0) {
showAlertDialog(
'{% trans "No Reports Found" %}',
'{% trans "No report templates found which match selected build(s)" %}'
);
return;
}
// Select which report to print
selectReport(
response,
builds,
{
success: function(pk) {
var href = `/api/report/build/${pk}/print/?`;
builds.forEach(function(build) {
href += `builds[]=${build}&`;
});
window.location.href = href;
}
}
)
}
}
)
}
function printBomReports(parts, options={}) {
/**
* Print BOM reports for the provided part(s)