diff --git a/InvenTree/templates/js/model_renderers.js b/InvenTree/templates/js/model_renderers.js
index 9e98199bfa..f13388237d 100644
--- a/InvenTree/templates/js/model_renderers.js
+++ b/InvenTree/templates/js/model_renderers.js
@@ -1,5 +1,20 @@
{% load i18n %}
+
+function blankImage() {
+ return `/static/img/blank_image.png`;
+}
+
+// Render a select2 thumbnail image
+function select2Thumbnail(image) {
+ if (!image) {
+ image = blankImage();
+ }
+
+ return ``;
+}
+
+
/*
* This file contains functions for rendering various InvenTree database models,
* in particular for displaying them in modal forms in a 'select2' context.
@@ -15,8 +30,10 @@
// Renderer for "Company" model
function renderCompany(name, data, parameters, options) {
+
+ var html = select2Thumbnail(data.image);
- var html = `${data.name} - ${data.description}`;
+ html += `${data.name} - ${data.description}`;
html += `{% trans "Company ID" %}: ${data.pk}`;
@@ -27,11 +44,7 @@ function renderCompany(name, data, parameters, options) {
// Renderer for "StockItem" model
function renderStockItem(name, data, parameters, options) {
- var image = data.part_detail.thumbnail || data.part_detail.image;
-
- if (!image) {
- image = `/static/img/blank_image.png`;
- }
+ var image = data.part_detail.thumbnail || data.part_detail.image || blankImage();
var html = ``;
@@ -72,15 +85,13 @@ function renderStockLocation(name, data, parameters, options) {
function renderBuild(name, data, parameters, options) {
- var image = '';
+ var image = null;
if (data.part_detail && data.part_detail.thumbnail) {
image = data.part_detail.thumbnail;
- } else {
- image = `/static/img/blank_image.png`;
- }
+ }
- var html = ``;
+ var html = select2Thumbnail(image);
html += `${data.reference} - ${data.quantity} x ${data.part_detail.full_name}`;
html += `{% trans "Build ID" %}: ${data.pk}`;
@@ -94,13 +105,7 @@ function renderBuild(name, data, parameters, options) {
// Renderer for "Part" model
function renderPart(name, data, parameters, options) {
- var image = data.image;
-
- if (!image) {
- image = `/static/img/blank_image.png`;
- }
-
- var html = ``;
+ var html = select2Thumbnail(data.image);
html += ` ${data.full_name || data.name}`;
@@ -131,7 +136,6 @@ function renderOwner(name, data, parameters, options) {
var html = `${data.name}`;
-
switch (data.label) {
case 'user':
html += ``;
@@ -177,13 +181,7 @@ function renderPartParameterTemplate(name, data, parameters, options) {
// Rendered for "SupplierPart" model
function renderSupplierPart(name, data, parameters, options) {
- var image = data.supplier_detail.image;
-
- if (!image) {
- image = `/static/img/blank_image.png`;
- }
-
- var html = ``;
+ var html = select2Thumbnail(data.supplier_detail.image);
html += ` ${data.supplier_detail.name} - ${data.SKU}`;
html += ` - ${data.part_detail.full_name}`;
@@ -193,4 +191,4 @@ function renderSupplierPart(name, data, parameters, options) {
return html;
-}
\ No newline at end of file
+}