mirror of
https://github.com/inventree/InvenTree.git
synced 2025-04-30 20:46:47 +00:00
Fix annotations for Company serializers
This commit is contained in:
parent
db214dfd73
commit
598e15af46
@ -4,7 +4,7 @@ JSON serializers for Company app
|
|||||||
|
|
||||||
from rest_framework import serializers
|
from rest_framework import serializers
|
||||||
|
|
||||||
from django.db.models import Count
|
from sql_util.utils import SubqueryCount
|
||||||
|
|
||||||
from .models import Company
|
from .models import Company
|
||||||
from .models import SupplierPart, SupplierPriceBreak
|
from .models import SupplierPart, SupplierPriceBreak
|
||||||
@ -38,11 +38,17 @@ class CompanySerializer(InvenTreeModelSerializer):
|
|||||||
@staticmethod
|
@staticmethod
|
||||||
def annotate_queryset(queryset):
|
def annotate_queryset(queryset):
|
||||||
|
|
||||||
return queryset.annotate(
|
# Add count of parts manufactured
|
||||||
parts_supplied=Count('supplied_parts'),
|
queryset = queryset.annotate(
|
||||||
parts_manufactured=Count('manufactured_parts')
|
parts_manufactured=SubqueryCount('manufactured_parts')
|
||||||
)
|
)
|
||||||
|
|
||||||
|
queryset = queryset.annotate(
|
||||||
|
parts_supplied=SubqueryCount('supplied_parts')
|
||||||
|
)
|
||||||
|
|
||||||
|
return queryset
|
||||||
|
|
||||||
url = serializers.CharField(source='get_absolute_url', read_only=True)
|
url = serializers.CharField(source='get_absolute_url', read_only=True)
|
||||||
|
|
||||||
image = serializers.CharField(source='get_thumbnail_url', read_only=True)
|
image = serializers.CharField(source='get_thumbnail_url', read_only=True)
|
||||||
|
@ -33,6 +33,7 @@ InvenTree | {% trans "Supplier List" %}
|
|||||||
|
|
||||||
loadCompanyTable("#company-table", "{% url 'api-company-list' %}",
|
loadCompanyTable("#company-table", "{% url 'api-company-list' %}",
|
||||||
{
|
{
|
||||||
|
pagetype: '{{ pagetype }}',
|
||||||
params: {
|
params: {
|
||||||
{% for key,value in filters.items %}{{ key }}: "{{ value }}",{% endfor %}
|
{% for key,value in filters.items %}{{ key }}: "{{ value }}",{% endfor %}
|
||||||
}
|
}
|
||||||
|
@ -51,18 +51,21 @@ class CompanyIndex(ListView):
|
|||||||
'button_text': _('New Supplier'),
|
'button_text': _('New Supplier'),
|
||||||
'filters': {'is_supplier': 'true'},
|
'filters': {'is_supplier': 'true'},
|
||||||
'create_url': reverse('supplier-create'),
|
'create_url': reverse('supplier-create'),
|
||||||
|
'pagetype': 'suppliers',
|
||||||
},
|
},
|
||||||
reverse('manufacturer-index'): {
|
reverse('manufacturer-index'): {
|
||||||
'title': _('Manufacturers'),
|
'title': _('Manufacturers'),
|
||||||
'button_text': _('New Manufacturer'),
|
'button_text': _('New Manufacturer'),
|
||||||
'filters': {'is_manufacturer': 'true'},
|
'filters': {'is_manufacturer': 'true'},
|
||||||
'create_url': reverse('manufacturer-create'),
|
'create_url': reverse('manufacturer-create'),
|
||||||
|
'pagetype': 'manufacturers',
|
||||||
},
|
},
|
||||||
reverse('customer-index'): {
|
reverse('customer-index'): {
|
||||||
'title': _('Customers'),
|
'title': _('Customers'),
|
||||||
'button_text': _('New Customer'),
|
'button_text': _('New Customer'),
|
||||||
'filters': {'is_customer': 'true'},
|
'filters': {'is_customer': 'true'},
|
||||||
'create_url': reverse('customer-create'),
|
'create_url': reverse('customer-create'),
|
||||||
|
'pagetype': 'customers',
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -71,6 +74,7 @@ class CompanyIndex(ListView):
|
|||||||
'button_text': _('New Company'),
|
'button_text': _('New Company'),
|
||||||
'filters': {},
|
'filters': {},
|
||||||
'create_url': reverse('company-create'),
|
'create_url': reverse('company-create'),
|
||||||
|
'pagetype': 'companies'
|
||||||
}
|
}
|
||||||
|
|
||||||
context = None
|
context = None
|
||||||
|
@ -21,15 +21,7 @@ function loadCompanyTable(table, url, options={}) {
|
|||||||
|
|
||||||
setupFilterList("company", $(table));
|
setupFilterList("company", $(table));
|
||||||
|
|
||||||
$(table).inventreeTable({
|
var columns = [
|
||||||
url: url,
|
|
||||||
method: 'get',
|
|
||||||
queryParams: filters,
|
|
||||||
groupBy: false,
|
|
||||||
formatNoMatches: function() { return "{% trans "No company information found" %}"; },
|
|
||||||
showColumns: true,
|
|
||||||
name: 'company',
|
|
||||||
columns: [
|
|
||||||
{
|
{
|
||||||
field: 'pk',
|
field: 'pk',
|
||||||
title: 'ID',
|
title: 'ID',
|
||||||
@ -74,7 +66,37 @@ function loadCompanyTable(table, url, options={}) {
|
|||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
],
|
];
|
||||||
|
|
||||||
|
if (options.pagetype == 'suppliers') {
|
||||||
|
columns.push({
|
||||||
|
sortable: true,
|
||||||
|
field: 'parts_supplied',
|
||||||
|
title: '{% trans "Parts Supplied" %}',
|
||||||
|
formatter: function(value, row) {
|
||||||
|
return renderLink(value, `/company/${row.pk}/parts/`);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else if (options.pagetype == 'manufacturers') {
|
||||||
|
columns.push({
|
||||||
|
sortable: true,
|
||||||
|
field: 'parts_manufactured',
|
||||||
|
title: '{% trans "Parts Manufactured" %}',
|
||||||
|
formatter: function(value, row) {
|
||||||
|
return renderLink(value, `/company/${row.pk}/parts/`);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
$(table).inventreeTable({
|
||||||
|
url: url,
|
||||||
|
method: 'get',
|
||||||
|
queryParams: filters,
|
||||||
|
groupBy: false,
|
||||||
|
formatNoMatches: function() { return "{% trans "No company information found" %}"; },
|
||||||
|
showColumns: true,
|
||||||
|
name: options.pagetype || 'company',
|
||||||
|
columns: columns,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user