Merge branch 'master' of https://github.com/inventree/InvenTree into price-history

This commit is contained in:
Matthias 2021-05-13 22:58:01 +02:00
commit be92efe7b9
20 changed files with 223 additions and 65 deletions

View File

@ -1,14 +1,31 @@
function attachClipboard(selector) { function attachClipboard(selector, containerselector, textElement) {
// set container
new ClipboardJS(selector, { if (containerselector){
text: function(trigger) { containerselector = document.getElementById(containerselector);
var content = trigger.parentElement.parentElement.textContent; } else {
containerselector = document.body;
return content.trim();
} }
// set text-function
if (textElement){
text = function() {
return document.getElementById(textElement).textContent;
}
} else {
text = function() {
var content = trigger.parentElement.parentElement.textContent;return content.trim();
}
}
// create Clipboard
var cis = new ClipboardJS(selector, {
text: text,
container: containerselector
}); });
console.log(cis);
} }
function inventreeDocReady() { function inventreeDocReady() {
/* Run this function when the HTML document is loaded. /* Run this function when the HTML document is loaded.
* This will be called for every page that extends "base.html" * This will be called for every page that extends "base.html"
@ -62,6 +79,8 @@ function inventreeDocReady() {
// Initialize clipboard-buttons // Initialize clipboard-buttons
attachClipboard('.clip-btn'); attachClipboard('.clip-btn');
attachClipboard('.clip-btn', 'modal-about'); // modals
attachClipboard('.clip-btn-version', 'modal-about', 'about-copy-text'); // version-text
} }

View File

@ -19,12 +19,12 @@
<tr> <tr>
<td><span class='fas fa-info'></span></td> <td><span class='fas fa-info'></span></td>
<td>{% trans "Description" %}</td> <td>{% trans "Description" %}</td>
<td>{{ build.title }}</td> <td>{{ build.title }}{% include "clip.html"%}</td>
</tr> </tr>
<tr> <tr>
<td><span class='fas fa-shapes'></span></td> <td><span class='fas fa-shapes'></span></td>
<td>{% trans "Part" %}</td> <td>{% trans "Part" %}</td>
<td><a href="{% url 'part-build' build.part.id %}">{{ build.part.full_name }}</a></td> <td><a href="{% url 'part-build' build.part.id %}">{{ build.part.full_name }}</a>{% include "clip.html"%}</td>
</tr> </tr>
<tr> <tr>
<td></td> <td></td>
@ -35,7 +35,7 @@
<td>{% trans "Stock Source" %}</td> <td>{% trans "Stock Source" %}</td>
<td> <td>
{% if build.take_from %} {% if build.take_from %}
<a href="{% url 'stock-location-detail' build.take_from.id %}">{{ build.take_from }}</a> <a href="{% url 'stock-location-detail' build.take_from.id %}">{{ build.take_from }}</a>{% include "clip.html"%}
{% else %} {% else %}
<i>{% trans "Stock can be taken from any available location." %}</i> <i>{% trans "Stock can be taken from any available location." %}</i>
{% endif %} {% endif %}
@ -48,7 +48,7 @@
{% if build.destination %} {% if build.destination %}
<a href="{% url 'stock-location-detail' build.destination.id %}"> <a href="{% url 'stock-location-detail' build.destination.id %}">
{{ build.destination }} {{ build.destination }}
</a> </a>{% include "clip.html"%}
{% else %} {% else %}
<i>{% trans "Destination location not specified" %}</i> <i>{% trans "Destination location not specified" %}</i>
{% endif %} {% endif %}
@ -68,28 +68,28 @@
<tr> <tr>
<td><span class='fas fa-layer-group'></span></td> <td><span class='fas fa-layer-group'></span></td>
<td>{% trans "Batch" %}</td> <td>{% trans "Batch" %}</td>
<td>{{ build.batch }}</td> <td>{{ build.batch }}{% include "clip.html"%}</td>
</tr> </tr>
{% endif %} {% endif %}
{% if build.parent %} {% if build.parent %}
<tr> <tr>
<td><span class='fas fa-sitemap'></span></td> <td><span class='fas fa-sitemap'></span></td>
<td>{% trans "Parent Build" %}</td> <td>{% trans "Parent Build" %}</td>
<td><a href="{% url 'build-detail' build.parent.id %}">{{ build.parent }}</a></td> <td><a href="{% url 'build-detail' build.parent.id %}">{{ build.parent }}</a>{% include "clip.html"%}</td>
</tr> </tr>
{% endif %} {% endif %}
{% if build.sales_order %} {% if build.sales_order %}
<tr> <tr>
<td><span class='fas fa-dolly'></span></td> <td><span class='fas fa-dolly'></span></td>
<td>{% trans "Sales Order" %}</td> <td>{% trans "Sales Order" %}</td>
<td><a href="{% url 'so-detail' build.sales_order.id %}">{{ build.sales_order }}</a></td> <td><a href="{% url 'so-detail' build.sales_order.id %}">{{ build.sales_order }}</a>{% include "clip.html"%}</td>
</tr> </tr>
{% endif %} {% endif %}
{% if build.link %} {% if build.link %}
<tr> <tr>
<td><span class='fas fa-link'></span></td> <td><span class='fas fa-link'></span></td>
<td>{% trans "External Link" %}</td> <td>{% trans "External Link" %}</td>
<td><a href="{{ build.link }}">{{ build.link }}</a></td> <td><a href="{{ build.link }}">{{ build.link }}</a>{% include "clip.html"%}</td>
</tr> </tr>
{% endif %} {% endif %}
{% if build.issued_by %} {% if build.issued_by %}

View File

@ -68,35 +68,35 @@
<tr> <tr>
<td><span class='fas fa-globe'></span></td> <td><span class='fas fa-globe'></span></td>
<td>{% trans "Website" %}</td> <td>{% trans "Website" %}</td>
<td><a href="{{ company.website }}">{{ company.website }}</a></td> <td><a href="{{ company.website }}">{{ company.website }}</a>{% include "clip.html"%}</td>
</tr> </tr>
{% endif %} {% endif %}
{% if company.address %} {% if company.address %}
<tr> <tr>
<td><span class='fas fa-map-marked-alt'></span></td> <td><span class='fas fa-map-marked-alt'></span></td>
<td>{% trans "Address" %}</td> <td>{% trans "Address" %}</td>
<td>{{ company.address }}</td> <td>{{ company.address }}{% include "clip.html"%}</td>
</tr> </tr>
{% endif %} {% endif %}
{% if company.phone %} {% if company.phone %}
<tr> <tr>
<td><span class='fas fa-phone'></span></td> <td><span class='fas fa-phone'></span></td>
<td>{% trans "Phone" %}</td> <td>{% trans "Phone" %}</td>
<td>{{ company.phone }}</td> <td>{% include "tel.html" with tel=company.phone %}</td>
</tr> </tr>
{% endif %} {% endif %}
{% if company.email %} {% if company.email %}
<tr> <tr>
<td><span class='fas fa-at'></span></td> <td><span class='fas fa-at'></span></td>
<td>{% trans "Email" %}</td> <td>{% trans "Email" %}</td>
<td>{{ company.email }}</td> <td>{% include "mail.html" with mail=company.email %}</td>
</tr> </tr>
{% endif %} {% endif %}
{% if company.contact %} {% if company.contact %}
<tr> <tr>
<td><span class='fas fa-user'></span></td> <td><span class='fas fa-user'></span></td>
<td>{% trans "Contact" %}</td> <td>{% trans "Contact" %}</td>
<td>{{ company.contact }}</td> <td>{{ company.contact }}{% include "clip.html"%}</td>
</tr> </tr>
{% endif %} {% endif %}
</table> </table>

View File

@ -19,20 +19,20 @@
<tr> <tr>
<td><span class='fas fa-font'></span></td> <td><span class='fas fa-font'></span></td>
<td>{% trans "Company Name" %}</td> <td>{% trans "Company Name" %}</td>
<td>{{ company.name }}</td> <td>{{ company.name }}{% include "clip.html"%}</td>
</tr> </tr>
{% if company.description %} {% if company.description %}
<tr> <tr>
<td><span class='fas fa-info'></span></td> <td><span class='fas fa-info'></span></td>
<td>{% trans "Description" %}</td> <td>{% trans "Description" %}</td>
<td>{{ company.description }}</td> <td>{{ company.description }}{% include "clip.html"%}</td>
</tr> </tr>
{% endif %} {% endif %}
<tr> <tr>
<td><span class='fas fa-globe'></span></td> <td><span class='fas fa-globe'></span></td>
<td>{% trans "Website" %}</td> <td>{% trans "Website" %}</td>
<td> <td>
{% if company.website %}<a href='{{ company.website }}'>{{ company.website }}</a> {% if company.website %}<a href='{{ company.website }}'>{{ company.website }}</a>{% include "clip.html"%}
{% else %}<i>{% trans "No website specified" %}</i> {% else %}<i>{% trans "No website specified" %}</i>
{% endif %} {% endif %}
</td> </td>

View File

@ -62,7 +62,7 @@ src="{% static 'img/blank_image.png' %}"
<td>{% trans "Internal Part" %}</td> <td>{% trans "Internal Part" %}</td>
<td> <td>
{% if part.part %} {% if part.part %}
<a href="{% url 'part-manufacturers' part.part.id %}">{{ part.part.full_name }}</a> <a href="{% url 'part-manufacturers' part.part.id %}">{{ part.part.full_name }}</a>{% include "clip.html"%}
{% endif %} {% endif %}
</td> </td>
</tr> </tr>
@ -70,24 +70,24 @@ src="{% static 'img/blank_image.png' %}"
<tr> <tr>
<td></td> <td></td>
<td>{% trans "Description" %}</td> <td>{% trans "Description" %}</td>
<td>{{ part.description }}</td> <td>{{ part.description }}{% include "clip.html"%}</td>
</tr> </tr>
{% endif %} {% endif %}
{% if part.link %} {% if part.link %}
<tr> <tr>
<td><span class='fas fa-link'></span></td> <td><span class='fas fa-link'></span></td>
<td>{% trans "External Link" %}</td> <td>{% trans "External Link" %}</td>
<td><a href="{{ part.link }}">{{ part.link }}</a></td> <td><a href="{{ part.link }}">{{ part.link }}</a>{% include "clip.html"%}</td>
</tr> </tr>
{% endif %} {% endif %}
<tr> <tr>
<td><span class='fas fa-industry'></span></td> <td><span class='fas fa-industry'></span></td>
<td>{% trans "Manufacturer" %}</td> <td>{% trans "Manufacturer" %}</td>
<td><a href="{% url 'company-detail-manufacturer-parts' part.manufacturer.id %}">{{ part.manufacturer.name }}</a></td></tr> <td><a href="{% url 'company-detail-manufacturer-parts' part.manufacturer.id %}">{{ part.manufacturer.name }}</a>{% include "clip.html"%}</td></tr>
<tr> <tr>
<td><span class='fas fa-hashtag'></span></td> <td><span class='fas fa-hashtag'></span></td>
<td>{% trans "MPN" %}</td> <td>{% trans "MPN" %}</td>
<td>{{ part.MPN }}</td> <td>{{ part.MPN }}{% include "clip.html"%}</td>
</tr> </tr>
</table> </table>
{% endblock %} {% endblock %}

View File

@ -61,7 +61,7 @@ src="{% static 'img/blank_image.png' %}"
<td>{% trans "Internal Part" %}</td> <td>{% trans "Internal Part" %}</td>
<td> <td>
{% if part.part %} {% if part.part %}
<a href="{% url 'part-suppliers' part.part.id %}">{{ part.part.full_name }}</a> <a href="{% url 'part-suppliers' part.part.id %}">{{ part.part.full_name }}</a>{% include "clip.html"%}
{% endif %} {% endif %}
</td> </td>
</tr> </tr>
@ -69,51 +69,52 @@ src="{% static 'img/blank_image.png' %}"
<tr> <tr>
<td></td> <td></td>
<td>{% trans "Description" %}</td> <td>{% trans "Description" %}</td>
<td>{{ part.description }}</td> <td>{{ part.description }}{% include "clip.html"%}</td>
</tr> </tr>
{% endif %} {% endif %}
{% if part.link %} {% if part.link %}
<tr> <tr>
<td><span class='fas fa-link'></span></td> <td><span class='fas fa-link'></span></td>
<td>{% trans "External Link" %}</td> <td>{% trans "External Link" %}</td>
<td><a href="{{ part.link }}">{{ part.link }}</a></td> <td><a href="{{ part.link }}">{{ part.link }}</a>{% include "clip.html"%}</td>
</tr> </tr>
{% endif %} {% endif %}
<tr> <tr>
<td><span class='fas fa-building'></span></td> <td><span class='fas fa-building'></span></td>
<td>{% trans "Supplier" %}</td> <td>{% trans "Supplier" %}</td>
<td><a href="{% url 'company-detail-supplier-parts' part.supplier.id %}">{{ part.supplier.name }}</a></td></tr> <td><a href="{% url 'company-detail-supplier-parts' part.supplier.id %}">{{ part.supplier.name }}</a>{% include "clip.html"%}</td></tr>
<tr> <tr>
<td><span class='fas fa-hashtag'></span></td> <td><span class='fas fa-hashtag'></span></td>
<td>{% trans "SKU" %}</td> <td>{% trans "SKU" %}</td>
<td>{{ part.SKU }}</tr> <td>{{ part.SKU }}{% include "clip.html"%}</tr>
</tr> </tr>
{% if part.manufacturer_part.manufacturer %} {% if part.manufacturer_part.manufacturer %}
<tr> <tr>
<td><span class='fas fa-industry'></span></td> <td><span class='fas fa-industry'></span></td>
<td>{% trans "Manufacturer" %}</td> <td>{% trans "Manufacturer" %}</td>
<td><a href="{% url 'company-detail-manufacturer-parts' part.manufacturer_part.manufacturer.id %}">{{ part.manufacturer_part.manufacturer.name }}</a></td> <td><a href="{% url 'company-detail-manufacturer-parts' part.manufacturer_part.manufacturer.id %}">
{{ part.manufacturer_part.manufacturer.name }}</a>{% include "clip.html"%}</td>
</tr> </tr>
{% endif %} {% endif %}
{% if part.manufacturer_part.MPN %} {% if part.manufacturer_part.MPN %}
<tr> <tr>
<td><span class='fas fa-hashtag'></span></td> <td><span class='fas fa-hashtag'></span></td>
<td>{% trans "MPN" %}</td> <td>{% trans "MPN" %}</td>
<td><a href="{% url 'manufacturer-part-detail' part.manufacturer_part.id %}">{{ part.manufacturer_part.MPN }}</a></td> <td><a href="{% url 'manufacturer-part-detail' part.manufacturer_part.id %}">{{ part.manufacturer_part.MPN }}</a>{% include "clip.html"%}</td>
</tr> </tr>
{% endif %} {% endif %}
{% if part.packaging %} {% if part.packaging %}
<tr> <tr>
<td><span class='fas fa-cube'></span></td> <td><span class='fas fa-cube'></span></td>
<td>{% trans "Packaging" %}</td> <td>{% trans "Packaging" %}</td>
<td>{{ part.packaging }}</td> <td>{{ part.packaging }}{% include "clip.html"%}</td>
</tr> </tr>
{% endif %} {% endif %}
{% if part.note %} {% if part.note %}
<tr> <tr>
<td><span class='fas fa-sticky-note'></span></td> <td><span class='fas fa-sticky-note'></span></td>
<td>{% trans "Note" %}</td> <td>{% trans "Note" %}</td>
<td>{{ part.note }}</td> <td>{{ part.note }}{% include "clip.html"%}</td>
</tr> </tr>
{% endif %} {% endif %}
</table> </table>

View File

@ -28,14 +28,14 @@
<tr><td>{% trans "External Link" %}</td><td><a href="{{ part.link }}">{{ part.link }}</a></td></tr> <tr><td>{% trans "External Link" %}</td><td><a href="{{ part.link }}">{{ part.link }}</a></td></tr>
{% endif %} {% endif %}
{% if part.description %} {% if part.description %}
<tr><td>{% trans "Description" %}</td><td>{{ part.description }}</td></tr> <tr><td>{% trans "Description" %}</td><td>{{ part.description }}{% include "clip.html"%}</td></tr>
{% endif %} {% endif %}
{% if part.manufacturer %} {% if part.manufacturer %}
<tr><td>{% trans "Manufacturer" %}</td><td>{{ part.manufacturer }}</td></tr> <tr><td>{% trans "Manufacturer" %}</td><td>{{ part.manufacturer }}{% include "clip.html"%}</td></tr>
<tr><td>{% trans "MPN" %}</td><td>{{ part.MPN }}</td></tr> <tr><td>{% trans "MPN" %}</td><td>{{ part.MPN }}{% include "clip.html"%}</td></tr>
{% endif %} {% endif %}
{% if part.note %} {% if part.note %}
<tr><td>{% trans "Note" %}</td><td>{{ part.note }}</td></tr> <tr><td>{% trans "Note" %}</td><td>{{ part.note }}{% include "clip.html"%}</td></tr>
{% endif %} {% endif %}
</table> </table>

View File

@ -63,16 +63,23 @@ class LabelPrintMixin:
# In debug mode, generate single HTML output, rather than PDF # In debug mode, generate single HTML output, rather than PDF
debug_mode = common.models.InvenTreeSetting.get_setting('REPORT_DEBUG_MODE') debug_mode = common.models.InvenTreeSetting.get_setting('REPORT_DEBUG_MODE')
label_name = "label.pdf"
# Merge one or more PDF files into a single download # Merge one or more PDF files into a single download
for item in items_to_print: for item in items_to_print:
label = self.get_object() label = self.get_object()
label.object_to_print = item label.object_to_print = item
label_name = label.generate_filename(request)
if debug_mode: if debug_mode:
outputs.append(label.render_as_string(request)) outputs.append(label.render_as_string(request))
else: else:
outputs.append(label.render(request)) outputs.append(label.render(request))
if not label_name.endswith(".pdf"):
label_name += ".pdf"
if debug_mode: if debug_mode:
""" """
Contatenate all rendered templates into a single HTML string, Contatenate all rendered templates into a single HTML string,
@ -103,7 +110,7 @@ class LabelPrintMixin:
return InvenTree.helpers.DownloadFile( return InvenTree.helpers.DownloadFile(
pdf, pdf,
'inventree_label.pdf', label_name,
content_type='application/pdf' content_type='application/pdf'
) )

View File

@ -0,0 +1,23 @@
# Generated by Django 3.2 on 2021-05-13 03:27
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('label', '0006_auto_20210222_1535'),
]
operations = [
migrations.AddField(
model_name='stockitemlabel',
name='filename_pattern',
field=models.CharField(default='label.pdf', help_text='Pattern for generating label filenames', max_length=100, verbose_name='Filename Pattern'),
),
migrations.AddField(
model_name='stocklocationlabel',
name='filename_pattern',
field=models.CharField(default='label.pdf', help_text='Pattern for generating label filenames', max_length=100, verbose_name='Filename Pattern'),
),
]

View File

@ -15,6 +15,7 @@ from django.db import models
from django.core.validators import FileExtensionValidator, MinValueValidator from django.core.validators import FileExtensionValidator, MinValueValidator
from django.core.exceptions import ValidationError, FieldError from django.core.exceptions import ValidationError, FieldError
from django.template import Template, Context
from django.template.loader import render_to_string from django.template.loader import render_to_string
from django.utils.translation import gettext_lazy as _ from django.utils.translation import gettext_lazy as _
@ -138,6 +139,13 @@ class LabelTemplate(models.Model):
validators=[MinValueValidator(2)] validators=[MinValueValidator(2)]
) )
filename_pattern = models.CharField(
default="label.pdf",
verbose_name=_('Filename Pattern'),
help_text=_('Pattern for generating label filenames'),
max_length=100,
)
@property @property
def template_name(self): def template_name(self):
""" """
@ -162,6 +170,19 @@ class LabelTemplate(models.Model):
return {} return {}
def generate_filename(self, request, **kwargs):
"""
Generate a filename for this label
"""
template_string = Template(self.filename_pattern)
ctx = self.context(request)
context = Context(ctx)
return template_string.render(context)
def context(self, request): def context(self, request):
""" """
Provides context data to the template. Provides context data to the template.
@ -201,6 +222,7 @@ class LabelTemplate(models.Model):
self.template_name, self.template_name,
base_url=request.build_absolute_uri("/"), base_url=request.build_absolute_uri("/"),
presentational_hints=True, presentational_hints=True,
filename=self.generate_filename(request),
**kwargs **kwargs
) )

View File

@ -33,7 +33,7 @@ src="{% static 'img/blank_image.png' %}"
{% endif %} {% endif %}
</h3> </h3>
<hr> <hr>
<p>{{ order.description }}</p> <p>{{ order.description }}{% include "clip.html"%}</p>
<div class='btn-row'> <div class='btn-row'>
<div class='btn-group action-buttons' role='group'> <div class='btn-group action-buttons' role='group'>
<button type='button' class='btn btn-default' id='print-order-report' title='{% trans "Print" %}'> <button type='button' class='btn btn-default' id='print-order-report' title='{% trans "Print" %}'>
@ -75,7 +75,7 @@ src="{% static 'img/blank_image.png' %}"
<tr> <tr>
<td><span class='fas fa-hashtag'></span></td> <td><span class='fas fa-hashtag'></span></td>
<td>{% trans "Order Reference" %}</td> <td>{% trans "Order Reference" %}</td>
<td>{{ order.reference }}</td> <td>{{ order.reference }}{% include "clip.html"%}</td>
</tr> </tr>
<tr> <tr>
<td><span class='fas fa-info'></span></td> <td><span class='fas fa-info'></span></td>
@ -90,20 +90,20 @@ src="{% static 'img/blank_image.png' %}"
<tr> <tr>
<td><span class='fas fa-building'></span></td> <td><span class='fas fa-building'></span></td>
<td>{% trans "Supplier" %}</td> <td>{% trans "Supplier" %}</td>
<td><a href="{% url 'company-detail' order.supplier.id %}">{{ order.supplier.name }}</a></td> <td><a href="{% url 'company-detail' order.supplier.id %}">{{ order.supplier.name }}</a>{% include "clip.html"%}</td>
</tr> </tr>
{% if order.supplier_reference %} {% if order.supplier_reference %}
<tr> <tr>
<td><span class='fas fa-hashtag'></span></td> <td><span class='fas fa-hashtag'></span></td>
<td>{% trans "Supplier Reference" %}</td> <td>{% trans "Supplier Reference" %}</td>
<td>{{ order.supplier_reference }}</td> <td>{{ order.supplier_reference }}{% include "clip.html"%}</td>
</tr> </tr>
{% endif %} {% endif %}
{% if order.link %} {% if order.link %}
<tr> <tr>
<td><span class='fas fa-link'></span></td> <td><span class='fas fa-link'></span></td>
<td>External Link</td> <td>External Link</td>
<td><a href="{{ order.link }}">{{ order.link }}</a></td> <td><a href="{{ order.link }}">{{ order.link }}</a>{% include "clip.html"%}</td>
</tr> </tr>
{% endif %} {% endif %}
<tr> <tr>

View File

@ -42,7 +42,7 @@ src="{% static 'img/blank_image.png' %}"
{% endif %} {% endif %}
</h3> </h3>
<hr> <hr>
<p>{{ order.description }}</p> <p>{{ order.description }}{% include "clip.html"%}</p>
<div class='btn-row'> <div class='btn-row'>
<div class='btn-group action-buttons'> <div class='btn-group action-buttons'>
<button type='button' class='btn btn-default' id='print-order-report' title='{% trans "Print" %}'> <button type='button' class='btn btn-default' id='print-order-report' title='{% trans "Print" %}'>
@ -75,7 +75,7 @@ src="{% static 'img/blank_image.png' %}"
<tr> <tr>
<td><span class='fas fa-hashtag'></span></td> <td><span class='fas fa-hashtag'></span></td>
<td>{% trans "Order Reference" %}</td> <td>{% trans "Order Reference" %}</td>
<td>{{ order.reference }}</td> <td>{{ order.reference }}{% include "clip.html"%}</td>
</tr> </tr>
<tr> <tr>
<td><span class='fas fa-info'></span></td> <td><span class='fas fa-info'></span></td>
@ -90,20 +90,20 @@ src="{% static 'img/blank_image.png' %}"
<tr> <tr>
<td><span class='fas fa-building'></span></td> <td><span class='fas fa-building'></span></td>
<td>{% trans "Customer" %}</td> <td>{% trans "Customer" %}</td>
<td><a href="{% url 'company-detail' order.customer.id %}">{{ order.customer.name }}</a></td> <td><a href="{% url 'company-detail' order.customer.id %}">{{ order.customer.name }}</a>{% include "clip.html"%}</td>
</tr> </tr>
{% if order.customer_reference %} {% if order.customer_reference %}
<tr> <tr>
<td><span class='fas fa-hashtag'></span></td> <td><span class='fas fa-hashtag'></span></td>
<td>{% trans "Customer Reference" %}</td> <td>{% trans "Customer Reference" %}</td>
<td>{{ order.customer_reference }}</td> <td>{{ order.customer_reference }}{% include "clip.html"%}</td>
</tr> </tr>
{% endif %} {% endif %}
{% if order.link %} {% if order.link %}
<tr> <tr>
<td><span class='fas fa-link'></span></td> <td><span class='fas fa-link'></span></td>
<td>External Link</td> <td>External Link</td>
<td><a href="{{ order.link }}">{{ order.link }}</a></td> <td><a href="{{ order.link }}">{{ order.link }}</a>{% include "clip.html"%}</td>
</tr> </tr>
{% endif %} {% endif %}
<tr> <tr>

View File

@ -58,14 +58,14 @@
<tr> <tr>
<td></td> <td></td>
<td><strong>{% trans "Variant Of" %}</strong></td> <td><strong>{% trans "Variant Of" %}</strong></td>
<td><a href="{% url 'part-detail' part.variant_of.id %}">{{ part.variant_of.full_name }}</a></td> <td><a href="{% url 'part-detail' part.variant_of.id %}">{{ part.variant_of.full_name }}</a>{% include "clip.html"%}</td>
</tr> </tr>
{% endif %} {% endif %}
{% if part.keywords %} {% if part.keywords %}
<tr> <tr>
<td><span class='fas fa-key'></span></td> <td><span class='fas fa-key'></span></td>
<td><strong>{% trans "Keywords" %}</strong></td> <td><strong>{% trans "Keywords" %}</strong></td>
<td>{{ part.keywords }}</td> <td>{{ part.keywords }}{% include "clip.html"%}</td>
</tr> </tr>
{% endif %} {% endif %}
<tr> <tr>
@ -73,7 +73,7 @@
<td><strong>{% trans "Category" %}</strong></td> <td><strong>{% trans "Category" %}</strong></td>
<td> <td>
{% if part.category %} {% if part.category %}
<a href="{% url 'category-detail' part.category.id %}">{{ part.category.pathstring }}</a> <a href="{% url 'category-detail' part.category.id %}">{{ part.category.pathstring }}</a>{% include "clip.html"%}
{% endif %} {% endif %}
</td> </td>
</tr> </tr>
@ -81,14 +81,14 @@
<tr> <tr>
<td><span class='fas fa-link'></span></td> <td><span class='fas fa-link'></span></td>
<td><strong>{% trans "External Link" %}</strong></td> <td><strong>{% trans "External Link" %}</strong></td>
<td><a href="{{ part.link }}">{{ part.link }}</a></td> <td><a href="{{ part.link }}">{{ part.link }}</a>{% include "clip.html"%}</td>
</tr> </tr>
{% endif %} {% endif %}
{% if part.default_location %} {% if part.default_location %}
<tr> <tr>
<td><span class='fas fa-map-marker-alt'></span></td> <td><span class='fas fa-map-marker-alt'></span></td>
<td><strong>{% trans "Default Location" %}</strong></td> <td><strong>{% trans "Default Location" %}</strong></td>
<td><a href="{% url 'stock-location-detail' part.default_location.id %}">{{ part.default_location.pathstring }}</a></td> <td><a href="{% url 'stock-location-detail' part.default_location.id %}">{{ part.default_location.pathstring }}</a>{% include "clip.html"%}</td>
</tr> </tr>
{% endif %} {% endif %}
{% if part.default_supplier %} {% if part.default_supplier %}
@ -96,15 +96,15 @@
<td></td> <td></td>
<td><strong>{% trans "Default Supplier" %}</strong></td> <td><strong>{% trans "Default Supplier" %}</strong></td>
<td><a href="{% url 'supplier-part-detail' part.default_supplier.id %}"> <td><a href="{% url 'supplier-part-detail' part.default_supplier.id %}">
{{ part.default_supplier.supplier.name }} | {{ part.default_supplier.SKU }}{% include "clip.html"%} {{ part.default_supplier.supplier.name }} | {{ part.default_supplier.SKU }}
</a></td> </a>{% include "clip.html"%}</td>
</tr> </tr>
{% endif %} {% endif %}
{% if part.units %} {% if part.units %}
<tr> <tr>
<td></td> <td></td>
<td><strong>{% trans "Units" %}</strong></td> <td><strong>{% trans "Units" %}</strong></td>
<td>{{ part.units }}</td> <td>{{ part.units }}{% include "clip.html"%}</td>
</tr> </tr>
{% endif %} {% endif %}
{% if part.minimum_stock > 0 %} {% if part.minimum_stock > 0 %}

View File

@ -208,16 +208,24 @@ class ReportPrintMixin:
# In debug mode, generate single HTML output, rather than PDF # In debug mode, generate single HTML output, rather than PDF
debug_mode = common.models.InvenTreeSetting.get_setting('REPORT_DEBUG_MODE') debug_mode = common.models.InvenTreeSetting.get_setting('REPORT_DEBUG_MODE')
# Start with a default report name
report_name = "report.pdf"
# Merge one or more PDF files into a single download # Merge one or more PDF files into a single download
for item in items_to_print: for item in items_to_print:
report = self.get_object() report = self.get_object()
report.object_to_print = item report.object_to_print = item
report_name = report.generate_filename(request)
if debug_mode: if debug_mode:
outputs.append(report.render_as_string(request)) outputs.append(report.render_as_string(request))
else: else:
outputs.append(report.render(request)) outputs.append(report.render(request))
if not report_name.endswith('.pdf'):
report_name += '.pdf'
if debug_mode: if debug_mode:
""" """
Contatenate all rendered templates into a single HTML string, Contatenate all rendered templates into a single HTML string,
@ -248,7 +256,7 @@ class ReportPrintMixin:
return InvenTree.helpers.DownloadFile( return InvenTree.helpers.DownloadFile(
pdf, pdf,
'inventree_report.pdf', report_name,
content_type='application/pdf' content_type='application/pdf'
) )

View File

@ -0,0 +1,38 @@
# Generated by Django 3.2 on 2021-05-13 03:03
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('report', '0015_auto_20210403_1837'),
]
operations = [
migrations.AddField(
model_name='billofmaterialsreport',
name='filename_pattern',
field=models.CharField(default='report.pdf', help_text='Pattern for generating report filenames', max_length=100, verbose_name='Filename Pattern'),
),
migrations.AddField(
model_name='buildreport',
name='filename_pattern',
field=models.CharField(default='report.pdf', help_text='Pattern for generating report filenames', max_length=100, verbose_name='Filename Pattern'),
),
migrations.AddField(
model_name='purchaseorderreport',
name='filename_pattern',
field=models.CharField(default='report.pdf', help_text='Pattern for generating report filenames', max_length=100, verbose_name='Filename Pattern'),
),
migrations.AddField(
model_name='salesorderreport',
name='filename_pattern',
field=models.CharField(default='report.pdf', help_text='Pattern for generating report filenames', max_length=100, verbose_name='Filename Pattern'),
),
migrations.AddField(
model_name='testreport',
name='filename_pattern',
field=models.CharField(default='report.pdf', help_text='Pattern for generating report filenames', max_length=100, verbose_name='Filename Pattern'),
),
]

View File

@ -16,6 +16,7 @@ from django.conf import settings
from django.core.exceptions import ValidationError, FieldError from django.core.exceptions import ValidationError, FieldError
from django.template.loader import render_to_string from django.template.loader import render_to_string
from django.template import Template, Context
from django.core.files.storage import FileSystemStorage from django.core.files.storage import FileSystemStorage
from django.core.validators import FileExtensionValidator from django.core.validators import FileExtensionValidator
@ -224,6 +225,7 @@ class ReportTemplateBase(ReportBase):
All context to be passed to the renderer. All context to be passed to the renderer.
""" """
# Generate custom context data based on the particular report subclass
context = self.get_context_data(request) context = self.get_context_data(request)
context['base_url'] = common.models.InvenTreeSetting.get_setting('INVENTREE_BASE_URL') context['base_url'] = common.models.InvenTreeSetting.get_setting('INVENTREE_BASE_URL')
@ -238,9 +240,22 @@ class ReportTemplateBase(ReportBase):
return context return context
def generate_filename(self, request, **kwargs):
"""
Generate a filename for this report
"""
template_string = Template(self.filename_pattern)
ctx = self.context(request)
context = Context(ctx)
return template_string.render(context)
def render_as_string(self, request, **kwargs): def render_as_string(self, request, **kwargs):
""" """
Render the report to a HTML stiring. Render the report to a HTML string.
Useful for debug mode (viewing generated code) Useful for debug mode (viewing generated code)
""" """
@ -263,12 +278,20 @@ class ReportTemplateBase(ReportBase):
self.template_name, self.template_name,
base_url=request.build_absolute_uri("/"), base_url=request.build_absolute_uri("/"),
presentational_hints=True, presentational_hints=True,
filename=self.generate_filename(request),
**kwargs) **kwargs)
return wp.render_to_response( return wp.render_to_response(
self.context(request), self.context(request),
**kwargs) **kwargs)
filename_pattern = models.CharField(
default="report.pdf",
verbose_name=_('Filename Pattern'),
help_text=_('Pattern for generating report filenames'),
max_length=100,
)
enabled = models.BooleanField( enabled = models.BooleanField(
default=True, default=True,
verbose_name=_('Enabled'), verbose_name=_('Enabled'),
@ -326,6 +349,7 @@ class TestReport(ReportTemplateBase):
return { return {
'stock_item': stock_item, 'stock_item': stock_item,
'serial': stock_item.serial,
'part': stock_item.part, 'part': stock_item.part,
'results': stock_item.testResultMap(include_installed=self.include_installed), 'results': stock_item.testResultMap(include_installed=self.include_installed),
'result_list': stock_item.testResultList(include_installed=self.include_installed) 'result_list': stock_item.testResultList(include_installed=self.include_installed)
@ -367,6 +391,7 @@ class BuildReport(ReportTemplateBase):
'bom_items': my_build.part.get_bom_items(), 'bom_items': my_build.part.get_bom_items(),
'reference': my_build.reference, 'reference': my_build.reference,
'quantity': my_build.quantity, 'quantity': my_build.quantity,
'title': str(my_build),
} }

View File

@ -21,7 +21,7 @@
<td><span class='fas fa-hashtag'></span></td> <td><span class='fas fa-hashtag'></span></td>
<td>{% trans "InvenTree Version" %}</td> <td>{% trans "InvenTree Version" %}</td>
<td> <td>
<a href="https://github.com/inventree/InvenTree/releases">{% inventree_version %}</a> <a href="https://github.com/inventree/InvenTree/releases">{% inventree_version %}</a>{% include "clip.html" %}
{% if up_to_date %} {% if up_to_date %}
<span class='label label-green float-right'>{% trans "Up to Date" %}</span> <span class='label label-green float-right'>{% trans "Up to Date" %}</span>
{% else %} {% else %}
@ -32,20 +32,20 @@
<tr> <tr>
<td><span class='fas fa-hashtag'></span></td> <td><span class='fas fa-hashtag'></span></td>
<td>{% trans "Django Version" %}</td> <td>{% trans "Django Version" %}</td>
<td><a href="https://www.djangoproject.com/">{% django_version %}</a></td> <td><a href="https://www.djangoproject.com/">{% django_version %}</a>{% include "clip.html" %}</td>
</tr> </tr>
{% inventree_commit_hash as hash %} {% inventree_commit_hash as hash %}
{% if hash %} {% if hash %}
<tr> <tr>
<td><span class='fas fa-code-branch'></span></td> <td><span class='fas fa-code-branch'></span></td>
<td>{% trans "Commit Hash" %}</td><td>{{ hash }}</td> <td>{% trans "Commit Hash" %}</td><td>{{ hash }}{% include "clip.html" %}</td>
</tr> </tr>
{% endif %} {% endif %}
{% inventree_commit_date as commit_date %} {% inventree_commit_date as commit_date %}
{% if commit_date %} {% if commit_date %}
<tr> <tr>
<td><span class='fas fa-calendar-alt'></span></td> <td><span class='fas fa-calendar-alt'></span></td>
<td>{% trans "Commit Date" %}</td><td>{{ commit_date }}</td> <td>{% trans "Commit Date" %}</td><td>{{ commit_date }}{% include "clip.html" %}</td>
</tr> </tr>
{% endif %} {% endif %}
<tr> <tr>
@ -73,6 +73,14 @@
<td>{% trans "Submit Bug Report" %}</td> <td>{% trans "Submit Bug Report" %}</td>
<td><a href='{% inventree_github_url %}/issues'>{% inventree_github_url %}issues</a></td> <td><a href='{% inventree_github_url %}/issues'>{% inventree_github_url %}issues</a></td>
</tr> </tr>
<tr><td></td><td></td>
<td>
<span style="display: none;" id="about-copy-text">{% include "version.html" %}</span>
<span class="float-right">
<button class="btn clip-btn-version" type="button" data-toggle='tooltip' title='{% trans "copy to clipboard" %}'><i class="fas fa-copy"></i> {% trans "copy version information" %}</button>
</span>
</td>
</tr>
</table> </table>
</div> </div>

View File

@ -0,0 +1 @@
<a href="mailto:{{ mail }}">{{ mail }}</a>{% include "clip.html"%}

View File

@ -0,0 +1 @@
<a href="tel:{{ tel }}">{{ tel }}</a>{% include "clip.html"%}

View File

@ -0,0 +1,5 @@
# Version Information:{% load inventree_extras %}
InvenTree-Version: {% inventree_version %}
Django Version: {% django_version %}
{% inventree_commit_hash as hash %}{% if hash %}Commit Hash: {{ hash }}{% endif %}
{% inventree_commit_date as commit_date %}{% if commit_date %}Commit Date: {{ commit_date }}{% endif %}