Merge pull request #1833 from SchrodingersGat/part-cat-form-improvements

Part cat form improvements
This commit is contained in:
Oliver 2021-07-18 21:32:31 +10:00 committed by GitHub
commit b1165af3c3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 32 additions and 13 deletions

View File

@ -118,9 +118,17 @@ class CategoryList(generics.ListCreateAPIView):
ordering_fields = [ ordering_fields = [
'name', 'name',
'level',
'tree_id',
'lft',
] ]
ordering = 'name' # Use hierarchical ordering by default
ordering = [
'tree_id',
'lft',
'name'
]
search_fields = [ search_fields = [
'name', 'name',

View File

@ -32,6 +32,8 @@ class CategorySerializer(InvenTreeModelSerializer):
parts = serializers.IntegerField(source='item_count', read_only=True) parts = serializers.IntegerField(source='item_count', read_only=True)
level = serializers.IntegerField(read_only=True)
class Meta: class Meta:
model = PartCategory model = PartCategory
fields = [ fields = [
@ -40,10 +42,11 @@ class CategorySerializer(InvenTreeModelSerializer):
'description', 'description',
'default_location', 'default_location',
'default_keywords', 'default_keywords',
'pathstring', 'level',
'url',
'parent', 'parent',
'parts', 'parts',
'pathstring',
'url',
] ]

View File

@ -363,6 +363,15 @@ class StockLocationList(generics.ListCreateAPIView):
ordering_fields = [ ordering_fields = [
'name', 'name',
'items', 'items',
'level',
'tree_id',
'lft',
]
ordering = [
'tree_id',
'lft',
'name',
] ]

View File

@ -260,12 +260,15 @@ class LocationSerializer(InvenTreeModelSerializer):
items = serializers.IntegerField(source='item_count', read_only=True) items = serializers.IntegerField(source='item_count', read_only=True)
level = serializers.IntegerField(read_only=True)
class Meta: class Meta:
model = StockLocation model = StockLocation
fields = [ fields = [
'pk', 'pk',
'url', 'url',
'name', 'name',
'level',
'description', 'description',
'parent', 'parent',
'pathstring', 'pathstring',

View File

@ -67,7 +67,9 @@ function renderStockItem(name, data, parameters, options) {
// Renderer for "StockLocation" model // Renderer for "StockLocation" model
function renderStockLocation(name, data, parameters, options) { function renderStockLocation(name, data, parameters, options) {
var html = `<span>${data.name}</span>`; var level = '- '.repeat(data.level);
var html = `<span>${level}${data.pathstring}</span>`;
if (data.description) { if (data.description) {
html += ` - <i>${data.description}</i>`; html += ` - <i>${data.description}</i>`;
@ -75,10 +77,6 @@ function renderStockLocation(name, data, parameters, options) {
html += `<span class='float-right'>{% trans "Location ID" %}: ${data.pk}</span>`; html += `<span class='float-right'>{% trans "Location ID" %}: ${data.pk}</span>`;
if (data.pathstring) {
html += `<p><small>${data.pathstring}</small></p>`;
}
return html; return html;
} }
@ -154,7 +152,9 @@ function renderOwner(name, data, parameters, options) {
// Renderer for "PartCategory" model // Renderer for "PartCategory" model
function renderPartCategory(name, data, parameters, options) { function renderPartCategory(name, data, parameters, options) {
var html = `<span><b>${data.name}</b></span>`; var level = '- '.repeat(data.level);
var html = `<span>${level}${data.pathstring}</span>`;
if (data.description) { if (data.description) {
html += ` - <i>${data.description}</i>`; html += ` - <i>${data.description}</i>`;
@ -162,10 +162,6 @@ function renderPartCategory(name, data, parameters, options) {
html += `<span class='float-right'>{% trans "Category ID" %}: ${data.pk}</span>`; html += `<span class='float-right'>{% trans "Category ID" %}: ${data.pk}</span>`;
if (data.pathstring) {
html += `<p><small>${data.pathstring}</small></p>`;
}
return html; return html;
} }