Add optional display of part stock quantity in forms

This commit is contained in:
Oliver 2021-10-06 22:12:59 +11:00
parent 54d770927a
commit 166af3592d
3 changed files with 25 additions and 2 deletions

View File

@ -242,6 +242,13 @@
border-color: var(--label-red);
}
.label-form {
margin: 2px;
padding-left: 4px;
padding-right: 4px;
border-radius: 5px;
}
.label-red {
background: var(--label-red);
}

View File

@ -648,7 +648,6 @@ class InvenTreeSetting(BaseInvenTreeSetting):
'validator': bool,
},
# TODO: Remove this setting in future, new API forms make this not useful
'PART_SHOW_QUANTITY_IN_FORMS': {
'name': _('Show Quantity in Forms'),
'description': _('Display available part quantity in some forms'),

View File

@ -159,7 +159,24 @@ function renderPart(name, data, parameters, options) {
html += ` - <i>${data.description}</i>`;
}
html += `<span class='float-right'><small>{% trans "Part ID" %}: ${data.pk}</small></span>`;
var stock = '';
// Display available part quantity
if (global_settings.PART_SHOW_QUANTITY_IN_FORMS) {
if (data.in_stock == 0) {
stock = `<span class='label-form label-red'>{% trans "No Stock" %}</span>`;
} else {
stock = `<span class='label-form label-green'>{% trans "In Stock" %}: ${data.in_stock}</span>`;
}
}
html += `
<span class='float-right'>
<small>
${stock}
{% trans "Part ID" %}: ${data.pk}
</small>
</span>`;
return html;
}