Skip to content

Commit

Permalink
Merge pull request #965 from SchrodingersGat/api-stock-fix
Browse files Browse the repository at this point in the history
Major bugfix for multiple annotations in API querysets
  • Loading branch information
SchrodingersGat committed Sep 5, 2020
2 parents a2efac4 + 46a8107 commit 22e3090
Show file tree
Hide file tree
Showing 17 changed files with 907 additions and 511 deletions.
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.

0 comments on commit 22e3090

Please sign in to comment.