Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Major bugfix for multiple annotations in API querysets #965

Merged
merged 7 commits into from
Sep 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 8 additions & 1 deletion InvenTree/company/fixtures/company.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,11 @@
pk: 3
fields:
name: Zerg Corp
description: We eat the competition
description: We eat the competition
- model: company.company
pk: 4
fields:
name: A customer
description: A company that we sell things to!
is_customer: True

14 changes: 10 additions & 4 deletions InvenTree/company/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from rest_framework import serializers

from django.db.models import Count
from sql_util.utils import SubqueryCount

from .models import Company
from .models import SupplierPart, SupplierPriceBreak
Expand Down Expand Up @@ -38,11 +38,17 @@ class CompanySerializer(InvenTreeModelSerializer):
@staticmethod
def annotate_queryset(queryset):

return queryset.annotate(
parts_supplied=Count('supplied_parts'),
parts_manufactured=Count('manufactured_parts')
# Add count of parts manufactured
queryset = queryset.annotate(
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)

image = serializers.CharField(source='get_thumbnail_url', read_only=True)
Expand Down
1 change: 1 addition & 0 deletions InvenTree/company/templates/company/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ <h3>{{ title }}</h3>

loadCompanyTable("#company-table", "{% url 'api-company-list' %}",
{
pagetype: '{{ pagetype }}',
params: {
{% for key,value in filters.items %}{{ key }}: "{{ value }}",{% endfor %}
}
Expand Down
4 changes: 4 additions & 0 deletions InvenTree/company/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,21 @@ def get_context_data(self, **kwargs):
'button_text': _('New Supplier'),
'filters': {'is_supplier': 'true'},
'create_url': reverse('supplier-create'),
'pagetype': 'suppliers',
},
reverse('manufacturer-index'): {
'title': _('Manufacturers'),
'button_text': _('New Manufacturer'),
'filters': {'is_manufacturer': 'true'},
'create_url': reverse('manufacturer-create'),
'pagetype': 'manufacturers',
},
reverse('customer-index'): {
'title': _('Customers'),
'button_text': _('New Customer'),
'filters': {'is_customer': 'true'},
'create_url': reverse('customer-create'),
'pagetype': 'customers',
}
}

Expand All @@ -71,6 +74,7 @@ def get_context_data(self, **kwargs):
'button_text': _('New Company'),
'filters': {},
'create_url': reverse('company-create'),
'pagetype': 'companies'
}

context = None
Expand Down
Binary file modified InvenTree/locale/de/LC_MESSAGES/django.mo
Binary file not shown.